QtServices provide an event loop for Qt and Pyro4. PySide and PyQt4 is supported, but the former is prefered.
Warning
Due to problems of Qt with threads it is not possible to use init_resources() to initialize Qt objects. The user interface has to be initialized in the qt_main() function, which is called in the main thread after init_resources() has finished.
Warning
You have to connect to events or other PyroMP stuff in the init_resources() function or your program will deadlock
Note
QtService makes it possible to use PySide and PyQt4 in parallel (see PySide PyQt Example).
Qt objects are not thread-safe. If a threaded server is used, normal function calls won’t work (see QtService Example). Calling functions on QObject needs to use the Qt Signal/Slot mechanism.
import PyroMP
from PyroMP.Qt import QtGui, QtCore
class MyDialog(QtGui.QDialog):
call_func = QtCore.Signal(object)
def __init__(self):
super(MyDialog, self).__init__()
self.call_func.connect(self.my_function)
def my_function(self, arg):
# do some stuff here
class MyService(PyroMP.QtService):
def qt_main(self):
self.dlg = MyDialog()
self.dlg.show()
def my_function(self, arg):
self.dlg.call_func.emit(arg)
Bases: PyroMP.Service
A Service providing a Qt and Pyro4 event loop.
Notes
The service is stopped when all windows are closed
Parameters : | multiplex : bool
async : bool
|
---|
Methods
Returns the logger of this class or just a logger stub, if LOGGING is False
Called when the service process is starting after everything else was set up
Called before stopping the service process
Main function to initialize the gui. If no window is shown, the service will be stopped immediately.
Has to be reimplemented in derived classes.
Warning
You have to connect to events or other PyroMP stuff in the init_resources() function or your program will deadlock
Class Methods
Parameters : | async : bool
|
---|
Returns a name for registering at a NameServer
Checks if the Service is running
Returns : | running : bool
|
---|
Starts the service if not already running
Parameters : | multiplex : bool
|
---|
Notes
Only the process that has started a service is able to stop it.
Stops the service if running and managed by this process
Wait until the service is not running anymore (e.g. windows has been closed)