KDE 4.7 PyKDE API Reference

- KDE's Python API

# KPluginFactory Class Reference

`from PyKDE4.kdecore import *`

Inherits: QObject

## Detailed Description

\class KPluginFactory kpluginfactory.h <KPluginFactory>

If you develop a library that is to be loaded dynamically at runtime, then you should return a pointer to a KPluginFactory.

For most cases it is enough to use the K_PLUGIN_FACTORY macro to create the factory.

Example:

     #include <KPluginFactory>
     #include <KPluginLoader>
     #include <plugininterface.h>

     class MyPlugin;

     K_PLUGIN_FACTORY(MyPluginFactory,
                      registerPlugin<MyPlugin>();
                     )
     K_EXPORT_PLUGIN(MyPluginFactory("componentName"))

     class MyPlugin : public PluginInterface
     {
         ...
         KComponentData kcd = MyPluginFactory.componentData();
         ...
     };

K_PLUGIN_FACTORY is a convenient macro that expands to a class derived from KPluginFactory providing two constructors and a static componentData() function. The second argument to K_PLUGIN_FACTORY is code that is called from the constructors. There you can use registerPlugin to register as many plugins for the factory as you want to.

If you want to write a custom KPluginFactory not using the standard macro(s) you can reimplement the create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword) function.

Example:

     class SomeScriptLanguageFactory : public KPluginFactory
     {
         Q_OBJECT
     public:
         SomeScriptLanguageFactory()
             : KPluginFactory("SomeScriptLanguageComponent")
         {}

     protected:
         virtual QObject *create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword)
         {
             const QString identifier = QLatin1String(iface) + QLatin1Char('_') + keyword;
             // load scripting language module from the information in identifier
             // and return it:
             return object;
         }
     };

If you want to load a library use KPluginLoader. The application that wants to instantiate plugin classes can do the following:

     KPluginFactory *factory = KPluginLoader("libraryname").factory();
     if (factory) {
         PluginInterface *p1 = factory->create<PluginInterface>(parent);
         OtherInterface *p2  = factory->create<OtherInterface>(parent);
         NextInterface *p3   = factory->create<NextInterface>("keyword1", parent);
         NextInterface *p3   = factory->create<NextInterface>("keyword2", parent);
     }

Author:
  Matthias Kretz <kretz@kde.org>

Author:
  Bernhard Loos <nhuh.put@web.de>

## Signals

| objectCreated (QObject object)

## Methods

| __init__ (self, QString componentName=0, QString catalogName=0, QObject parent=0)
| __init__ (self, KAboutData aboutData, QObject parent=0)
| __init__ (self, KAboutData aboutData, QObject parent=0)
| __init__ (self, QObject parent)
KComponentData | componentData (self)
QObject | create (self, QObject parent=0, QString classname="QObject", QStringList args=QStringList())
QObject | create (self, QString iface, QWidget parentWidget, QObject parent, [QVariant] args, QString keyword)
QObject | createObject (self, QObject parent, QString className, QStringList args)
| setComponentData (self, KComponentData componentData)
| setupTranslations (self)
[QVariant] | stringListToVariantList (self, QStringList list)
QStringList | variantListToStringList (self, [QVariant] list)

## Signal Documentation

objectCreated | ( | QObject | object
| ) |  |  |

Signal syntax:
  `QObject.connect(source, SIGNAL("objectCreated(QObject*)"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | QString | componentName=0,
|  | QString | catalogName=0,
|  | QObject | parent=0
| ) |  |  |

This constructor creates a factory for a plugin with the given componentName and catalogName. Those values are used to initialize a KComponentData object for the plugin. You can later access it with componentData(). If componentName is 0, an invalid KComponentData object will be created.

Parameters:

  | componentName | the component name of the plugin

Parameters:

  | catalogName | the translation catalog to use

Parameters:

  | parent | a parent object

__init__ | ( | self, |
|  | KAboutData | aboutData,
|  | QObject | parent=0
| ) |  |  |

Deprecated:

__init__ | ( | self, |
|  | KAboutData | aboutData,
|  | QObject | parent=0
| ) |  |  |

Deprecated:

__init__ | ( | self, |
|  | QObject | parent
| ) |  |  |

Deprecated:

KComponentData componentData | ( |  | self ) |

You can use this method to get the component data of the plugin. It is filled with the information given to the constructor of KPluginFactory. The K_PLUGIN_FACTORY macros provide a static version of this method, this can be used from any place within the plugin.

Only use this method if you specified a componentData name or instance to the factory constructor or to setComponentData. Otherwise you get an invalid KComponentData, which will crash if used.

Returns:
  The KComponentData for the plugin

QObject create | ( | self, |
|  | QObject | parent=0,
|  | QString | classname="QObject",
|  | QStringList | args=QStringList()
| ) |  |  |

This function is called when the factory asked to create an Object.

You may reimplement it to provide a very flexible factory. This is especially useful to provide generic factories for plugins implemeted using a scripting language.

Parameters:

  | iface | The staticMetaObject.className() string identifying the plugin interface that was requested. E.g. for KCModule plugins this string will be "KCModule".

Parameters:

  | parentWidget | Only used if the requested plugin is a KPart.

Parameters:

  | parent | The parent object for the plugin object.

Parameters:

  | args | A plugin specific list of arbitrary arguments.

Parameters:

  | keyword | A string that uniquely identifies the plugin. If a KService is used this keyword is read from the X-KDE-PluginKeyword entry in the .desktop file.

QObject create | ( | self, |
|  | QString | iface,
|  | QWidget | parentWidget,
|  | QObject | parent,
|  | [QVariant] | args,
|  | QString | keyword
| ) |  |  |

This function is called when the factory asked to create an Object.

You may reimplement it to provide a very flexible factory. This is especially useful to provide generic factories for plugins implemeted using a scripting language.

Parameters:

  | iface | The staticMetaObject.className() string identifying the plugin interface that was requested. E.g. for KCModule plugins this string will be "KCModule".

Parameters:

  | parentWidget | Only used if the requested plugin is a KPart.

Parameters:

  | parent | The parent object for the plugin object.

Parameters:

  | args | A plugin specific list of arbitrary arguments.

Parameters:

  | keyword | A string that uniquely identifies the plugin. If a KService is used this keyword is read from the X-KDE-PluginKeyword entry in the .desktop file.

QObject createObject | ( | self, |
|  | QObject | parent,
|  | QString | className,
|  | QStringList | args
| ) |  |  |

Deprecated:

setComponentData | ( | self, |
|  | KComponentData | componentData
| ) |  |  |

This method sets the component data of the plugin. You can access the component data object later with componentData(). Normally you don't have to call this, because the factory constructs a component data object from the information given to the constructor. The object is destroyed, when the module containing the plugin is unloaded. Normally this happens only on application shutdown.

Parameters:

  | componentData | the new KComponentData object

setupTranslations | ( |  | self ) |

[QVariant] stringListToVariantList | ( | self, |
|  | QStringList | list
| ) |  |  |

Internal:
  Converts a QStringList to a QVariantList

QStringList variantListToStringList | ( | self, |
|  | [QVariant] | list
| ) |  |  |

Internal:
  Converts a QVariantList of strings to a QStringList