ó
[³XMc           @   sb  d  Z  d d l Z y d d l Z e j d ƒ Wn e k
 rD Z n Xd d l Z d d l m Z d d l	 m
 Z
 m Z m Z m Z d d l m Z d d l m Z m Z e j d d	 d
 d ƒ Z d Z d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d „  Z e j e e e d ƒ d „  Z e j e e e d ƒ e j j ƒ  d k rUe Z n  d g Z  d S(   s>  
This module provides support for Twisted to interact with the PyGTK mainloop.

In order to use this support, simply do the following::

    |  from twisted.internet import gtkreactor
    |  gtkreactor.install()

Then use twisted.internet APIs as usual.  The other methods here are not
intended to be called directly.
iÿÿÿÿNs   1.2(   t
   implements(   t   logt   runtimet	   deprecatet   versions(   t   IReactorFDSet(   t	   posixbaset   selectreactort   Twistedi
   i   i    sh   All new applications should be written with gtk 2.x, which is supported by twisted.internet.gtk2reactor.t
   GtkReactorc           B   s¾   e  Z d  Z e e ƒ e j e e e  d ƒ d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d Z d
 „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z RS(   sG  
    GTK+ event loop reactor.

    @ivar _reads: A dictionary mapping L{FileDescriptor} instances to gtk INPUT_READ
        watch handles.

    @ivar _writes: A dictionary mapping L{FileDescriptor} instances to gtk
        INTPUT_WRITE watch handles.

    @ivar _simtag: A gtk timeout handle for the next L{simulate} call.
    R	   c         C   s/   d |  _ i  |  _ i  |  _ t j j |  ƒ d S(   sb   
        Initialize the file descriptor tracking dictionaries and the base
        class.
        N(   t   Nonet   _simtagt   _readst   _writesR   t   PosixReactorBaset   __init__(   t   self(    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyR   :   s    			c         C   s;   | |  j  k r7 t j | t j j |  j ƒ |  j  | <n  d  S(   N(   R   t   gtkt	   input_addt   GDKt
   INPUT_READt   callback(   R   t   reader(    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyt	   addReaderE   s    c         C   s;   | |  j  k r7 t j | t j j |  j ƒ |  j  | <n  d  S(   N(   R   R   R   R   t   INPUT_WRITER   (   R   t   writer(    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyt	   addWriterI   s    c         C   s   |  j  j ƒ  S(   N(   R   t   keys(   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyt
   getReadersN   s    c         C   s   |  j  j ƒ  S(   N(   R   R   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyt
   getWritersR   s    c         C   s   |  j  |  j |  j ƒ S(   N(   t
   _removeAllR   R   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyt	   removeAllV   s    c         C   s4   | |  j  k r0 t j |  j  | ƒ |  j  | =n  d  S(   N(   R   R   t   input_remove(   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyt   removeReaderZ   s    c         C   s4   | |  j  k r0 t j |  j  | ƒ |  j  | =n  d  S(   N(   R   R   R    (   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyt   removeWriter_   s    c         G   s   d  |  _ d S(   Ni    (   R
   t   doIterationTimer(   R   t   args(    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyt   doIterationTimeoutf   s    	c         C   s¡   t  j d d d d d |  ƒ t j ƒ  r9 t j d ƒ d  S| d k rI d  St j t | d ƒ |  j ƒ |  _ t j d ƒ |  j r t j	 |  j ƒ d  |  _ n  d  S(	   Nt   channelt   systemt   eventt	   iterationt   reactori    iè  i   (   R   t   msgR   t   events_pendingt   mainiterationt   timeout_addt   intR%   R#   t   timeout_removeR
   (   R   t   delay(    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyt   doIterationi   s    	c         C   s   t  j j |  ƒ t j ƒ  d  S(   N(   R   R   t   crashR   t   mainquit(   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyR3   €   s    i   c         C   s1   |  j  d | ƒ t j d |  j ƒ t j ƒ  d  S(   Nt   installSignalHandlersi    (   t   startRunningR   R.   t   simulatet   mainloop(   R   R5   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyt   run„   s    c         C   sá   d  } d  } yw | t j j @r7 | j ƒ  } | j } n  | r‚ | t j j @r‚ | j r‚ | j | k r‚ | j ƒ  } | j } q‚ n  Wn2 t j	 ƒ  d } t
 j d | ƒ t
 j ƒ  n X| rÝ |  j | | | | j k ƒ n  d  S(   Ni   s   Error In %s(   R
   R   R   R   t   doReadR   t   disconnectedt   doWritet   syst   exc_infoR   R+   t   deferrt   _disconnectSelectable(   R   t   sourcet	   conditiont   whyt   didRead(    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyt   _readAndWrite‰   s     
c         C   s'   t  j | |  j | | ƒ |  j ƒ  d S(   Ni   (   R   t   callWithLoggerRE   R7   (   R   RA   RB   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyR   §   s    
c         C   s|   |  j  d k	 r" t j |  j  ƒ n  |  j ƒ  t |  j ƒ  d ƒ } | d k rV d } n  t j t | d ƒ |  j	 ƒ |  _  d S(   s7   Run simulation loops and reschedule callbacks.
        gš™™™™™¹?iò  N(
   R   R
   R   R0   t   runUntilCurrentt   mint   timeoutR.   R/   R7   (   R   RI   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyR7   ¬   s    
	N(   t   __name__t
   __module__t   __doc__R    R   R   t   deprecatedModuleAttributet   deprecatedSincet   deprecationMessageR   R   R   R   R   R   R!   R"   R
   R#   R%   R2   R3   R9   RE   R   R7   (    (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyR	   )   s(   

													t   PortableGtkReactorc           B   sH   e  Z d  Z d Z e j e e e  d ƒ d „  Z	 d d „ Z
 d „  Z RS(   sª   Reactor that works on Windows.

    input_add is not supported on GTK+ for Win32, apparently.

    @ivar _simtag: A gtk timeout handle for the next L{simulate} call.
    RP   c         C   s   t  j j |  ƒ t j ƒ  d  S(   N(   R   t   SelectReactorR3   R   R4   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyR3   Ç   s    i   c         C   s(   |  j  d | ƒ |  j ƒ  t j ƒ  d  S(   NR5   (   R6   R7   R   R8   (   R   R5   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyR9   Ë   s    
c         C   sv   |  j  d k	 r" t j |  j  ƒ n  |  j ƒ  t |  j ƒ  d ƒ } | d k rV d } n  t j | d |  j ƒ |  _  d S(   s7   Run simulation loops and reschedule callbacks.
        gš™™™™™¹?iò  N(	   R   R
   R   R0   t   iterateRH   RI   R.   R7   (   R   RI   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyR7   Ð   s    
	N(   RJ   RK   RL   R
   R   R   RM   RN   RO   R3   R9   R7   (    (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyRP   »   s   
	c          C   s'   t  ƒ  }  d d l m } | |  ƒ |  S(   sF   Configure the twisted mainloop to be run inside the gtk mainloop.
    iÿÿÿÿ(   t   installReactor(   R	   t   twisted.internet.mainRS   (   R*   RS   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyt   installß   s    	
RU   c          C   s'   t  ƒ  }  d d l m } | |  ƒ |  S(   sF   Configure the twisted mainloop to be run inside the gtk mainloop.
    iÿÿÿÿ(   RS   (   RP   RT   RS   (   R*   RS   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyt   portableInstallë   s    	
RV   t   posix(!   RL   R=   t   pygtkt   requiret   ImportErrort   AttributeErrorR   t   zope.interfaceR    t   twisted.pythonR   R   R   R   t   twisted.internet.interfacesR   t   twisted.internetR   R   t   VersionRN   RO   R   R	   RQ   RP   RU   RM   RJ   RV   t   platformt   getTypet   __all__(    (    (    s?   /usr/lib/python2.7/dist-packages/twisted/internet/gtkreactor.pyt   <module>   s0   "’$	
	
	