ó
&9_[c           @@  sÂ   d  Z  d d l m Z d d l Z d d l Z d d l Z d d l m Z d d l	 Z	 d „  Z
 d e	 j f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 „  Z d „  Z e j d k r¸ e Z n e Z d S(   s:   Enable wxPython to be used interacively in prompt_toolkit
i    (   t   absolute_importN(   t   default_timerc         C@  sŽ   yv t  j ƒ  } | d k	 ru t  j ƒ  s- t ‚ t  j ƒ  } t  j | ƒ } x | j ƒ  rd | j ƒ  qK W| j	 ƒ  ~ n  Wn t
 k
 r‰ n Xd S(   s¼   Run 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.
    i    N(   t   wxt   GetAppt   Nonet   Thread_IsMaint   AssertionErrort	   EventLoopt   EventLoopActivatort   Pendingt   Dispatcht   ProcessIdlet   KeyboardInterrupt(   t   contextt   appt   evtloopt   ea(    (    s@   lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/wx.pyt   inputhook_wx1   s    

t   EventLoopTimerc           B@  s   e  Z d  „  Z d „  Z RS(   c         C@  s   | |  _  t j j |  ƒ d  S(   N(   t   funcR   t   Timert   __init__(   t   selfR   (    (    s@   lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/wx.pyR   &   s    	c         C@  s   |  j  ƒ  d  S(   N(   R   (   R   (    (    s@   lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/wx.pyt   Notify*   s    (   t   __name__t
   __module__R   R   (    (    (    s@   lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/wx.pyR   $   s   	t   EventLoopRunnerc           B@  s   e  Z d  „  Z d „  Z RS(   c         C@  sK   | |  _  t j ƒ  |  _ t |  j ƒ |  _ |  j j | ƒ |  j j ƒ  d  S(   N(	   t   input_is_readyR   R   R   R   t   check_stdint   timert   Startt   Run(   R   t   timeR   (    (    s@   lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/wx.pyR   /   s
    	c         C@  s-   |  j  ƒ  r) |  j j ƒ  |  j j ƒ  n  d  S(   N(   R   R   t   StopR   t   Exit(   R   (    (    s@   lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/wx.pyR   6   s    (   R   R   R   R   (    (    (    s@   lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/wx.pyR   -   s   	c         C@  sk   yS t  j ƒ  } | d k	 rR t  j ƒ  s- t ‚ t ƒ  } | j d d d |  j ƒ n  Wn t k
 rf n Xd S(   sˆ  Run 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.
    R    i
   R   i    N(	   R   R   R   R   R   R   R   R   R   (   R   R   t   elr(    (    s@   lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/wx.pyt   inputhook_wx2;   s    	c         C@  s6  yt  j ƒ  } | d k	 rt  j ƒ  s- t ‚ t t j t j ƒ ƒ s^ t j t j t j	 ƒ n  t  j
 ƒ  } t  j | ƒ } t ƒ  } x’ |  j ƒ  sx# | j ƒ  r¶ t ƒ  } | j ƒ  q” W| j ƒ  t ƒ  | } | d k rê t j d ƒ q… | d k rt j d ƒ q… t j d ƒ q… W~ n  Wn t k
 r1n Xd S(   s^  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š™™™™™©?gü©ñÒMbP?i    N(   R   R   R   R   R   t   callablet   signalt	   getsignalt   SIGINTt   default_int_handlerR   R   t   clockR   R	   R
   R   R    t   sleepR   (   R   R   R   R   t   tt	   used_time(    (    s@   lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/wx.pyt   inputhook_wx3V   s0    
		

t   darwin(   t   __doc__t
   __future__R    t   sysR&   R    t   timeitR   R*   R   R   R   R   t   objectR   R$   R.   t   platformt	   inputhook(    (    (    s@   lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/wx.pyt   <module>   s   				7	