o
    8g+^                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlmZ G dd	 d	e	Z
G d
d de
Zdd ZG dd de	ZG dd de	ZdS )z
    pyudev._qt_base
    ===============

    Base mixin class for Qt4,Qt5 support.

    .. moduleauthor::  Sebastian Wiesner  <lunaryorn@gmail.com>
    )absolute_import)division)print_function)unicode_literalsN)Devicec                   @   sB   e Zd ZdZdd Zedd Zejdd Zdd Zd	d
 Z	dS )MonitorObserverMixinz0
    Base mixin for pyqt monitor observers.
    c                 C   s2   || _ || |j| | _| jjt | j d S N)monitorfilenoReadnotifier	activatedintconnect_process_udev_event)selfr	   notifier_class r   1/usr/lib/python3/dist-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   	isEnabled)r   r   r   r   enabled1   s   
zMonitorObserverMixin.enabledc                 C      | j | d S r   )r   
setEnabled)r   valuer   r   r   r   ?   s   c                 C   s(   | j jdd}|dur| | dS dS )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	   poll_emit_eventr   devicer   r   r   r   C   s   z(MonitorObserverMixin._process_udev_eventc                 C   r   r   )deviceEventemitr   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 Zd ZdZdd Zdd ZdS )QUDevMonitorObserverMixinz*
    Obsolete monitor observer mixin.
    c                 C   s>   t | || | j| j| j| jd| _dd l}|dt	 d S )N)addremovechangemover   zAWill be removed in 1.0. Use pyudev.pyqt4.MonitorObserver instead.)
r   r   deviceAddeddeviceRemoveddeviceChangeddeviceMoved_action_signal_mapwarningswarnDeprecationWarning)r   r	   r   r2   r   r   r   r   Z   s   z)QUDevMonitorObserverMixin._setup_notifierc                 C   s8   | j |j| | j|j}|d ur|| d S d S r   )r    r!   actionr1   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 fdd	}|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	   parentqobjectsocket_notifierr   r   r8   x   s   zmake_init.<locals>.__init__r   r   )r;   r<   r8   r   r:   r   	make_initn   s   
r=   c                   @      e Zd ZdZedd ZdS )MonitorObserverGenerator4
    Class to generate a MonitorObserver class.
    c                 C   s.   t td| tftdt| |td|tiS )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`.

        MonitorObserverr8   r    )typestrr   r=   r   r;   r7   r<   r   r   r   make_monitor_observer   s   z.MonitorObserverGenerator.make_monitor_observerNr"   r#   r$   r%   staticmethodrE   r   r   r   r   r?          r?   c                   @   r>   )QUDevMonitorObserverGeneratorr@   c                 C   sb   t td| tftdt| |td|tjttd|ttd|ttd|ttd|tiS )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`.

        QUDevMonitorObserverr8   r    r-   r.   r/   r0   )rB   rC   r(   r=   six	text_typer   rD   r   r   r   rE      s"   
z3QUDevMonitorObserverGenerator.make_monitor_observerNrF   r   r   r   r   rI      rH   rI   )r%   
__future__r   r   r   r   rK   pyudev.devicer   objectr   r(   r=   r?   rI   r   r   r   r   <module>   s   	/#