Toolkit integration

Qt integration

To plug monitoring with pyudev.Monitor into the Qt event loop, so that Qt signals are asynchronously emitted upon events, QUDevMonitorObserver is provided:

class QUDevMonitorObserver

Observe a Monitor and emit Qt signals upon device events:

>>> context = pyudev.Context()
>>> monitor = pyudev.Monitor.from_netlink(context)
>>> monitor.filter_by(subsystem='input')
>>> observer = QUDevMonitorObserver(monitor)
>>> def device_connected(device):
...     print('{0!r} added'.format(device))
>>> observer.deviceAdded.connect(device_connected)
>>> monitor.start()

This class is a child of QtCore.QObject.

__init__(monitor, parent=None)

Observe the given monitor (a pyudev.Monitor).

parent is the parent QObject of this object. It is passed straight to the inherited constructor of QObject.

monitor

The Monitor observed by this object.

notifier

The underlying QtCore.QSocketNotifier used to watch the monitor

Signals

This class defines the following Qt signals:

deviceEvent(action, device)

Emitted upon any device event. action is a unicode string containing the action name, and device is the Device object describing the device.

Basically the arguments of this signal are simply the return value of receive_device()

deviceAdded(device)

Emitted if a Device is added (e.g a USB device was plugged).

deviceRemoved(device)

Emitted if a Device is removed (e.g. a USB device was unplugged).

deviceChanged(device)

Emitted if a Device was somehow changed (e.g. a change of a property)

deviceMoved(device)

Emitted if a Device was renamed, moved or re-parented.

Currently there are two different, incompatible bindings to Qt4:

PyQt4_
Older, more mature, but developed by a 3rd party (Riverbank computing) and distributed under the GPL (though with some exceptions for other free software licences)
PySide_
Developed by Nokia as alternative to PyQt4_ and distributed under the less restrictive LGPL, however not yet as mature and feature-rich as PyQt4_.

For both of these bindings a QUDevMonitorObserver implementation is provided, each in a separate module:

pyudev.pyqt4

class QUDevMonitorObserver

A QUDevMonitorObserver implementation for PyQt4_

pyudev.pyside

class QUDevMonitorObserver

A QUDevMonitorObserver implementation for PySide_

pyudev.glib – Glib and Gtk integration

Project Versions

Table Of Contents

Previous topic

Monitor – monitor devices

Next topic

Licencing

This Page