o
    8g+^                     @   s   d Z ddlmZmZmZmZ ddlmZmZ ddl	m
Z
 ddlZe
 \ZZG dd deZe
 \ZZe
 \ZZe
 \ZZe
 \ZZG dd	 d	eZdS )
a  pyudev.wx
    =========

    Wx integration.

    :class:`MonitorObserver` integrates device monitoring into the wxPython\_
    mainloop by turing device events into wx events.

    :mod:`wx` from wxPython\_ must be available when importing this module.

    .. _wxPython: http://wxpython.org/

    .. moduleauthor::  Tobias Eberle  <tobias.eberle@gmx.de>
    .. versionadded:: 0.14

    )print_functiondivisionunicode_literalsabsolute_import)
EvtHandler	PostEvent)NewEventNc                   @   sJ   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d Z
dS )MonitorObservera  
    An observer for device events integrating into the :mod:`wx` mainloop.

    This class inherits :class:`~wx.EvtHandler` to turn device events into
    wx events:

    >>> from pyudev import Context, Monitor
    >>> from pyudev.wx import MonitorObserver
    >>> context = Context()
    >>> monitor = Monitor.from_netlink(context)
    >>> monitor.filter_by(subsystem='input')
    >>> observer = MonitorObserver(monitor)
    >>> def device_event(event):
    ...     print('action {0} on device {1}'.format(event.device.action, event.device))
    >>> observer.Bind(EVT_DEVICE_EVENT, device_event)
    >>> monitor.start()

    This class is a child of :class:`wx.EvtHandler`.

    .. versionadded:: 0.17
    c                 C   s"   t |  || _d | _|   d S N)r   __init__monitor_observer_threadstart)selfr    r   +/usr/lib/python3/dist-packages/pyudev/wx.pyr   C   s   
zMonitorObserver.__init__c                 C   s
   | j duS )z
        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.
        N)r   r   r   r   r   enabledI   s   
zMonitorObserver.enabledc                 C   s   |r|    d S |   d S r
   )r   stop)r   valuer   r   r   r   S   s   c                 C   s2   | j durdS tj| j| jdd| _ | j   dS )z`
        Enable this observer.

        Do nothing, if the observer is already enabled.
        Nzwx-observer-thread)callbackname)r   pyudevr	   r   _emit_eventr   r   r   r   r   r   Z   s   

zMonitorObserver.startc                 C   s   | j du rdS | j   dS )zb
        Disable this observer.

        Do nothing, if the observer is already disabled.
        N)r   r   r   r   r   r   r   f   s   
zMonitorObserver.stopc                 C   s   t | t|d d S )Ndevice)r   DeviceEvent)r   r   r   r   r   r   p   s   zMonitorObserver._emit_eventN)__name__
__module____qualname____doc__r   propertyr   setterr   r   r   r   r   r   r   r	   ,   s    
	

r	   c                   @   s.   e Zd ZdZeeeedZdd Z	dd Z
dS )WxUDevMonitorObserverzAn observer for device events integrating into the :mod:`wx` mainloop.

    .. deprecated:: 0.17
       Will be removed in 1.0.  Use :class:`MonitorObserver` instead.
    )addremovechangemovec                 C   s$   t | | dd l}|dt d S )Nr   z>Will be removed in 1.0. Use pyudev.wx.MonitorObserver instead.)r	   r   warningswarnDeprecationWarning)r   r   r(   r   r   r   r      s
   zWxUDevMonitorObserver.__init__c                 C   sB   t | t|j|d | j|j}|d urt | ||d d S d S )N)actionr   r   )r   r   r+   _action_event_mapget)r   r   event_classr   r   r   r      s
   z!WxUDevMonitorObserver._emit_eventN)r   r   r   r    DeviceAddedEventDeviceRemovedEventDeviceChangedEventDeviceMovedEventr,   r   r   r   r   r   r   r#   z   s    r#   )r    
__future__r   r   r   r   wxr   r   wx.lib.neweventr   r   r   EVT_DEVICE_EVENTr	   r/   EVT_DEVICE_ADDEDr0   EVT_DEVICE_REMOVEDr1   EVT_DEVICE_CHANGEDr2   EVT_DEVICE_MOVEDr#   r   r   r   r   <module>   s   

H


