o
    T`YI                     @   s  d dl Z ddlmZmZ ddlmZmZmZ ddlm	Z	 d dl
mZ d dlmZ d dlZe	dZg ZG d	d
 d
ejZeeZed
 d/ddZeG dd dejZed eG dd dejZed eG dd dejZed eG dd dejZed eG dd dejZed eG dd dejZed eG dd dejZed G dd dejZeeZed G dd dejZeeZed G dd  d ejZeeZed  G d!d" d"ejZeeZed" G d#d$ d$ZG d%d& d&ej Z ee Z ed& G d'd( d(ej!Z!ee!Z!ed( ej"ej#ej$fd)k r<d*d+ Z%nd,d+ Z%G d-d. d.ej&Z&ee&Z&ed. dS )0    N   )wakeup_on_signalregister_sigint_fallback)overridedeprecated_initwrap_list_store_sort_func)get_introspection_module)PyGIWarning)GLibGioc                   @      e Zd Zdd ZdS )Applicationc              	   O   s~   t | j0 t  tjj| g|R i |W  d    W  d    S 1 s(w   Y  W d    d S 1 s8w   Y  d S N)r   quitr   r   r   run)selfargskwargs r   2/usr/lib/python3/dist-packages/gi/overrides/Gio.pyr   '   s   "zApplication.runN)__name__
__module____qualname__r   r   r   r   r   r   %   s    r   c                    s    fdd}|S )Nc                    sl   t  | j|i |  jddd d  j }r)tjd|f tdd d S tjd|f tdd d S )N.   z6%s shouldn't be instantiated directly, use %s instead.r   )
stacklevelz&%s shouldn't be instantiated directly.)super__init__r   rsplitr   warningswarnr	   )r   r   r   nameclsinsteadr   r   new_init3   s   

z_warn_init.<locals>.new_initr   )r$   r%   r&   r   r#   r   
_warn_init1   s   r'   c                   @   s   e Zd ZeejdZdS )VolumeMonitorzGio.VolumeMonitor.get()N)r   r   r   r'   r   r(   r   r   r   r   r   r(   C   s    r(   c                   @      e Zd ZeejZdS )DBusAnnotationInfoN)r   r   r   r'   r   r*   r   r   r   r   r   r*   L       r*   c                   @   r)   )DBusArgInfoN)r   r   r   r'   r   r,   r   r   r   r   r   r,   T   r+   r,   c                   @   r)   )DBusMethodInfoN)r   r   r   r'   r   r-   r   r   r   r   r   r-   \   r+   r-   c                   @   r)   )DBusSignalInfoN)r   r   r   r'   r   r.   r   r   r   r   r   r.   d   r+   r.   c                   @   r)   )DBusInterfaceInfoN)r   r   r   r'   r   r/   r   r   r   r   r   r/   l   r+   r/   c                   @   r)   )DBusNodeInfoN)r   r   r   r'   r   r0   r   r   r   r   r   r0   t   r+   r0   c                   @   s   e Zd ZdddZdS )	ActionMapNc                    sN   zt | W n ty   tdw 		d fdd	}|D ]}||  qdS )a  
        The add_action_entries() method is a convenience function for creating
        multiple Gio.SimpleAction instances and adding them to a Gio.ActionMap.
        Each action is constructed as per one entry.

        :param list entries:
            List of entry tuples for add_action() method. The entry tuple can
            vary in size with the following information:

                * The name of the action. Must be specified.
                * The callback to connect to the "activate" signal of the
                  action. Since GLib 2.40, this can be None for stateful
                  actions, in which case the default handler is used. For
                  boolean-stated actions with no parameter, this is a toggle.
                  For other state types (and parameter type equal to the state
                  type) this will be a function that just calls change_state
                  (which you should provide).
                * The type of the parameter that must be passed to the activate
                  function for this action, given as a single GLib.Variant type
                  string (or None for no parameter)
                * The initial state for this action, given in GLib.Variant text
                  format. The state is parsed with no extra type information, so
                  type tags must be added to the string if they are necessary.
                  Stateless actions should give None here.
                * The callback to connect to the "change-state" signal of the
                  action. All stateful actions should provide a handler here;
                  stateless actions should not.

        :param user_data:
            The user data for signal connections, or None
        zentries must be iterableNc                    s   |rt j|std|| f t j|}nd }|d ur:t jd |d d }tj	| ||}|d ur9|
d| n|d urFtd| |f tj| |d}|d urX|
d|  | d S )NzfThe type string '%s' given as the parameter type for action '%s' is not a valid GVariant type string. zchange-statezDStateless action '%s' should give None for 'change_state', not '%s'.)r"   parameter_typeactivate)r
   VariantTypestring_is_valid	TypeErrornewVariantparser   SimpleActionnew_statefulconnect
ValueError
add_action)r"   r3   r2   statechange_statevariant_parametervariant_stateactionr   	user_datar   r   _process_action   s.   
z5ActionMap.add_action_entries.<locals>._process_action)NNNN)iterr6   )r   entriesrE   rF   entryr   rD   r   add_action_entries}   s    
zActionMap.add_action_entriesr   )r   r   r   rJ   r   r   r   r   r1   |   s    r1   c                   @   s    e Zd Zdd Zdd ZeZdS )FileEnumeratorc                 C   s   | S r   r   r   r   r   r   __iter__   s   zFileEnumerator.__iter__c                 C   s   |  d }|d ur|S tr   )	next_fileStopIteration)r   	file_infor   r   r   __next__   s   
zFileEnumerator.__next__N)r   r   r   rM   rQ   nextr   r   r   r   rK      s    	rK   c                   @   r   )MenuItemc                 C   s(   |D ]\}}}|  |t|| qd S r   )set_attribute_valuer
   r8   )r   
attributesr"   format_stringvaluer   r   r   set_attribute   s   zMenuItem.set_attributeN)r   r   r   rX   r   r   r   r   rS      s    rS   c                   @   s\   e Zd ZdZeejjddZdd Zdd Z	dd	 Z
d
d ZeZdd Zdd Zdd ZdS )Settingsz0Provide dictionary-like access to GLib.Settings.)schemapathbackend)	arg_namesc                 C   s   ||   v S r   	list_keysr   keyr   r   r   __contains__      zSettings.__contains__c                 C   s   t |  S r   )lenr_   rL   r   r   r   __len__   rc   zSettings.__len__c                 c   s    |   D ]}|V  qd S r   r^   r`   r   r   r   rM      s   zSettings.__iter__c                 C   s   dS )NTr   rL   r   r   r   __bool__   s   zSettings.__bool__c                 C   s$   || vrt d|f | | S )Nunknown key: %r)KeyError	get_valueunpackr`   r   r   r   __getitem__   s   zSettings.__getitem__c                 C   s8  || vrt d|f | |}|d }|d}|dkr5|d }|ds.J |dd  }n[|dkr`|d dsEJ |dd }| }||vr_td||f n0|dkr|d}|d }| \}	}
||	k s~||
krtd	||	|
f ntd
t	| | 
|t|| d S )Nrg   r   r   typeaenumz$value %s is not an allowed enum (%s)rangezvalue %s not in range (%s - %s)z'Cannot handle allowed type range class )rh   	get_rangeget_child_value
get_stringget_type_string
startswithrj   r=   NotImplementedErrorstr	set_valuer
   r8   )r   ra   rW   ro   type_vtype_strallowedtuple_min_max_r   r   r   __setitem__  s6   


zSettings.__setitem__c                 C      |   S r   r^   rL   r   r   r   keys(     zSettings.keysN)r   r   r   __doc__r   r   rY   r   rb   re   rM   rf   __nonzero__rk   r   r   r   r   r   r   rY      s    !rY   c                   @   s4   e Zd ZdZdd Zdd Zdd Zedd	 Zd
S )_DBusProxyMethodCallz1Helper class to implement DBusProxy method calls.c                 C   s   || _ || _d S r   )
dbus_proxymethod_name)r   r   r   r   r   r   r   3  s   
z_DBusProxyMethodCall.__init__c           
      C   sz   |\}}}z| |}W n% ty1   t d d \}}	|r(|||	| Y d S |||	| Y d S w ||| || d S )Nr   )call_finish	Exceptionsysexc_info_unpack_result)
r   objresultrE   result_callbackerror_callbackreal_user_dataretetypeer   r   r   __async_result_handler7  s   
	z+_DBusProxyMethodCall.__async_result_handlerc              	   O   s   |r|d }|dd  }t |tstd| nd}t|t|}d|v rK|d |d|df}| j| j	||dd|d	d
d | j
| d S | j| j	||dd|d	d
d }| |S )Nr   r   z6first argument must be the method signature string: %rz()result_handlererror_handlerrE   flagstimeoutr   )
isinstancerv   r6   r
   r8   tuplegetr   callr   *_DBusProxyMethodCall__async_result_handler	call_syncr   )r   r   r   	signaturearg_variantrE   r   r   r   r   __call__F  s.   



z_DBusProxyMethodCall.__call__c                 C   s4   |  }t|dkr|d }|S t|dkrd}|S )z?Convert a D-BUS return variant into an appropriate return valuer   r   N)rj   rd   )klassr   r   r   r   r   c  s   z#_DBusProxyMethodCall._unpack_resultN)	r   r   r   r   r   r   r   classmethodr   r   r   r   r   r   0  s    r   c                   @   s   e Zd ZdZdd ZdS )	DBusProxya$  Provide comfortable and pythonic method calls.

    This marshalls the method arguments into a GVariant, invokes the
    call_sync() method on the DBusProxy object, and unmarshalls the result
    GVariant back into a Python tuple.

    The first argument always needs to be the D-Bus signature tuple of the
    method call. Example:

      proxy = Gio.DBusProxy.new_sync(...)
      result = proxy.MyMethod('(is)', 42, 'hello')

    The exception are methods which take no arguments, like
    proxy.MyMethod('()'). For these you can omit the signature and just write
    proxy.MyMethod().

    Optional keyword arguments:

    - timeout: timeout for the call in milliseconds (default to D-Bus timeout)

    - flags: Combination of Gio.DBusCallFlags.*

    - result_handler: Do an asynchronous method call and invoke
         result_handler(proxy_object, result, user_data) when it finishes.

    - error_handler: If the asynchronous call raises an exception,
      error_handler(proxy_object, exception, user_data) is called when it
      finishes. If error_handler is not given, result_handler is called with
      the exception object as result instead.

    - user_data: Optional user data to pass to result_handler for
      asynchronous calls.

    Example for asynchronous calls:

      def mymethod_done(proxy, result, user_data):
          if isinstance(result, Exception):
              # handle error
          else:
              # do something with result

      proxy.MyMethod('(is)', 42, 'hello',
          result_handler=mymethod_done, user_data='data')
    c                 C   s
   t | |S r   )r   )r   r"   r   r   r   __getattr__  s   
zDBusProxy.__getattr__N)r   r   r   r   r   r   r   r   r   r   s  s    ,r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
	ListModelc                    sr   t |tr fddt|t  D S t |tr7|dk r$|t 7 }|dk r*t |}|d u r5t|S t)Nc                    s   g | ]}  |qS r   )get_item).0irL   r   r   
<listcomp>  s    z)ListModel.__getitem__.<locals>.<listcomp>r   )	r   slicero   indicesrd   int
IndexErrorr   r6   )r   ra   r   r   rL   r   rk     s   
 

zListModel.__getitem__c                 C   sD   |   j}t||std|j|jf | D ]	}||kr dS qdS )NExpected type %s.%sTF)get_item_typepytyper   r6   r   r   )r   itemr   r   r   r   r   rb     s   

zListModel.__contains__c                 C   r   r   )get_n_itemsrL   r   r   r   re     r   zListModel.__len__c                 c   s$    t t| D ]}| |V  qd S r   )ro   rd   r   )r   r   r   r   r   rM     s   zListModel.__iter__N)r   r   r   rk   rb   re   rM   r   r   r   r   r     s
    
r   )r   9   r   c                 C   s,   |  ||g  t|D ]}| || qd S r   )splicereversedinsert)r   position
n_removals	additionsry   r   r   r   _list_store_splice  s   r   c                 C   s   |  ||| d S r   )r   )r   r   r   r   r   r   r   r     s   c                       s8   e Zd Z fddZ fddZdd Zdd Z  ZS )		ListStorec                    s    t |}tt| j|g|R  S r   )r   r   r   sort)r   compare_funcrE   	__class__r   r   r     s   zListStore.sortc                    s"   t |}tt| j||g|R  S r   )r   r   r   insert_sorted)r   r   r   rE   r   r   r   r     s   
zListStore.insert_sortedc                 C   s   t |trI|t| \}}}|dkr!t| |t|| dg  d S |dkr5t| |d t|| dg  d S tt|||ddD ]}| | q?d S t |t	rk|dk rX|t| 7 }|dk sb|t| krdt
| | d S t)Nr   r   r   T)reverse)r   r   r   rd   r   maxsortedro   remover   r   r6   )r   ra   startstopstepr   r   r   r   __delitem__  s    
 
zListStore.__delitem__c                 C   sv  t |tr|  j}g }|D ]}t ||std|j|jf || q|t	| \}}}|dkrAt
| |t|| d| d S tt|||}	t	|	t	|krSt|dkrlt
| |d t|| d|d d d  d S t|	|D ]\}
}t
| |
d|g qqd S t |tr|dk r|t	| 7 }|dk s|t	| krt|  j}t ||std|j|jf t
| |d|g d S t)Nr   r   r   r   )r   r   r   r   r6   r   r   appendr   rd   r   r   listro   r=   zipr   r   )r   ra   rW   r   	valuelistry   r   r   r   r   r   r   r   r   r     sP   


 


zListStore.__setitem__)r   r   r   r   r   r   r   __classcell__r   r   r   r   r     s
    r   r   )'r    _ossighelperr   r   	overridesr   r   r   moduler   gir	   gi.repositoryr
   r   r   __all__r   r   r'   r(   r*   r,   r-   r.   r/   r0   r1   rK   rS   rY   r   r   r   MAJOR_VERSIONMINOR_VERSIONMICRO_VERSIONr   r   r   r   r   r   <module>   sv   








J


D
C1
#

I