ó
&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	 e j
 j d ƒ rt d „  Z n	 d „  Z d „  Z d S(	   s:   Enable pyglet to be used interacively with prompt_toolkit
i    (   t   absolute_importN(   t   default_timert   linuxc         C@  s&   y |  j  ƒ  Wn t k
 r! n Xd  S(   N(   t   flipt   AttributeError(   t   window(    (    sD   lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/pyglet.pyR      s    c         C@  s   |  j  ƒ  d  S(   N(   R   (   R   (    (    sD   lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/pyglet.pyR      s    c         C@  sÙ   yÁ t  ƒ  } x± |  j ƒ  s¿ t j  j ƒ  x? t j j D]1 } | j ƒ  | j ƒ  | j d ƒ t	 | ƒ q5 Wt  ƒ  | } | d k r“ t
 j d ƒ q | d k r¯ t
 j d ƒ q t
 j d ƒ q WWn t k
 rÔ n Xd S(   sE  Run the pyglet event loop by processing pending events only.

    This 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.
    t   on_drawg      $@g      ð?gš™™™™™¹?gš™™™™™©?gü©ñÒMbP?N(   t   clockt   input_is_readyt   pyglett   tickt   appt   windowst	   switch_tot   dispatch_eventst   dispatch_eventR   t   timet   sleept   KeyboardInterrupt(   t   contextt   tR   t	   used_time(    (    sD   lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/pyglet.pyt	   inputhook   s"    
	

(   t   __doc__t
   __future__R    t   ost   sysR   t   timeitR   R   R	   t   platformt
   startswithR   R   (    (    (    sD   lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/pyglet.pyt   <module>   s   	