Toolkit integration

Qt integration

QUDevMonitorObserver plugs a pyudev.Monitor into the Qt event loop, so that Qt signals are asynchronously emitted upon events. This class is implemented for both available Qt bindings, PyQt4 and PySide.

pyudev.pyqt4PyQt4 integration

Provide QUDevMonitorObserver to integrate a Monitor into the Qt event loop in applications using the PyQt4 binding to Qt.

To use this module, PyQt4.QtCore from PyQt4 must be available.

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

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 = pyudev.pyqt4.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.

pyudev.pysidePySide integration

Provide QUDevMonitorObserver to integrate a Monitor into the Qt event loop in applications using the PySide binding to Qt.

To use this module, PySide.QtCore from PySide must be available.

New in version 0.6.

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

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 = pyudev.pyqt4.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.

pyudev.glib – Glib and Gtk integration

Provide GUDevMonitorObserver to integrate a Monitor into a glib.MainLoop.

To use this module, glib and gobject from PyGObject must be available. PyGtk is not required.

New in version 0.7.

class pyudev.glib.GUDevMonitorObserver(monitor)

Observe a Monitor and emit Glib signals upon device events:

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

This class is a child of gobject.GObject.

monitor

The Monitor observed by this object.

event_source

The event source, which represents the watch on the monitor (as returned by glib.io_add_watch()), or None, if enabled is False.

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.

New in version 0.14.

Signals

This class defines the following GObject signals:

device-event(observer, action, device)

Emitted upon any device event. observer is the GUDevMonitorObserver, which emitted the signal. action is a unicode string containing the action name, and device is the Device, which caused this event.

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

device-added(observer, device)

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

device-removed(observer, device)

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

device-changed(observer, device)

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

device-moved(observer, device)

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

pyudev.wx – wxWidgets integration

Provides WXUDevMonitorObserver to integrate a Monitor into a wx.App.MainLoop().

To use this module, wx from wxPython must be available.

New in version 0.14.

class pyudev.wx.WxUDevMonitorObserver(monitor)

Observe a Monitor and post wx events upon device events:

>>> context = pyudev.Context()
>>> monitor = pyudev.Monitor.from_netlink(context)
>>> monitor.filter_by(subsystem='input')
>>> observer = pyudev.wx.WxUDevMonitorObserver(monitor)
>>> def device_connected(event):
...     print('{0!r} added'.format(event.device))
>>> observer.Bind(EVT_DEVICE_ADDED, device_connected)
>>> monitor.start()

This class is a child of wx.EvtHandler.

monitor

The Monitor observed by this object.

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.

Event constants

WxUDevMonitorObserver exposes the following events:

pyudev.wx.EVT_DEVICE_EVENT

Emitted upon any device event. Receivers get a DeviceEvent object as argument.

pyudev.wx.EVT_DEVICE_ADDED

Emitted if a Device is added (e.g a USB device was plugged). Receivers get a DeviceAddedEvent object as argument.

pyudev.wx.EVT_DEVICE_REMOVED

Emitted if a Device is removed (e.g. a USB device was unplugged). Receivers get a DeviceRemovedEvent object as argument.

pyudev.wx.EVT_DEVICE_CHANGED

Emitted if a Device was somehow changed (e.g. a change of a property). Receivers get a DeviceChangedEvent object as argument.

pyudev.wx.EVT_DEVICE_MOVED

Emitted if a Device was renamed, moved or re-parented. Receivers get a DeviceMovedEvent object as argument.

Event objects

class pyudev.wx.DeviceEvent

Argument object for EVT_DEVICE_EVENT.

action

A unicode string containing the action name.

device

The Device object that caused this event.

class pyudev.wx.DeviceAddedEvent
class pyudev.wx.DeviceRemovedEvent
class pyudev.wx.DeviceChangedEvent
class pyudev.wx.DeviceMovedEvent

Argument objects for EVT_DEVICE_ADDED, EVT_DEVICE_REMOVED, EVT_DEVICE_CHANGED and EVT_DEVICE_MOVED.

device

The Device object that caused this event.

Project Versions

Table Of Contents

Previous topic

Monitor – monitor devices

Next topic

Licencing

This Page