pyudev.glib – Glib/Gtk 2 integration¶
Glib integration.
GUDevMonitorObserver 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.GUDevMonitorObserver(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 GUDevMonitorObserver >>> context = Context() >>> monitor = Monitor.from_netlink(context) >>> monitor.filter_by(subsystem='input') >>> observer = 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.-
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 defines 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.
-