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   
>

