wL i6dZddlZddlZddlZddlmZddlZdZedZ GddejZ Gdd Z ed Z ed Zed Zd Z eej$dZedk\reZyej*dk(re ZyeZy#e$rY$wxYw)z;Enable wxPython to be used interactively in prompt_toolkit N) default_timercfd}|S)aCDecorator which causes KeyboardInterrupt exceptions to be ignored during execution of the decorated function. This is used by the inputhook functions to handle the event where the user presses CTRL+C while IPython is idle, and the inputhook loop is running. In this case, we want to ignore interrupts. c6 |i|y#t$rYywxYwN)KeyboardInterrupt)argskwargsfuncs g/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/IPython/terminal/pt_inputhooks/wx.pywrapperz*ignore_keyboardinterrupts..wrappers'  $ !& !    s  )r r s` r ignore_keyboardinterruptsr s Nc2tj}|tjsJtj}tj|}|j r!|j |j r!|j~y)zRun the wx event loop by processing pending events only. This approach seems to work, but its performance is not great as it relies on having PyOS_InputHook called regularly. r)wxGetApp Thread_IsMain EventLoopEventLoopActivatorPendingDispatch ProcessIdle)contextappevtloopeas r inputhook_wx1rsu ))+C !!! ,,.  " "7 +oo    oo   rceZdZdZdZy)EventLoopTimercP||_tjj|yr)r rTimer__init__)selfr s r r"zEventLoopTimer.__init__4s  $rc$|jyr)r r#s r NotifyzEventLoopTimer.Notify8s  rN)__name__ __module__ __qualname__r"r&r rr rr2s  rrceZdZdZdZy)EventLoopRunnerc||_tj|_t |j |_|j j||jjyr) input_is_readyrrrr check_stdintimerStartRun)r#timer-s r r1zEventLoopRunner.Run>sK,||~ #D$4$45   rc|jr5|jj|jj yyr)r-r/StoprExitr%s r r.zEventLoopRunner.check_stdinEs1    JJOO  LL    !rN)r'r(r)r1r.r rr r+r+<s  rr+ctj}|=tjsJt}|j d|j y)aRun the wx event loop, polling for stdin. This version runs the wx eventloop for an undetermined amount of time, during which it periodically checks to see if anything is ready on stdin. If anything is ready on stdin, the event loop exits. The argument to elr.Run controls how often the event loop looks at stdin. This determines the responsiveness at the keyboard. A setting of 1000 enables a user to type at most 1 char per second. I have found that a setting of 10 gives good keyboard response. We can shorten it further, but eventually performance would suffer from calling select/kbhit too often. )r2r-r)rrrr+r1r-)rrelrs r inputhook_wx2r9KsO ))+C !!! R&55  7 rc tj}|ltjsJtt j tj s2t jtj tjtj}tj|}t}|js|jr+t}|j|jr+|jt|z }|dkDrtj dn0|dkDrtj dntj d|js~y)a^Run the wx event loop by processing pending events only. This is like inputhook_wx1, but it keeps processing pending events until stdin is ready. After processing all pending events, a call to time.sleep is inserted. This is needed, otherwise, CPU usage is at 100%. This sleep time should be tuned though for best performance. g$@g?g?g?gMbP?r)rrrcallablesignal getsignalSIGINTdefault_int_handlerrrclockr-rrrr2sleep)rrrrt used_times r inputhook_wx3rDes ))+C !!! ((78 MM&--)C)C D,,.  " "7 + G((*//#G  "//# OO ! I4 3S 4  5!3((*4  rc tjyjrytjsJd}tjfd}j |j tj|ttjtjs2tjtjtjjdjy)a|Run the wx event loop until the user provides more input. This input hook is suitable for use with wxPython >= 4 (a.k.a. Phoenix). It uses the same approach to that used in ipykernel.eventloops.loop_wx. The wx.MainLoop is executed, and a wx.Timer is used to periodically poll the context for input. As soon as input is ready, the wx.MainLoop is stopped. Ndchjr!jjyyr)r-r4 ExitMainLoop)evrrr/s r pollz!inputhook_wxphoenix..polls)  ! ! # JJL     $rF)rrr- IsMainThreadr!r0Bind EVT_TIMERr;r<r=r>r?SetExitOnFrameDeleteMainLoop)r poll_intervalrJrr/s` @@r inputhook_wxphoenixrQs ))+C { ??  M HHJE  KK  JJr||T" F$$V]]3 4 fmmV%?%?@U#LLNrdarwin)__doc__sysr<r2timeitrr@rrrr!rr+r9rDrQ major_versionint __version__ Exception inputhookplatformr rr r^s )     ,RXX     20 0 f--b  q)*M A#I \\XII  sBBB