U
    	^                     @   s~   d dl mZmZmZ dd Zdd Zdd ZG dd	 d	eZG d
d deZ	G dd deZ
dd ZG dd deZdgZdS )    )GLibGObjectGioc                 C   s   ||j krd S |j | }| |j}|j| t||}	t|tjj	@ }
t|tjj
@ }|rntdtjj
 |d k	r|
r|j}n|j}|||	| n|
r|j}n|j}|||	 d S )Nz%r not supported)__gtktemplate_methods__Z
get_object__gtype_name____gtktemplate_handlers__addgetattrintr   ZConnectFlagsZAFTERZSWAPPEDRuntimeErrorZconnect_object_afterconnect_objectZconnect_afterZconnect)ZbuilderobjZsignal_namehandler_namer   flagsclsZmethod_nameZtemplate_instZhandlerZafterZswappedfunc r   1/usr/lib/python3/dist-packages/gi/_gtktemplate.pyconnect_func   s*    



r   c                    s
  i }i }t j D ]\}}t|trvt||j |j}|d krH|}||krl|| }td|||f q|||< qt|t	r|j}|d kr|}||kr|| }td|||f q|||< 
||jd q|_|_t j  fdd_j_d S )Nz>Error while exposing handler %r as %r, already available as %rz<Error while exposing child %r as %r, already available as %rr   c                    s   t |  S N)init_templatesbase_init_templater   r   r   <lambda>_       z#register_template.<locals>.<lambda>)list__dict__items
isinstance	CallThingsetattr_func_namer   ChildZbind_template_child_full	_internalr   __gtktemplate_widgets__Zset_connect_funcr   r   Z__dontuse_ginstance_init__)r   Zbound_methodsZbound_widgets	attr_namer   r   Zold_attr_namewidget_namer   r   r   register_template6   sT    
  

  r*   c                 C   s   dd | _ | j|k	rtdt | _||  | j D ]\}}| ||| j|< q6| j	 D ]\}}|| jkr\t
d| q\d S )Nc                 S   s   d S r   r   r   r   r   r   r   f   r   zinit_template.<locals>.<lambda>zRInheritance from classes with @Gtk.Template decorators is not allowed at this timezUHandler '%s' was declared with @Gtk.Template.Callback but was not present in template)r   	__class__	TypeErrorsetr   r'   r   Zget_template_childr   r   r   )selfr   r   r)   r(   r   r   r   r   r   e   s     


r   c                   @   s   e Zd ZdddZdS )r%   Nc                 K   s(   || _ |dd| _|r$td| d S )NZinternalFzUnhandled arguments: %r)r$   popr&   r,   )r.   namekwargsr   r   r   __init__}   s    zChild.__init__)N__name__
__module____qualname__r2   r   r   r   r   r%   {   s   r%   c                   @   s   e Zd Zdd ZdS )r!   c                 C   s   || _ || _d S r   )r$   r#   )r.   r0   r   r   r   r   r2      s    zCallThing.__init__Nr3   r   r   r   r   r!      s   r!   c                   @   s   e Zd ZdddZdd ZdS )CallbackNc                 C   s
   || _ d S r   )r$   )r.   r0   r   r   r   r2      s    zCallback.__init__c                 C   s   t | j|S r   )r!   r$   )r.   r   r   r   r   __call__   s    zCallback.__call__)N)r4   r5   r6   r2   r8   r   r   r   r   r7      s   
r7   c                 C   s@   zt | t jj W n& tjk
r:   t | t jj Y nX dS )z4Raises GLib.Error in case the resource doesn't existN)r   Zresources_get_infoZResourceLookupFlagsZNONEr   ErrorZresources_lookup_data)pathr   r   r   validate_resource_path   s    r;   c                   @   sH   e Zd Zdd Zedd Zedd Zedd ZeZe	Z	d	d
 Z
dS )Templatec                 K   sp   d | _ d | _d | _d|kr(|d| _ n4d|kr>|d| _nd|krT|d| _ntd|rltd| d S )Nstringfilenameresource_pathzHRequires one of the following arguments: string, filename, resource_pathzUnhandled keyword arguments %r)r=   r>   r?   r/   r,   )r.   r1   r   r   r   r2      s    zTemplate.__init__c                 C   s
   | |dS )N)r>   r   )r   r>   r   r   r   	from_file   s    zTemplate.from_filec                 C   s
   | |dS )N)r=   r   )r   r=   r   r   r   from_string   s    zTemplate.from_stringc                 C   s
   | |dS )N)r?   r   )r   r?   r   r   r   from_resource   s    zTemplate.from_resourcec                 C   s  ddl m} t|tr"t||js*tdd|jkrBtd|j t	|drTtd| j
d k	r| j
}t|tsx|d}tj|}|| t| |S | jd k	rt| j || j t| |S | jd k	sttj| j}tj| d	 }|| t| |S d S )
Nr   )Gtkz%Can only use @Gtk.Template on Widgetsr   zS%r does not have a __gtype_name__. Set it to the name of the class in your templater   zCannot nest template classeszutf-8   )gi.repositoryrC   r    type
issubclassZWidgetr,   r   r4   hasattrr=   bytesencoder   ZBytesnewZset_templater*   r?   r;   Zset_template_from_resourcer>   AssertionErrorr   ZFileZnew_for_pathZload_contents)r.   r   rC   dataZbytes_Zfile_r   r   r   r8      s<    








zTemplate.__call__N)r4   r5   r6   r2   classmethodr@   rA   rB   r7   r%   r8   r   r   r   r   r<      s   


r<   N)rE   r   r   r   r   r*   r   objectr%   r!   r7   r;   r<   __all__r   r   r   r   <module>   s   /		H