Python-Qt context manager. Helper methods for Qt-Python interaction. More...
#include <PyContext.h>
Classes | |
class | ArgFactoryEntry |
struct | ConnectEntry |
struct | Method |
Stores information used at method invocation time. | |
struct | PyQObject |
PyObject type More... | |
struct | Type |
Stores type information needed for invoking methods from Python. More... | |
struct | TypeConstruction |
Stores information on registered types. More... | |
Public Member Functions | |
PyContext () | |
Constructor: Create qpy module with QPy interface. | |
~PyContext () | |
void | AddGlobals (PyObject *module) |
Add QPy globals to Python interpreter; currently only __version__ is added. | |
PyTypeObject * | AddType (const QMetaObject *mo, PyObject *module, bool checkConstructor=true, const QSet< QString > &selectedMembers=QSet< QString >(), const PyMemberNameMapper &mm=DefaultMemberNameMapper(), const char *className=0, const char *doc=0) |
template<typename T > | |
void | Add (PyObject *module, bool checkConstructor=true, const QSet< QString > &selectedMembers=QSet< QString >(), const PyMemberNameMapper &mm=DefaultMemberNameMapper(), const char *className=0, const char *doc=0) |
PyMethodDef * | ModuleFunctions () |
PyObject * | AddObject (QObject *qobj, PyObject *targetModule, PyObject *typeModule, const char *instanceName, bool pythonOwned=false, const QSet< QString > &selectedMembers=QSet< QString >(), const PyMemberNameMapper &mm=DefaultMemberNameMapper()) |
Add pre-existing QObject instance to Python module. | |
template<typename QArgConstructorT , typename PyArgConstructorT > | |
bool | RegisterType (const QString &typeName, bool overwrite=false) |
template<typename T , typename QArgConstructorT , typename PyArgConstructorT > | |
bool | RegisterType (const QString &typeName, bool overwrite=false) |
TypeConstruction | RegTypeInfo (const QString &t) const |
QList< TypeConstruction > | RegisteredTypes () const |
Return list of registered types. | |
Static Public Member Functions | |
static const char * | Version () |
Return version info. |
Python-Qt context manager. Helper methods for Qt-Python interaction.
This class is the interface exposed by QPy to client code. Use the provided methods to add QObject-derived type, QObject instances and other types the Python context. PyContext is also used internally by other classes to add QObjects returned by methods or received from signals to the Python context.
qpy::PyContext::~PyContext | ( | ) | [inline] |
Destructor: free all QVariant <--> Python converters that are not foreign owned
void qpy::PyContext::Add | ( | PyObject * | module, |
bool | checkConstructor = true , |
||
const QSet< QString > & | selectedMembers = QSet< QString >() , |
||
const PyMemberNameMapper & | mm = DefaultMemberNameMapper() , |
||
const char * | className = 0 , |
||
const char * | doc = 0 |
||
) | [inline] |
Templated version of Addtype
. QMetaObject is automatically extracted.
module | Python module where type is added |
checkConstructor | if the method rises an exception in case a constructor is not available; note that when adding pre-created instances through the AddObject method it is not required that the object be constructible from Python |
selectedMembers | select the members(properties or method) to make accessible from Python; if not specified all members are exposed |
mm | optional member name mapper |
className | specify class name; if NULL the Qt class name is used |
doc | optional documentation string |
PyTypeObject * qpy::PyContext::AddType | ( | const QMetaObject * | mo, |
PyObject * | module, | ||
bool | checkConstructor = true , |
||
const QSet< QString > & | selectedMembers = QSet< QString >() , |
||
const PyMemberNameMapper & | mm = DefaultMemberNameMapper() , |
||
const char * | className = 0 , |
||
const char * | doc = 0 |
||
) |
Add type to Python interpreter; the Qt type is wrapped with a Python class. Instances are created from within Python by explicilty invoking constructors mapped to the actual C++ constructors declared as Q_INVOKABLE
.
mo | MetaObject pointer to the type to add |
module | Python module where type is added |
checkConstructor | if the method rises an exception in case a constructor is not available; note that when adding pre-created instances through the AddObject method it is not required that the object be constructible from Python |
selectedMembers | select the members(properties or method) to make accessible from Python; if not specified all members are exposed |
mm | optional member name mapper |
className | specify class name; if NULL the Qt class name is used |
doc | optional documentation string |
PyMethodDef * qpy::PyContext::ModuleFunctions | ( | ) |
Return global functions to be added to Python module. These are the mainly the functions required for accessing the signal-slot binding facilities.
bool qpy::PyContext::RegisterType | ( | const QString & | typeName, |
bool | overwrite = false |
||
) | [inline] |
Register new types by passing the type of QArgConstructor and PyArgConstructor; this way of registering does not allow to pass actual instances, and does require support for operator new and delete.
bool qpy::PyContext::RegisterType | ( | const QString & | typeName, |
bool | overwrite = false |
||
) | [inline] |
Register new types by passing the type of QArgConstructor and PyArgConstructor; this way of registering does not allow to pass actual instances, and does require support for operator new and delete. Also register the
TypeConstruction qpy::PyContext::RegTypeInfo | ( | const QString & | t | ) | const [inline] |
Return information on registered type.
t | type name |