pyudev.glib – Glib/Gtk 2 integration — pyudev 0.21.0 documentation

# `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 `glib` mainloop.

  This class inherits `GObject` to 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`.

  `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 emits the following GObject signal:

  `device-event(observer, action, device)`

    Emitted upon any device event.

    `observer` is the `MonitorObserver`, which emitted the signal. `device` is the `Device`, which caused this event.

    Use `action` to get the type of event.

## Deprecated API

class `pyudev.glib.` `GUDevMonitorObserver`(monitor)

  An observer for device events integrating into the `glib` mainloop.

  Deprecated since version 0.17: Will be removed in 1.0. Use `MonitorObserver` instead.

  `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 emits 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.