o b@sdZddlmZmZz ddlmZmZm Z Wne y)ddl mZmZm Z Ynwddl mZddlmZmZGddde ZGd d d ejZd d Zd gZd 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. )EmptyQueue) CallAfter PySimpleAppTimer) wxPySimpleApp wxCallAfterwxTimer)_threadedselect)logruntimec@s eZdZdZddZddZdS)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. cCst|||_dSN)r __init__wxappselfrrzddl}||j|jWn tyYdSw|dS)zO wx sometimes removes our own signal handlers, so re-add them. rN)signalSIGINTdefault_int_handler ImportError_handleSignals)rrrrr_installSignalHandlersAgainLs  z%WxReactor._installSignalHandlersAgaincCs |jrdSd|_tj|dS)z# Stop the reactor. NT) _stoppingr ThreadedSelectReactorstoprrrrr&YszWxReactor.stopcCs&t|dr t|dS|j|dS)zm Schedule function to run in main wx/Twisted thread. Called by the select() thread. rN)hasattrr _postQueueput)rfrrr_runInMainThreadbs  zWxReactor._runInMainThreadcCst|dr |jdSdS)z Stop the wx event loop if it hasn't already been stopped. Called during Twisted event loop shutdown. rN)r'r ExitMainLooprrrr_stopWxns zWxReactor._stopWxTcst_tdstdtjj|d|r% dj  ddj  ddfddt jrGtj}|d jj}`js| z jjd d }Wn tyoYq\w|d urvd Sz|Wn tytYnwq]d S)z$ Start the reactor. rzMregisterWxApp() was not called on reactor, registering my own wxApp instance.)installSignalHandlersraftershutdowncs jdSr)r(r)rrrrs zWxReactor.run..g{Gz?)timeoutN)rr(r'r msgrr interleaver+ callLaterr#addSystemEventTriggerr-r platformisMacOSXr rStartMainLoopr$r&rgetr BaseExceptionerr)rr.trr*rrrrunwsN          z WxReactor.runN)T) rrrrr$rr#r&r+r-rArrrrr=s    rcCst}ddlm}|||S)zP Configure the twisted mainloop to be run inside the wxPython mainloop. r)installReactor)rtwisted.internet.mainrB)reactorrBrrrinstalls rEN)rqueuerrwxrrrrrr r! wxPython.wxtwisted.internetr twisted.pythonr r r r%rrE__all__rrrrs  t