itom 1.3.0
|
This class provides the possibility to redirect any signal emitted in an user-defined GUI to different python methods. More...
Public Member Functions | |
PythonQtSignalMapper (unsigned int initSlotCount) | |
constructor | |
~PythonQtSignalMapper () | |
destructor | |
bool | addSignalHandler (QObject *obj, const char *signal, int sigId, PyObject *callable, IntList &argTypeList) |
creates signal-slot connection between the signal of any widget and a python method as slot | |
bool | removeSignalHandler (QObject *obj, const char *signal, int sigId, PyObject *callable) |
disconnects a certain connection | |
void | removeSignalHandlers () |
disconnects all signal-slot connections managed by this instane of PythonQtSignalMapper | |
virtual int | qt_metacall (QMetaObject::Call c, int id, void **arguments) |
method invoked by Qt if a connected signal is emitted | |
Private Attributes | |
QList< PythonQtSignalTarget > | m_targets |
list with all virtual slot targets that are the destination for any registered signal-slot-connection | |
int | m_slotCount |
index of the last virtual slot managed by this instance (auto-incremented) |
This class provides the possibility to redirect any signal emitted in an user-defined GUI to different python methods.
Every user-defined dialog, main window or widget that is loaded by the python-class ui or that is loaded from a plugin, contains one instance of this class. Any signal from any item of this user interface, that is connected by a python script with any appropriate bounded or unbounded pyhton method, is handled by this instance. This works as follows: The Qt-signal-slot system obtains a virtual slot that fits to the requirements of the signal. Both are connected. Once the slot as a member of this class is called, the call is catched by the overwritten method qt_metacall. If anything is ok, the call is then redirected to the registered python method. Any python method that acts as slot for any signal of the dialog or window, is one instance of the class PythonQtSignalTarget.
Since the mapper usually is created in the python thread, while the signaling widgets are in the main thread, the necessary thread-change is already handled when connection the signal of the widget with the virtual slot of this mapper instance.
ito::PythonQtSignalMapper::PythonQtSignalMapper | ( | unsigned int | initSlotCount | ) |
constructor
Creates an instance of PythonQtSignalMapper and initializes the slot counter with the given value. Usually this initial slot counter is set to the highest slot number of the graphical user interface this mapper is assigned to.
ito::PythonQtSignalMapper::~PythonQtSignalMapper | ( | ) |
destructor
Destroys this signal mapper and deletes the managed targets (virtual slots). The connected signals are automatically disconnected by Qt.
bool ito::PythonQtSignalMapper::addSignalHandler | ( | QObject * | obj, |
const char * | signal, | ||
int | sigId, | ||
PyObject * | callable, | ||
IntList & | argTypeList | ||
) |
creates signal-slot connection between the signal of any widget and a python method as slot
The connection is established as follows: 1. An instance of PythonQtSignalTarget is created as virtual slot for the corresponding python method 2. This instance is appended to the target list m_targets. 3. Using Qt-methods, the widget's signal is connected to the slot of this virtual target (auto-connection). 4. This virtual slot gets the index of the member m_slotCount, that is incremented afterwards
[in] | obj | is the instance derived from QObject that is the signaling instance |
[in] | signal | is the signature of the signal (Qt-syntax) |
[in] | sigId | is the Qt-internal ID of the signal (obtained by QMetaObject-system) |
[in] | callable | is a reference to the real python method, that should act as slot. This method can be bounded or unbounded. |
[in] | argTypeList | is a list of integer values that describe the Qt-internal type number for all arguments of the signal (type number with respect to QMetaType) |
int ito::PythonQtSignalMapper::qt_metacall | ( | QMetaObject::Call | c, |
int | id, | ||
void ** | arguments | ||
) | [virtual] |
method invoked by Qt if a connected signal is emitted
This method is overwritten from the method created by the Qt-moc process. It is called whenever a signal, connected to a slot or virtual (python) slot of this instance. At first, the instance of qt_metacall of the derived from QObject is called with the same parameters, in order to allow the usual Qt-communcation. If the slot-id could not be handled by the base implementation, all registered PythonQtSignalTarget instances are searched. If their internal slot-index corresponds to the index given as argument to this function, the PythonQtSignalTarget instance is called (method call) with the given arguments.
[in] | c | provide basic information about the call (only used for passing to the base implementation) |
[in] | id | is the unique slot index of the slot to call. |
[in] | arguments | is an array of different argument variables, whose types corresponds to the type-number list, passed when the connection has been registered. |
bool ito::PythonQtSignalMapper::removeSignalHandler | ( | QObject * | obj, |
const char * | signal, | ||
int | sigId, | ||
PyObject * | callable | ||
) |
disconnects a certain connection
Disconnects a certain signal-slot connection, that has previously been connected. This connection is described by the signaling object, the index of the signal (and its signature) and the python callable object (as virtual slot)
[in] | obj | is the instance derived from QObject that is the signaling instance |
[in] | signal | is the signature of the signal (Qt-syntax) |
[in] | sigId | is the Qt-internal ID of the signal (obtained by QMetaObject-system) |
[in] | callable | is a reference to the real python method, that should act as slot. This method can be bounded or unbounded. |
void ito::PythonQtSignalMapper::removeSignalHandlers | ( | ) |
disconnects all signal-slot connections managed by this instane of PythonQtSignalMapper
This disconnection is easily done by deleting the list of targets.