
    BPc                     <    d Z ddlZddlmZmZ  G d d          ZdS )z8
Structures for consistant testing of Gtk GUI programs.
    N)GtkGLibc                   2    e Zd ZdZd	dZd Zd Zd Zd ZdS )
MainLoopProtectiona  
    This protection class provides a way to launch the Gtk mainloop in a test
    friendly way.

    Exception handling hooks provide a way to see errors that happen
        inside the main loop, raising them back to the caller.
    A full timeout in seconds stops the gtk mainloop from operating
        beyond a set time, acting as a kill switch in the event something
        has gone horribly wrong.

    Use:
        with MainLoopProtection(timeout=10s):
            app.run()
    
   c                 6    |dz  | _         d | _        d | _        d S )Ni  )timeout_hooked_old_excepthook)selfr	   s     2/usr/share/inkscape/extensions/inkex/gui/tester.py__init__zMainLoopProtection.__init__*   s"    ~#    c                     t           j        | _        | j        t           _        t          j        | j        | j                  | _        d S )N)sys
excepthookr   r   timeout_addr	   	idle_exit_timeoutr   s    r   	__enter__zMainLoopProtection.__enter__/   s1    "~(t~FFr   c                     | j         r| j         t          _        | j        rt	          j        | j                   | j        r| j        \  }}}|r|r|                    |          dS dS )zAPut the except handler back, cancel the timer and raise if neededN)r   r   r   r   r   source_remover
   with_traceback)r   excvalue	tracebacks       r   __exit__zMainLoopProtection.__exit__6   s     	2!1CN= 	.t}---< 	1$(L!C	 	2Y 	2&&y111	2 	2 	2 	2r   c                 B    t          j        t          j                   dS )z*Try to going to kill any running mainloop.N)r   idle_addr   	main_quitr   s    r   r   zMainLoopProtection.idle_exitC   s    cm$$$$$r   c                 p    |                                   |
|||g| _        |                     |||          S )z'Catch errors thrown by the Gtk mainloop)r   r
   r   )r   ex_typeex_valuer   s       r   r   zMainLoopProtection.excepthookG   s>    #Xy9DL##GXyAAAr   N)r   )	__name__
__module____qualname____doc__r   r   r   r   r    r   r   r   r      sv         $ $ $ $
G G G2 2 2% % %B B B B Br   r   )r(   r   gi.repositoryr   r   r   r)   r   r   <module>r+      sn   $  


 # # # # # # # #4B 4B 4B 4B 4B 4B 4B 4B 4B 4Br   