KDE 4.9 PyKDE API Reference

- KDE's Python API

# KWordMacroExpander Class Reference

`from PyKDE4.kdecore import *`

Inherits: KMacroExpanderBase

## Detailed Description

\class KWordMacroExpander kmacroexpander.h <KMacroExpanderBase>

Abstract base class for simple word macro substitutors. Use this instead of the functions in the KMacroExpander namespace if speculatively pre-filling the substitution map would be too expensive.

A typical application:

     class MyClass {
     ...
       private:
         QString m_str;
     ...
       friend class MyExpander;
     };

     class MyExpander : public KWordMacroExpander {
       public:
         MyExpander( MyClass *_that ) : KWordMacroExpander(), that( _that ) {}
       protected:
         virtual bool expandMacro( const QString &str, QStringList &ret );
       private:
         MyClass *that;
     };

     bool MyExpander.expandMacro( const QString &str, QStringList &ret )
     {
       if (str == "macro") {
         ret += complexOperation( that->m_str );
         return true;
       }
       return false;
     }

     ... MyClass....(...)
     {
       QString str;
       ...
       MyExpander mx( this );
       mx.expandMacrosShellQuote( str );
       ...
     }

Alternatively MyClass could inherit from KWordMacroExpander directly.

Author:
  Oswald Buddenhagen <ossi@kde.org>

## Methods
| __init__ (self, QChar c=QLatin1Char('%'))
| __init__ (self, KWordMacroExpander other)
int | expandEscapedMacro (self, QString str, int pos, QStringList ret)
bool | expandMacro (self, QString str, QStringList ret)
int | expandPlainMacro (self, QString str, int pos, QStringList ret)

## Method Documentation

__init__ | ( | self, |
|  | QChar | c=QLatin1Char('%')
| ) |  |  |

Constructor.

Parameters:

  | c | escape char indicating start of macros, or QChar.null for none

__init__ | ( | self, |
|  | KWordMacroExpander | other
| ) |  |  |

int expandEscapedMacro | ( | self, |
|  | QString | str,
|  | int | pos,
|  | QStringList | ret
| ) |  |  |

Internal:
  Not to be called or reimplemented.

bool expandMacro | ( | self, |
|  | QString | str,
|  | QStringList | ret
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Return substitution list ret for string macro str.

Parameters:

  | str | the macro to expand
  | ret | return variable reference. It is guaranteed to be empty when expandMacro is entered.

Returns:
  true iff chr was a recognized macro name

int expandPlainMacro | ( | self, |
|  | QString | str,
|  | int | pos,
|  | QStringList | ret
| ) |  |  |

Internal:
  Not to be called or reimplemented.