o
    b                     @   s   d Z ddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 dZej  eedddur1e  G d	d
 d
ejZG dd dejZdddZdgZdS )a  
This module provides support for Twisted to interact with the glib
mainloop via GObject Introspection.

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

    from twisted.internet import gireactor
    gireactor.install()

If you wish to use a GApplication, register it with the reactor::

    from twisted.internet import reactor
    reactor.registerGApplication(app)

Then use twisted.internet APIs as usual.

On Python 3, pygobject v3.4 or later is required.
    N)GLib)	_glibbase)ReactorAlreadyRunning)runtimeTthreads_initc                   @   s^   e Zd ZdZejjejjB ejjB Z	ejj
ZejjZee	B Zee	B ZdZdddZdd ZdS )		GIReactorz
    GObject-introspection event loop reactor.

    @ivar _gapplication: A C{Gio.Application} instance that was registered
        with C{registerGApplication}.
    NFc                 C   0   d }|du rddl m} tjj| t||d d S NTr   )GtkuseGtk)gi.repositoryr
   r   GlibReactorBase__init__r   selfr   _gtk r   </usr/lib/python3/dist-packages/twisted/internet/gireactor.pyr   E      zGIReactor.__init__c                    sV   | j dur	td| jrtdt dstd | _  fdd}|| _ j| _dS )a  
        Register a C{Gio.Application} or C{Gtk.Application}, whose main loop
        will be used instead of the default one.

        We will C{hold} the application so it doesn't exit on its own. In
        versions of C{python-gi} 3.2 and later, we exit the event loop using
        the C{app.quit} method which overrides any holds. Older versions are
        not supported.
        Nz2Can't register more than one application instance.z5Can't register application after reactor was started.quitzPApplication registration is not supported in versions of PyGObject prior to 3.2.c                      s        d  d S )N)holdrunr   appr   r   r   c   s   z+GIReactor.registerGApplication.<locals>.run)_gapplicationRuntimeError_startedr   hasattr_runr   _crash)r   r   r   r   r   r   registerGApplicationL   s   


zGIReactor.registerGApplicationF)__name__
__module____qualname____doc__r   IOConditionHUPERRNVAL_POLL_DISCONNECTEDIN_POLL_INOUT	_POLL_OUTINFLAGSOUTFLAGSr   r   r!   r   r   r   r   r   .   s    
r   c                   @   s"   e Zd ZdZdddZdd ZdS )	PortableGIReactorz<
    Portable GObject Introspection event loop reactor.
    Fc                 C   r   r	   )r   r
   r   PortableGlibReactorBaser   r   r   r   r   r   r   q   r   zPortableGIReactor.__init__c                 C   s   t d)z
        Register a C{Gio.Application} or C{Gtk.Application}, whose main loop
        will be used instead of the default one.
        z3GApplication is not currently supported on Windows.)NotImplementedError)r   r   r   r   r   r!   x   s   z&PortableGIReactor.registerGApplicationNr"   )r#   r$   r%   r&   r   r!   r   r   r   r   r2   l   s    
r2   Fc                 C   s<   t j dkrt| d}nt| d}ddlm} || |S )z
    Configure the twisted mainloop to be run inside the glib mainloop.

    @param useGtk: should GTK+ rather than glib event loop be
        used (this will be slightly slower but does support GUI).
    posixr   r   )installReactor)r   platformgetTyper   r2   twisted.internet.mainr6   )r   reactorr6   r   r   r   install   s   
r;   r"   )r&   gi.pygtkcompatgir   r   twisted.internetr   twisted.internet.errorr   twisted.pythonr   _pygtkcompatPresentpygtkcompatenablegetattrr   r   r   r3   r2   r;   __all__r   r   r   r   <module>   s   
>

