File: toolkit.rst

package info (click to toggle)
pyudev 0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 468 kB
  • sloc: python: 2,481; makefile: 18
file content (167 lines) | stat: -rw-r--r-- 4,794 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
Toolkit integration
===================

Qt integration
--------------

To plug monitoring with :class:`pyudev.Monitor` into the Qt event loop, so
that Qt signals are asynchronously emitted upon events,
:class:`QUDevMonitorObserver` is provided:

.. class:: QUDevMonitorObserver

   Observe a :class:`~pyudev.Monitor` and emit Qt signals upon device
   events:

   >>> context = pyudev.Context()
   >>> monitor = pyudev.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 :class:`QtCore.QObject`.

   .. method:: __init__(monitor, parent=None)

      Observe the given ``monitor`` (a :class:`pyudev.Monitor`).

      ``parent`` is the parent :class:`~QtCore.QObject` of this object.  It
      is passed straight to the inherited constructor of
      :class:`~QtCore.QObject`.

   .. attribute:: monitor

      The :class:`~pyudev.Monitor` observed by this object.

   .. attribute:: notifier

      The underlying :class:`QtCore.QSocketNotifier` used to watch the
      :attr:`monitor`

   .. rubric:: Signals

   This class defines the following Qt signals:

   .. method:: deviceEvent(action, device)

      Emitted upon any device event.  ``action`` is a unicode string
      containing the action name, and ``device`` is the
      :class:`~pyudev.Device` object describing the device.

      Basically the arguments of this signal are simply the return value of
      :meth:`~pyudev.Monitor.receive_device`

   .. method:: deviceAdded(device)

      Emitted if a :class:`~pyudev.Device` is added (e.g a USB device was
      plugged).

   .. method:: deviceRemoved(device)

      Emitted if a :class:`~pyudev.Device` is removed (e.g. a USB device was
      unplugged).

   .. method:: deviceChanged(device)

      Emitted if a :class:`~pyudev.Device` was somehow changed (e.g. a
      change of a property)

   .. method:: deviceMoved(device)

      Emitted if a :class:`~pyudev.Device` was renamed, moved or
      re-parented.


Currently there are two different, incompatible bindings to Qt4:

PyQt4_
   Older, more mature, but developed by a 3rd party (Riverbank computing)
   and distributed under the GPL (though with some exceptions for other free
   software licences)

PySide_
   Developed by Nokia as alternative to PyQt4_ and distributed under the
   less restrictive LGPL, however not yet as mature and feature-rich as
   PyQt4_.

For both of these bindings a :class:`QUDevMonitorObserver` implementation is
provided, each in a separate module:

:mod:`pyudev.pyqt4`
^^^^^^^^^^^^^^^^^^^

.. automodule:: pyudev.pyqt4
   :platform: Linux
   :synopsis: PyQt4 integration

.. class:: QUDevMonitorObserver

   A :class:`QUDevMonitorObserver` implementation for PyQt4_

:mod:`pyudev.pyside`
^^^^^^^^^^^^^^^^^^^^

.. automodule:: pyudev.pyside
   :platform: Linux
   :synopsis: PySide integration

.. class:: QUDevMonitorObserver

   A :class:`QUDevMonitorObserver` implementation for PySide_


:mod:`pyudev.glib` – Glib and Gtk integration
---------------------------------------------

.. automodule:: pyudev.glib
   :platform: Linux
   :synopsis: Glib integration

.. autoclass:: GUDevMonitorObserver

   .. attribute:: monitor

      The :class:`~pyudev.Monitor` observed by this object.

   .. attribute:: event_source

      The event source, which represents the watch on the :attr:`monitor`
      (as returned by :func:`glib.io_add_watch`).  Can be passed to
      :func:`glib.source_remove` to stop observing the monitor.

   .. rubric:: Signals

   This class defines the following GObject signals:

   .. method:: device-event(observer, action, device)

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

      Basically the last two arguments of this signal are simply the
      return value of :meth:`~pyudev.Monitor.receive_device`

   .. method:: device-added(observer, device)

      Emitted if a :class:`~pyudev.Device` is added (e.g a USB device was
      plugged).

   .. method:: device-removed(observer, device)

      Emitted if a :class:`~pyudev.Device` is removed (e.g. a USB device was
      unplugged).

   .. method:: device-changed(observer, device)

      Emitted if a :class:`~pyudev.Device` was somehow changed (e.g. a
      change of a property)

   .. method:: device-moved(observer, device)

      Emitted if a :class:`~pyudev.Device` was renamed, moved or
      re-parented.