
    Vh                         d Z ddlmZmZ 	 ddlmZmZm	Z
 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y# e$ r ddlmZmZm
Z
 Y Fw xY w)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y)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                  |        || _        y N)r
   __init__wxappselfr   s     J/home/dcms/DCMS/lib/python3.12/site-packages/twisted/internet/wxreactor.pyr   zProcessEventsTimer.__init__2   s    
    c                 8    | j                   j                          y)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
y	)	WxReactorz[
    wxPython reactor.

    wxPython drives the event loop, select() runs in a thread.
    Fc                     || _         y)z;
        Register wxApp instance with the reactor.
        N)r   r   s     r   registerWxAppzWxReactor.registerWxAppF   s     
r   c                     	 ddl }|j                  |j                  |j                         | j                  j                          y# t        $ r Y yw xY w)zO
        wx sometimes removes our own signal handlers, so re-add them.
        r   N)signalSIGINTdefault_int_handlerImportError_signalsinstall)r   r&   s     r   _installSignalHandlersAgainz%WxReactor._installSignalHandlersAgainL   sH    	MM&--)C)CD 	  		s   *A 	AAc                 j    | j                   ryd| _         t        j                  j                  |        y)z#
        Stop the reactor.
        NT)	_stoppingr   ThreadedSelectReactorstopr   s    r   r0   zWxReactor.stopY   s)     >>--2248r   c                 j    t        | d      rt        |       y| j                  j                  |       y)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   s)     4!N OO"r   c                 R    t        | d      r| j                  j                          yy)z
        Stop the wx event loop if it hasn't already been stopped.

        Called during Twisted event loop shutdown.
        r   N)r2   r   ExitMainLoopr   s    r   _stopWxzWxReactor._stopWxn   s#     4!JJ##% "r   c                 \    t                _        t         d      s.t        j                  d        j                  t                       j                   j                  |       |r j                  d j                          j                  dd j                          j                  dd fd       t        j                  j                         r&t!         j"                        }|j%                  d        j"                  j'                           j"                  } ` j(                  sJ j+                          |j-                          	 	  j                  j/                  d	
      }|y	  |        )y# t0        $ r t        j2                          Y !w xY w# t4        $ r Y Yw xY w)z$
        Start the reactor.
        r   zMregisterWxApp() was not called on reactor, registering my own wxApp instance.)installSignalHandlersr   aftershutdownc                  :     j                   j                  d       S r   )r3   r4   r   s   r   <lambda>zWxReactor.run.<locals>.<lambda>   s    )<)<T)B r      g{Gz?)timeoutN)r   r3   r2   r   msgr$   r   
interleaver6   	callLaterr,   addSystemEventTriggerr9   r   platformisMacOSXr   r   StartMainLoopr.   r0   r   getBaseExceptionerrr   )r   r;   tr   r5   s   `    r   runzWxReactor.runw   st     'tW%GG5 }/ 	!!9N 	 	
 !NN1d>>? 	""7JE""Z!B	
 $$&"4::.AGGAJ



J~~ IIK&&(
"++D+9A y"  $ ) "	"  s$   F 3E< <FF	F+*F+N)T)r   r   r   r   r.   r$   r,   r0   r6   r9   rN   r    r   r   r"   r"   =   s,     I 9
#&7"r   r"   c                  6    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   r+   r+      s     kG47Nr   r+   N)r   queuer   r   wxr   r	   r   r   r   r
   r)   wxPython.wxtwisted.internetr   twisted.pythonr   r   r   r/   r"   r+   __all__r    r   r   <module>rY      sp   , @  - '* *&q"55 q"h +u  @??@s   
A AA