pyudev.pyqt4PyQt4 integration

PyQt4 integration.

QUDevMonitorObserver integrates device monitoring into the PyQt4 mainloop by turing device events into Qt signals.

PyQt4.QtCore from PyQt4 must be available when importing this module.

class pyudev.pyqt4.QUDevMonitorObserver(monitor, parent=None)

An observer for device events integrating into the PyQt4 mainloop.

This class inherits QObject to turn device events into Qt signals:

>>> from pyudev import Context, Monitor
>>> from pyudev.pyqt4 import QUDevMonitorObserver
>>> context = Context()
>>> monitor = 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 QObject.

__init__(monitor, parent=None)

Observe the given monitor (a Monitor):

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

monitor

The Monitor observed by this object.

notifier

The underlying QtCore.QSocketNotifier used to watch the monitor.

enabled

Whether this observer is enabled or not.

If True (the default), this observer is enabled, and emits events. Otherwise it is disabled and does not emit any events. This merely reflects the state of the enabled property of the underlying notifier.

New in version 0.14.

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.

Project Versions

pyudev 0.16

Install

  • pip install pyudev

Links

Support

Previous topic

pyudev - libudev binding

Next topic

pyudev.pyside – PySide integration

This Page