a
8g+^ @ s d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlmZ G dd d e Z
G d
d de
Zdd
ZG dd de Z
G dd de ZdS )z
pyudev._qt_base
===============
Base mixin class for Qt4,Qt5 support.
.. moduleauthor:: Sebastian Wiesner
)absolute_import)division)print_function)unicode_literalsN)Devicec @ sB e Zd ZdZdd Zedd Zejdd Zdd Zd d
Z dS )MonitorObserverMixinz0
Base mixin for pyqt monitor observers.
c C s2 || _ || |j| | _| jjt | j d S N)monitorfilenoZReadnotifierZ activatedintZconnect_process_udev_event)selfr notifier_class r 3/usr/lib/python3.9/site-packages/pyudev/_qt_base.py_setup_notifier+ s
z$MonitorObserverMixin._setup_notifierc C s
| j S )aY
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
:attr:`notifier`.
.. versionadded:: 0.14
)r Z isEnabled)r r r r enabled1 s zMonitorObserverMixin.enabledc C s | j | d S r )r Z
setEnabled)r valuer r r r ? s c C s$ | j jdd}|dur | | dS )z
Attempt to receive a single device event from the monitor, process
the event and emit corresponding signals.
Called by ``QSocketNotifier``, if data is available on the udev
monitoring socket.
r )timeoutN)r Zpoll_emit_eventr devicer r r r
C s z(MonitorObserverMixin._process_udev_eventc C s | j | d S r )deviceEventemitr r r r r O s z MonitorObserverMixin._emit_eventN)
__name__
__module____qualname____doc__r propertyr setterr
r r r r r r $ s
r c @ s e Zd ZdZdd Zdd ZdS )QUDevMonitorObserverMixinz*
Obsolete monitor observer mixin.
c C s> t | || | j| j| j| jd| _dd l}|dt d S )N)addremoveZchangemover zAWill be removed in 1.0. Use pyudev.pyqt4.MonitorObserver instead.)
r r deviceAdded
deviceRemoved
deviceChangeddeviceMoved_action_signal_mapwarningswarnDeprecationWarning)r r r r* r r r r Z s z)QUDevMonitorObserverMixin._setup_notifierc C s4 | j |j| | j|j}|d ur0|| d S r )r r actionr) get)r r signalr r r r g s z%QUDevMonitorObserverMixin._emit_eventN)r r r r r r r r r r r! S s
r! c s d fdd }|S )a
Generates an initializer to observer the given ``monitor``
(a :class:`~pyudev.Monitor`):
``parent`` is the parent :class:`~PyQt{4,5}.QtCore.QObject` of this
object. It is passed unchanged to the inherited constructor of
:class:`~PyQt{4,5}.QtCore.QObject`.
Nc s | | | | d S r )__init__r )r r parentqobjectsocket_notifierr r r0 x s zmake_init..__init__)Nr )r3 r4 r0 r r2 r make_initn s
r5 c @ s e Zd ZdZedd ZdS )MonitorObserverGenerator4
Class to generate a MonitorObserver class.
c C s. t td| tftdt| |td|tiS )a Generates an observer for device events integrating into the
PyQt{4,5} mainloop.
This class inherits :class:`~PyQt{4,5}.QtCore.QObject` to turn device
events into Qt signals:
>>> from pyudev import Context, Monitor
>>> from pyudev.pyqt4 import MonitorObserver
>>> context = Context()
>>> monitor = Monitor.from_netlink(context)
>>> monitor.filter_by(subsystem='input')
>>> observer = MonitorObserver(monitor)
>>> def device_event(device):
... print('event {0} on device {1}'.format(device.action, device))
>>> observer.deviceEvent.connect(device_event)
>>> monitor.start()
This class is a child of :class:`~{PySide, PyQt{4,5}}.QtCore.QObject`.
ZMonitorObserverr0 r )typestrr r5 r r3 r/ r4 r r r make_monitor_observer s z.MonitorObserverGenerator.make_monitor_observerNr r r r staticmethodr; r r r r r6 s r6 c @ s e Zd ZdZedd ZdS )QUDevMonitorObserverGeneratorr7 c C sb t td| tftdt| |td|tjttd|ttd|ttd|ttd|tiS )a Generates an observer for device events integrating into the
PyQt{4,5} mainloop.
This class inherits :class:`~PyQt{4,5}.QtCore.QObject` to turn device
events into Qt signals:
>>> from pyudev import Context, Monitor
>>> from pyudev.pyqt4 import MonitorObserver
>>> context = Context()
>>> monitor = Monitor.from_netlink(context)
>>> monitor.filter_by(subsystem='input')
>>> observer = MonitorObserver(monitor)
>>> def device_event(device):
... print('event {0} on device {1}'.format(device.action, device))
>>> observer.deviceEvent.connect(device_event)
>>> monitor.start()
This class is a child of :class:`~{PyQt{4,5}, PySide}.QtCore.QObject`.
ZQUDevMonitorObserverr0 r r% r&