QtService

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).

Calling convention

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.

Example

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)

API Reference

class PyroMP.QtService(multiplex=False, async=True, **kwargs)

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

Determines the servertype when using with
  • True -> multiplex
  • False -> threaded

See Pyro4 documentation

async : bool

Determines if the connection returned using with is synchronous or asynchronous

Methods

get_logger()

Returns the logger of this class or just a logger stub, if LOGGING is False

init_resources()

Called when the service process is starting after everything else was set up

close_resources()

Called before stopping the service process

qt_main()

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

classmethod get_connection(async=True)
Parameters :

async : bool

Determines if the connection is synchronous or asynchronous

classmethod get_pyro_name()

Returns a name for registering at a NameServer

classmethod is_running()

Checks if the Service is running

Returns :

running : bool

True if it is running False otherwise

classmethod start(multiplex=False)

Starts the service if not already running

Parameters :

multiplex : bool

Determines the servertype.
  • True -> multiplex
  • False -> threaded

See Pyro4 documentation

Notes

Only the process that has started a service is able to stop it.

classmethod stop()

Stops the service if running and managed by this process

classmethod wait_for()

Wait until the service is not running anymore (e.g. windows has been closed)

Table Of Contents

Previous topic

Queued Services

Next topic

Examples

This Page