pyudev.glib – Glib/Gtk 2 integration¶
Glib integration.
MonitorObserver integrates device monitoring into the Glib
mainloop by turing device events into Glib signals.
glib and gobject from PyGObject must be available when
importing this module. PyGtk is not required.
New in version 0.7.
-
class
pyudev.glib.MonitorObserver(monitor)¶ An observer for device events integrating into the
glibmainloop.This class inherits
GObjectto turn device events into glib signals.>>> from pyudev import Context, Monitor >>> from pyudev.glib import MonitorObserver >>> context = Context() >>> monitor = Monitor.from_netlink(context) >>> monitor.filter_by(subsystem='input') >>> observer = MonitorObserver(monitor) >>> def device_event(observer, device): ... print('event {0} on device {1}'.format(device.action, device)) >>> observer.connect('device-event', device_event) >>> monitor.start()
This class is a child of
gobject.GObject.-
event_source¶ The event source, which represents the watch on the
monitor(as returned byglib.io_add_watch()), orNone, ifenabledisFalse.
-
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 emits the following GObject signal:
-
device-event(observer, action, device) Emitted upon any device event.
observeris theMonitorObserver, which emitted the signal.deviceis theDevice, which caused this event.Use
actionto get the type of event.
-
Deprecated API¶
-
class
pyudev.glib.GUDevMonitorObserver(monitor)¶ An observer for device events integrating into the
glibmainloop.Deprecated since version 0.17: Will be removed in 1.0. Use
MonitorObserverinstead.-
event_source¶ The event source, which represents the watch on the
monitor(as returned byglib.io_add_watch()), orNone, ifenabledisFalse.
-
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 emits the following GObject signals:
-
device-event(observer, action, device) Emitted upon any device event.
observeris theGUDevMonitorObserver, which emitted the signal.actionis a unicode string containing the action name, anddeviceis theDevice, 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
Deviceis added (e.g a USB device was plugged).
-
device-removed(observer, device) Emitted if a
Deviceis removed (e.g. a USB device was unplugged).
-
device-changed(observer, device) Emitted if a
Devicewas somehow changed (e.g. a change of a property)
-
device-moved(observer, device) Emitted if a
Devicewas renamed, moved or re-parented.
-