
    \d                         d Z ddlmZmZ 	 ddlmZmZm	Z
 n# e$ r ddlmZmZm
Z
 Y nw xY wddlmZ ddlmZmZ  G d de
          Z G d	 d
ej                  Zd ZdgZdS )aa  
This module provides wxPython event loop support for Twisted.

In order to use this support, simply do the following::

    |  from twisted.internet import wxreactor
    |  wxreactor.install()

Then, when your root wxApp has been created::

    | from twisted.internet import reactor
    | reactor.registerWxApp(yourApp)
    | reactor.run()

Then use twisted.internet APIs as usual. Stop the event loop using
reactor.stop(), not yourApp.ExitMainLoop().

IMPORTANT: tests will fail when run under this reactor. This is
expected and probably does not reflect on the reactor's ability to run
real applications.
    )EmptyQueue)	CallAfterPySimpleAppTimer)wxPySimpleAppwxCallAfterwxTimer)_threadedselect)logruntimec                       e Zd ZdZd Zd ZdS )ProcessEventsTimerz
    Timer that tells wx to process pending events.

    This is necessary on macOS, probably due to a bug in wx, if we want
    wxCallAfters to be handled when modal dialogs, menus, etc.  are open.
    c                 <    t          j        |            || _        d S N)r
   __init__wxappselfr   s     :lib/python3.11/site-packages/twisted/internet/wxreactor.pyr   zProcessEventsTimer.__init__2   s    


    c                 8    | j                                          dS )z5
        Called repeatedly by wx event loop.
        N)r   ProcessPendingEventsr   s    r   NotifyzProcessEventsTimer.Notify6   s     	
'')))))r   N)__name__
__module____qualname____doc__r   r    r   r   r   r   *   s<           * * * * *r   r   c                   <    e Zd ZdZdZd Zd Zd Zd Zd Z	dd	Z
d
S )	WxReactorz[
    wxPython reactor.

    wxPython drives the event loop, select() runs in a thread.
    Fc                     || _         dS )z;
        Register wxApp instance with the reactor.
        N)r   r   s     r   registerWxAppzWxReactor.registerWxAppF   s     


r   c                     	 ddl }|                     |j        |j                   n# t          $ r Y dS w xY w|                                  dS )zO
        wx sometimes removes our own signal handlers, so re-add them.
        r   N)signalSIGINTdefault_int_handlerImportError_handleSignals)r   r&   s     r   _installSignalHandlersAgainz%WxReactor._installSignalHandlersAgainL   sf    	MMMMM&-)CDDDD 	 	 	FF	s   $' 
55c                 d    | j         rdS d| _         t          j                            |            dS )z#
        Stop the reactor.
        NT)	_stoppingr   ThreadedSelectReactorstopr   s    r   r/   zWxReactor.stopY   s7     > 	F-22488888r   c                 |    t          | d          rt          |           dS | j                            |           dS )zm
        Schedule function to run in main wx/Twisted thread.

        Called by the select() thread.
        r   N)hasattrr	   
_postQueueput)r   fs     r   _runInMainThreadzWxReactor._runInMainThreadb   sC     4!! 	#NNNNN O"""""r   c                 \    t          | d          r| j                                         dS dS )z
        Stop the wx event loop if it hasn't already been stopped.

        Called during Twisted event loop shutdown.
        r   N)r1   r   ExitMainLoopr   s    r   _stopWxzWxReactor._stopWxn   s:     4!! 	&J##%%%%%	& 	&r   Tc                     t                       _        t           d          s5t          j        d                                t                                                       j        |           |r 	                    d j
                                        dd j                                        dd fd           t          j                                        r)t!           j                  }|                    d            j                                          j        } ` j        s                                  |                                 	 	  j                            d
          }|dS 	  |             n3# t0          $ r t          j                     Y nw xY w# t4          $ r Y \w xY w`dS )z$
        Start the reactor.
        r   zMregisterWxApp() was not called on reactor, registering my own wxApp instance.)installSignalHandlersr   aftershutdownc                  8     j                             d           S r   )r2   r3   r   s   r   <lambda>zWxReactor.run.<locals>.<lambda>   s    )<)<T)B)B r         g{Gz?)timeoutN)r   r2   r1   r   msgr$   r   
interleaver5   	callLaterr+   addSystemEventTriggerr8   r   platformisMacOSXr   r   StartMainLoopr-   r/   r   getBaseExceptionerrr   )r   r:   tr   r4   s   `    r   runzWxReactor.runw   s     ''tW%% 	0G5   }/// 	!9N 	 	
 	
 	
 ! 	@NN1d>??? 	""7JEEE""Z!B!B!B!B	
 	
 	
 $$&& 	"4:..AGGAJJJ

J~ 	" IIKKK&&((("
"++D+99A y"( " " "					"    H"	" 	"s$   #F1 
F F.-F.1
F>=F>N)T)r   r   r   r   r-   r$   r+   r/   r5   r8   rN   r    r   r   r"   r"   =   s          I    9 9 9
# 
# 
#& & &7" 7" 7" 7" 7" 7"r   r"   c                  D    t                      } ddlm}  ||            | S )zP
    Configure the twisted mainloop to be run inside the wxPython mainloop.
    r   )installReactor)r"   twisted.internet.mainrP   )reactorrP   s     r   installrS      s4     kkG444444N7Nr   rS   N)r   queuer   r   wxr   r	   r   r   r   r
   r)   wxPython.wxtwisted.internetr   twisted.pythonr   r   r   r.   r"   rS   __all__r    r   r   <module>rZ      sS   ,        @          
  @ @ @????????????@ - , , , , , ' ' ' ' ' ' ' '* * * * * * * *&q" q" q" q" q"5 q" q" q"h   +s   
 ))