a
    «ˆc¥  ã                   @   s~   d dl mZ d dlmZmZ d dlmZmZmZ d dl	m
Z
mZmZ d dlmZ dadadd„ ZG d	d
„ d
eƒZddd„ZdS )é    )Ú	ETSConfig)ÚGUIÚApplicationWindow)Ú	HasTraitsÚButtonÚAny)ÚViewÚGroupÚItem)Ú
guisupportNc                  C   sB   ddl m}  | jrdS tjdkr(t ¡ S tjdkr:t ¡ S dS dS )z3 Returns True if the UI event loop is running.
    é   ©ÚoptionsTÚwxZqt4FN)Zengine_managerr   Z	offscreenr   Útoolkitr   Zis_event_loop_running_wxZis_event_loop_running_qt4r   © r   úT/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/tools/show.pyÚis_ui_running   s    

r   c                       sN   e Zd Zeddd�ZeZeee	dƒdd�g dd�Z
‡ fd	d
„Zdd„ Z‡  ZS )ÚStopShowzStop interactionz&if the UI interaction is to be stopped)ÚdescÚstopF)Zshow_labelszControl Show)ZbuttonsÚtitlec                    s$   t t| ƒjf i |¤Ž |  ¡ | _d S ©N)Úsuperr   Ú__init__Zedit_traitsÚ_ui)ÚselfZtraits©Ú	__class__r   r   r   6   s    zStopShow.__init__c                 C   s   t  ¡  | j ¡  d S r   )Ú_guiZstop_event_loopr   Zdispose)r   r   r   r   Ú_stop_fired=   s    zStopShow._stop_fired)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r	   r
   Úviewr   r    Ú__classcell__r   r   r   r   r   #   s   ÿÿr   Fc                    s@   ˆ du r.t ƒ s*tƒ }|aˆr"tƒ a| ¡  dS ‡ ‡fdd„}|S )a]   Start interacting with the figure.

    By default, this function simply creates a GUI and starts its
    event loop if needed.

    If it is used as a decorator, then it may be used to decorate a
    function which requires a UI.   If the GUI event loop is already
    running it simply runs the function.  If not the event loop is
    started and function is run in the toolkit's event loop.  The choice
    of UI is via `ETSConfig.toolkit`.

    If the argument stop is set to True then it pops up a UI where the
    user can stop the event loop.  Subsequent calls to `show` will
    restart the event loop.

    **Parameters**

      :stop:  A boolean which specifies if a UI dialog is displayed which
              allows the event loop to be stopped.

    **Examples**

    Here is a simple example demonstrating the use of show::

      >>> from mayavi import mlab
      >>> mlab.test_contour3d()
      >>> mlab.show()

    You can stop interaction via a simple pop up UI like so::

      >>> mlab.test_contour3d()
      >>> mlab.show(stop=True)

    The decorator can be used like so::

      >>> @mlab.show
      ... def do():
      ...    mlab.test_contour3d()
      ...
      >>> do()

    The decorator can also be passed the stop argument::

      >>> @mlab.show(stop=True)
      ... def do():
      ...    mlab.test_contour3d()
      ...
      >>> do()

    Nc                     s~   t j}tƒ rˆ| i |¤ŽS tƒ }|dkrLtdd�‰ t ‡ fdd„¡ ˆ  ¡  tjˆg| ¢R i |¤Ž |aˆrrtƒ a	| 
¡  dS )zRWrapper function to run given function inside the GUI event
        loop.
        r   )r   r   )Úsizec                      s   ˆ   ¡ S r   )Úcloser   ©Úar   r   Ú<lambda>�   ó    z'show.<locals>.wrapper.<locals>.<lambda>N)r   r   r   r   r   Zinvoke_laterÚopenr   r   Ú
_stop_showÚstart_event_loop)ÚargsÚkwZtkÚg©Úfuncr   r(   r   Úwrapper   s    
zshow.<locals>.wrapper)r   r   r   r   r-   r.   )r3   r   r1   r4   r   r2   r   ÚshowB   s    4r5   )NF)Ztraits.etsconfig.apir   Z
pyface.apir   r   Z
traits.apir   r   r   Ztraitsui.apir   r	   r
   Zpyface.utilr   r   r-   r   r   r5   r   r   r   r   Ú<module>   s   