ó
Û¤[c           @   sú  d  Z  d d l Z d d l Z d d l m Z e j j e j j d ƒ ƒ Z	 e j
 Z e e	 j _ e e	 j _ e e	 j _ e e g e	 j _ e	 j Z d „  Z d „  Z d „  Z e j j e j j d ƒ ƒ Z e j Z e j e _ e j Z e e _ e j Z e e _ e j Z d e _ e g e _ e j Z e e _ e e j e j e j e j e e g e _ e j Z d e _ e e e g e _ e j e d	 ƒ Z  d
 „  Z! d „  Z" e ƒ  Z# d d d „ Z$ e j% d e e ƒ Z& e& e$ ƒ Z' d „  Z( d d „ Z) d S(   sG   Eventloop hook for OS X

Calls NSApp / CoreFoundation APIs via ctypes.
iÿÿÿÿN(   t   Eventt   objcc         C   s%   t  |  t ƒ s! |  j d ƒ }  n  |  S(   s   ensure utf8 bytest   utf8(   t
   isinstancet   bytest   encode(   t   s(    (    s9   lib/python2.7/site-packages/ipykernel/_eventloop_macos.pyt   _utf8   s    c         C   s   t  j t |  ƒ ƒ S(   s)   create a selector name (for ObjC methods)(   R   t   sel_registerNameR   (   t   name(    (    s9   lib/python2.7/site-packages/ipykernel/_eventloop_macos.pyt   n    s    c         C   s   t  j t |  ƒ ƒ S(   s   get an ObjC Class by name(   R   t   objc_getClassR   (   t	   classname(    (    s9   lib/python2.7/site-packages/ipykernel/_eventloop_macos.pyt   C%   s    t   CoreFoundationt   kCFRunLoopCommonModesc           C   s   t  t d ƒ t d ƒ ƒ S(   s0   Return the global NSApplication instance (NSApp)t   NSApplicationt   sharedApplication(   t   msgR   R
   (    (    (    s9   lib/python2.7/site-packages/ipykernel/_eventloop_macos.pyt   _NSAppO   s    c         C   sY   t  t d ƒ t d ƒ d d d d d d d d d ƒ } t  |  t d ƒ t | ƒ t ƒ d S(   s   Wake the Applicationt   NSEvents]   otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:i   i    s   postEvent:atStart:N(   R   R   R
   t   Nonet   void_pt   True(   t   NSAppt   event(    (    s9   lib/python2.7/site-packages/ipykernel/_eventloop_macos.pyt   _wakeT   s    		c         C   s\   t  j ƒ  t ƒ  } t | t d ƒ ƒ rK t | t d ƒ | ƒ t | ƒ n t t ƒ  ƒ d S(   s.   Callback to fire when there's input to be readt	   isRunnings   stop:N(   t
   _triggeredt   setR   R   R
   R   t   CFRunLoopStopt   CFRunLoopGetCurrent(   t   timert   loopR   (    (    s9   lib/python2.7/site-packages/ipykernel/_eventloop_macos.pyt   stopi   s    
	c         C   s<   t  d t ƒ  |  d d d t d ƒ } t t ƒ  | t ƒ d S(   s1   Register callback to stop eventloop after a delayi    N(   t   CFRunLoopTimerCreateR   t   CFAbsoluteTimeGetCurrentt   _c_stop_callbackt   CFRunLoopAddTimert   CFRunLoopGetMainR   (   t   delayR    (    (    s9   lib/python2.7/site-packages/ipykernel/_eventloop_macos.pyt   _stop_afterz   s    
	i   c         C   sM   t  j ƒ  t ƒ  } t |  ƒ t | t d ƒ ƒ t  j ƒ  sI t j ƒ  n  d S(   s<   run the Cocoa eventloop for the specified duration (seconds)t   runN(	   R   t   clearR   R)   R   R
   t   is_setR   t   CFRunLoopRun(   t   durationR   (    (    s9   lib/python2.7/site-packages/ipykernel/_eventloop_macos.pyt   mainloopŒ   s    
	
(*   t   __doc__t   ctypest   ctypes.utilt	   threadingR    t   cdllt   LoadLibraryt   utilt   find_libraryR   t   c_void_pR   R   t   restypeR   t   objc_msgSendt   argtypesR   R   R
   R   R   R$   t   c_doubleR   R'   R   R   R#   t   c_intR&   t   in_dllR   R   R   R   R"   t	   CFUNCTYPEt   _c_callback_func_typeR%   R)   R/   (    (    (    s9   lib/python2.7/site-packages/ipykernel/_eventloop_macos.pyt   <module>   sX   																				