3 u1Wk@sdZddlmZddlmZddlmZddlmZddlZddlmZGdd d e Z Gd d d e Z d d Z Gddde Z Gddde ZdS)z pyudev._qt_base =============== Base mixin class for Qt4,Qt5 support. .. moduleauthor:: Sebastian Wiesner )absolute_import)division)print_function)unicode_literalsN)Devicec@sBeZdZdZddZeddZejddZddZd d Z d S) MonitorObserverMixinz0 Base mixin for pyqt monitor observers. cCs2||_||j|j||_|jjtj|jdS)N)monitorfilenoZReadnotifierZ activatedintZconnect_process_udev_event)selfrnotifier_classr/usr/lib/python3.6/_qt_base.py_setup_notifier+sz$MonitorObserverMixin._setup_notifiercCs |jjS)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 rrrenabled1s zMonitorObserverMixin.enabledcCs|jj|dS)N)r Z setEnabled)r valuerrrr?scCs$|jjdd}|dk r |j|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)ZtimeoutN)rZpoll _emit_event)r devicerrrr Csz(MonitorObserverMixin._process_udev_eventcCs|jj|dS)N) deviceEventemit)r rrrrrOsz MonitorObserverMixin._emit_eventN) __name__ __module__ __qualname____doc__rpropertyrsetterr rrrrrr%s   rc@s eZdZdZddZddZdS)QUDevMonitorObserverMixinz* Obsolete monitor observer mixin. cCs>tj||||j|j|j|jd|_ddl}|jdt dS)N)addremoveZchangeZmoverzAWill be removed in 1.0. Use pyudev.pyqt4.MonitorObserver instead.) rr deviceAdded deviceRemoved deviceChanged deviceMoved_action_signal_mapwarningswarnDeprecationWarning)r rrr&rrrrYs z)QUDevMonitorObserverMixin._setup_notifiercCs4|jj|j||jj|j}|dk r0|j|dS)N)rractionr%get)r rsignalrrrrdsz%QUDevMonitorObserverMixin._emit_eventN)rrrrrrrrrrrSs rcsdfdd }|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`. Ncsj|||j|dS)N)__init__r)r rparent)qobjectsocket_notifierrrr,ts zmake_init..__init__)Nr)r.r/r,r)r.r/r make_initjs r0c@seZdZdZeddZdS)MonitorObserverGeneratorz4 Class to generate a MonitorObserver class. cCs.ttd|tftdt||td|tiS)aGenerates 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`. ZMonitorObserverr,r)typestrrr0r)r.r+r/rrrmake_monitor_observers z.MonitorObserverGenerator.make_monitor_observerN)rrrr staticmethodr4rrrrr1|sr1c@seZdZdZeddZdS)QUDevMonitorObserverGeneratorz4 Class to generate a MonitorObserver class. cCsbttd|tftdt||td|tjttd|ttd|ttd|ttd|tiS)aGenerates 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`. ZQUDevMonitorObserverr,rr!r"r#r$)r2r3rr0sixZ text_typer)r.r+r/rrrr4s   z3QUDevMonitorObserverGenerator.make_monitor_observerN)rrrrr5r4rrrrr6sr6)rZ __future__rrrrr7Z pyudev.devicerobjectrrr0r1r6rrrrs     .'