a
    ¦ˆcD  ã                   @   sÚ   d Z ddlZddlZddlZz"ddlmZ ddlmZ eƒ ZW n e	yT   dZ
Y n0 dZ
ddlmZ ddlmZmZmZmZ G d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZG dd„ deejƒZG dd„ deejƒZdS )a   Tests for dynamic notifiers with `dispatch='ui'`.

Dynamic notifiers created with the `dispatch='ui'` option dispatch event
notifications on the UI thread. The class handling the dispatch,
`FastUITraitChangeNotifyWrapper`, is a subclass of `TraitChangeNotifyWrapper`.
Most of the functionality of the class is thus already covered by the
`TestDynamicNotifiers` test case, and we only need to test that the
notification really occurs on the UI thread.

At present, `dispatch='ui'` and `dispatch='fast_ui'` have the same effect.

é    N)Úget_app_qt4)ÚtoolkitFT)Útrait_notifiers)ÚCallableÚFloatÚ	HasTraitsÚon_trait_changec                   @   s   e Zd ZeZdS )ÚCalledAsMethodN)Ú__name__Ú
__module__Ú__qualname__r   Úfoo© r   r   úa/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traits/tests/test_ui_notifiers.pyr	   2   s   r	   c                   @   s(   e Zd ZeZeZeddd�dd„ ƒZdS )ÚCalledAsDecoratorr   Úui©Údispatchc                 C   s   |   ||||¡ d S ©N©Úcallback)ÚselfÚobjÚnameÚoldÚnewr   r   r   Úon_foo_change;   s    zCalledAsDecorator.on_foo_changeN)	r
   r   r   r   r   r   r   r   r   r   r   r   r   r   6   s   
r   c                   @   sT   e Zd ZdZdd„ Zdd„ Zdd„ Ze e	 d¡d	d
„ ƒZ
e e	 d¡dd„ ƒZdS )ÚBaseTestUINotifiersz7 Tests for dynamic notifiers with `dispatch='ui'`.
    c                 C   s
   g | _ d S r   )Únotifications©r   r   r   r   ÚsetUpF   s    zBaseTestUINotifiers.setUpc                 C   s   t  ¡  t  ¡  dS )z! Post and process the Qt events. N)Úqt4_appZsendPostedEventsZprocessEventsr   r   r   r   Úflush_event_loopK   s    z$BaseTestUINotifiers.flush_event_loopc                 C   s*   t  ¡ j}|||||ff}| j |¡ d S r   )Ú	threadingÚcurrent_threadÚidentr   Úappend)r   r   r   r   r   Ú	thread_idÚeventr   r   r   Úon_foo_notificationsP   s    
z(BaseTestUINotifiers.on_foo_notificationsz2Qt event loop not found, UI dispatch not possible.c                 C   sb   |   ¡ }d|_|  ¡  | j}|  t|ƒd¡ |d \}}|  ||dddf¡ tj}|  ||¡ d S )Né   é   r   r   )Úobj_factoryr   r"   r   ÚassertEqualÚlenr   Ú	ui_thread)r   r   r   r'   r(   r/   r   r   r   Ú"test_notification_from_main_threadW   s    z6BaseTestUINotifiers.test_notification_from_main_threadc                 C   s‚   |   ¡ }dd„ }tj||fd� ¡  t d¡ |  ¡  | j}|  t	|ƒd¡ |d \}}|  ||dddf¡ t
j}|  ||¡ d S )	Nc                 S   s
   d| _ d S )Nr*   )r   )r   r   r   r   Úset_foo_to_3r   s    zPBaseTestUINotifiers.test_notification_from_separate_thread.<locals>.set_foo_to_3)ÚtargetÚargsgš™™™™™¹?r+   r   r   r*   )r,   r#   ÚThreadÚstartÚtimeÚsleepr"   r   r-   r.   r   r/   )r   r   r1   r   r'   r(   r/   r   r   r   Ú&test_notification_from_separate_threadj   s    
z:BaseTestUINotifiers.test_notification_from_separate_threadN)r
   r   r   Ú__doc__r    r"   r)   ÚunittestZskipIfÚQT_FOUNDr0   r8   r   r   r   r   r   @   s   ÿ
ÿr   c                   @   s   e Zd ZdZdd„ ZdS )ÚTestMethodUINotifierszJ Tests for dynamic notifiers with `dispatch='ui'` set by method call.
    c                 C   s   t ƒ }|j| jddd� |S )Nr   r   r   )r	   r   r)   )r   r   r   r   r   r,   Š   s    z!TestMethodUINotifiers.obj_factoryN©r
   r   r   r9   r,   r   r   r   r   r<   †   s   r<   c                   @   s   e Zd ZdZdd„ ZdS )ÚTestDecoratorUINotifierszD Tests for dynamic notifiers with `dispatch='ui'` set by decorator. c                 C   s   t | jd�S )Nr   )r   r)   r   r   r   r   r,   “   s    z$TestDecoratorUINotifiers.obj_factoryNr=   r   r   r   r   r>   �   s   r>   )r9   r#   r6   r:   Zpyface.util.guisupportr   Ztraitsui.qt4r   r!   Ú	Exceptionr;   Ztraitsr   Z
traits.apir   r   r   r   r	   r   Úobjectr   ZTestCaser<   r>   r   r   r   r   Ú<module>   s"   


F
