a
    §ˆc   ã                   @   sN   d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 G dd„ dƒZ
dS )	zF Define top-level object(s) to support testing TraitsUI applications.
é    N)Úprocess_cascade_events)Úreraise_exceptions)Úget_default_registries)Ú	UIWrapperc                   @   sV   e Zd ZdZddddœdd„Zedd	„ ƒZejdd
d„ƒZ	dd„ Z
dd„ Zdd„ ZdS )ÚUITestera•  UITester assists testing of GUI applications developed using TraitsUI.

    See :ref:`testing-traitsui-applications` Section in the User Manual for
    further details.

    Parameters
    ----------
    registries : list of TargetRegistry, optional
        Registries of interaction for different targets, in the order
        of decreasing priority. If provided, a shallow copy will be made.
        Additional registries are appended to the list to provide
        builtin support for TraitsUI UI and editors.
    delay : int, optional
        Time delay (in ms) in which actions by the tester are performed. Note
        it is propagated through to created child wrappers. The delay allows
        visual confirmation test code is working as desired. Defaults to 0.
    auto_process_events : bool, optional
        Whether to process (cascade) GUI events automatically. Default is True.
        For tests that launch a modal dialog and rely on a recurring timer to
        poll if the dialog is closed, it may be necessary to set this flag to
        false in order to avoid deadlocks. Note that this is propagated
        through to created child wrappers.

    Attributes
    ----------
    delay : int
        Time delay (in ms) in which actions by the tester are performed. Note
        it is propagated through to created child wrappers. The delay allows
        visual confirmation test code is working as desired.
    Nr   T)Ú
registriesÚdelayÚauto_process_eventsc                C   s8   |d u rg | _ n
| ¡ | _ | j  tƒ ¡ || _|| _d S )N)Ú_registriesÚcopyÚextendr   r   Ú_auto_process_events)Úselfr   r   r	   © r   úd/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/testing/tester/ui_tester.pyÚ__init__8   s    
zUITester.__init__c                 C   s   | j S )a  Flag to indicate whether to process (cascade) GUI events
        automatically. This is propagated through to
        :class:`~traitsui.testing.tester.ui_wrapper.UIWrapper` instances
        created from this tester.

        This value can only be set at instantiation.
        )r   )r   r   r   r   r	   E   s    zUITester.auto_process_eventsc                 c   sæ   |du ri n|}|j f i |¤Ž}zd|V  W tƒ �D | jr>tƒ  z| ¡  W | jrftƒ  n| jrdtƒ  0 W d  ƒ qâ1 sz0    Y  n\tƒ �D | jrštƒ  z| ¡  W | jrÂtƒ  n| jrÀtƒ  0 W d  ƒ n1 sÖ0    Y  0 dS )al  Context manager to create a UI and dispose it upon exit.

        This method does not modify the states of the :class:`UITester` and is
        not a requirement for using other methods on the tester.

        Parameters
        ----------
        object : HasTraits
            An instance of HasTraits for which a GUI will be created.
        ui_kwargs : dict or None, optional
            Keyword arguments to be provided to ``HasTraits.edit_traits``.
            Default is to call ``edit_traits`` with no additional keyword
            arguments.

        Yields
        ------
        ui : traitsui.ui.UI
        N)Zedit_traitsr   r   r   Zdispose)r   ÚobjectZ	ui_kwargsÚuir   r   r   Ú	create_uiS   s,    
ÿ(ò
ÿzUITester.create_uic                 C   s   |   |¡j|d�S )a.  Find the TraitsUI editor with the given name and return a new
        ``UIWrapper`` object for further interactions with the editor.

        ``name`` is typically a value defined on
        :attr:`traitsui.item.Item.name`. This name is passed onto
        :func:`traitsui.ui.UI.get_editors`.

        Parameters
        ----------
        ui : traitsui.ui.UI
            The UI created, e.g. by ``create_ui``.
        name : str
            A single name for retrieving a target on a UI.

        Returns
        -------
        wrapper : UIWrapper
        )Úname)Ú_get_wrapperÚfind_by_name)r   r   r   r   r   r   r   }   s    zUITester.find_by_namec                 C   s   |   |¡j|d�S )aJ  Find the TraitsUI editor with the given identifier and return a new
        ``UIWrapper`` object for further interactions with the editor.

        ``id`` is typically a value defined on :attr:`traitsui.item.Item.id`
        or :attr:`traitsui.group.Group.id`. This provides a shortcut to locate
        a very nested editor in a view.

        Parameters
        ----------
        ui : traitsui.ui.UI
            The UI created, e.g. by ``create_ui``.
        id : str
            Id for finding an item in the UI.

        Returns
        -------
        wrapper : UIWrapper
        )Úid)r   Ú
find_by_id)r   r   r   r   r   r   r   ’   s    zUITester.find_by_idc                 C   s   t || j| j| jd�S )zõReturn a new UIWrapper wrapping the given traitsui.ui.UI.

        Parameters
        ----------
        ui : traitsui.ui.UI
            The UI created, e.g. by ``create_ui``.

        Returns
        -------
        wrapper : UIWrapper
        )Útargetr   r   r	   )r   r
   r   r   )r   r   r   r   r   r   §   s    üzUITester._get_wrapper)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr	   Ú
contextlibÚcontextmanagerr   r   r   r   r   r   r   r   r      s   
)r   )r   r    Ztraitsui.testing._guir   Z$traitsui.testing._exception_handlingr   Z<traitsui.testing.tester._ui_tester_registry.default_registryr   Z"traitsui.testing.tester.ui_wrapperr   r   r   r   r   r   Ú<module>   s   