o
    bê²^S7  ã                   @   sÀ   d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ejZejZejZejZejZej Z ej!Z!ej"Z"G dd„ de#ƒZ$dd„ Z%dS )é   )Ú_gi)Ú	TYPE_NONEÚTYPE_INTERFACEÚ	TYPE_CHARÚ
TYPE_UCHARÚTYPE_BOOLEANÚTYPE_INTÚ	TYPE_UINTÚ	TYPE_LONGÚ
TYPE_ULONGÚ
TYPE_INT64ÚTYPE_UINT64Ú	TYPE_ENUMÚ
TYPE_FLAGSÚ
TYPE_FLOATÚTYPE_DOUBLEÚTYPE_STRINGÚTYPE_POINTERÚ
TYPE_BOXEDÚ
TYPE_PARAMÚTYPE_OBJECTÚTYPE_PYOBJECTÚ
TYPE_GTYPEÚ	TYPE_STRVÚTYPE_VARIANTc                   @   sJ  e Zd ZdZeeeeee	e
eeeiZedededee e	e eeeeediZeeeeededeee	eeeeeiZedededededededede	di	ZG dd	„ d	e ƒZ!d
d
d
d
dde"j#d
d
f	dd„Z$dd„ Z%dd„ Z&dd„ Z'dd„ Z(dd„ Z)dd„ Z*dd„ Z+dd„ Z,dd„ Z-dd „ Z.d!d"„ Z/d#d$„ Z0d%d&„ Z1d'd(„ Z2d)d*„ Z3d+d,„ Z4d
S )-ÚPropertyaÄ  Creates a new Property which when used in conjunction with
    GObject subclass will create a Python property accessor for the
    GObject ParamSpec.

    :param callable getter:
        getter to get the value of the property
    :param callable setter:
        setter to set the value of the property
    :param type type:
        type of property
    :param default:
        default value, must match the property type.
    :param str nick:
        short description
    :param str blurb:
        long description
    :param GObject.ParamFlags flags:
        parameter flags
    :keyword minimum:
        minimum allowed value (int, float, long only)
    :keyword maximum:
        maximum allowed value (int, float, long only)

    .. code-block:: python

         class MyObject(GObject.Object):
             prop = GObject.Property(type=str)

         obj = MyObject()
         obj.prop = 'value'

         obj.prop  # now is 'value'

    The API is similar to the builtin :py:func:`property`:

    .. code-block:: python

        class AnotherObject(GObject.Object):
            value = 0

            @GObject.Property
            def prop(self):
                'Read only property.'
                return 1

            @GObject.Property(type=int)
            def propInt(self):
                'Read-write integer property.'
                return self.value

            @propInt.setter
            def propInt(self, value):
                self.value = value
    é    lûÿÿÿ         l   ÿÿÿÿ l   ÿÿÿÿ Ú g        c                   @   s   e Zd Zdd„ ZdS )zProperty.__metaclass__c                 C   s   dS )Nz<class 'GObject.Property'>© ©Úselfr   r   ú4/usr/lib/python3/dist-packages/gi/_propertyhelper.pyÚ__repr__Š   s   zProperty.__metaclass__.__repr__N)Ú__name__Ú
__module__Ú__qualname__r"   r   r   r   r!   Ú__metaclass__‰   s    r&   Nc
           
      C   s0  d | _ |d u r	t}|  |¡| _|  |¡| _|  ¡  t|tƒs"t	dƒ‚|| _
t|tƒs.t	dƒ‚|| _|| _|| _|r?|s?| j}n|rG|sG| j}n
|sQ|sQ| j}| j}|  |¡ || _|d uro||  ¡ k rnt	d| j|  ¡ f ƒ‚n|  ¡ }|| _|	d urŒ|	|  ¡ kr‹t	d| j|  ¡ f ƒ‚n|  ¡ }	|	| _d | _d S )Nznick must be a stringzblurb must be a stringz+Minimum for type %s cannot be lower than %dz,Maximum for type %s cannot be higher than %d)ÚnameÚobjectÚ_type_from_pythonÚtypeÚ_get_defaultÚdefaultÚ_check_defaultÚ
isinstanceÚstrÚ	TypeErrorÚnickÚblurbÚ__doc__ÚflagsÚ_readonly_setterÚ_writeonly_getterÚ_default_getterÚ_default_setterÚgetterÚfsetÚ_get_minimumÚminimumÚ_get_maximumÚmaximumÚ_exc)
r    r9   Úsetterr*   r,   r1   r2   r4   r<   r>   r   r   r!   Ú__init__�   sX   


ÿÿÿÿÿÿ
zProperty.__init__c                 C   s   d| j pd| jj f S )Nz<GObject Property %s (%s)>z(uninitialized))r'   r*   r   r   r   r!   r"   Å   s   þzProperty.__repr__c                 C   s6   |d u r| S d | _ |  |¡}| j r| j }d | _ |‚|S ©N)r?   Úfget)r    ÚinstanceÚklassÚvalueÚexcr   r   r!   Ú__get__Ê   s   
zProperty.__get__c                 C   s:   |d u rt ‚d | _| | j|¡ | jr| j}d | _|‚d S rB   )r0   r?   Úset_propertyr'   )r    rD   rF   rG   r   r   r!   Ú__set__×   s   ýzProperty.__set__c                 C   s
   |   |¡S )z;Allows application of the getter along with init arguments.)r9   ©r    rC   r   r   r!   Ú__call__â   s   
zProperty.__call__c                 C   s    |j r|j | _|j | _ || _| S )z8Set the getter function to fget. For use as a decorator.)r3   r2   rC   rK   r   r   r!   r9   æ   s
   zProperty.getterc                 C   s   || _ | js| jj| _| S )z8Set the setter function to fset. For use as a decorator.)r:   r'   rC   r#   )r    r:   r   r   r!   r@   ï   s   
zProperty.setterc                 C   sˆ   || j v r
| j | S t|tƒr!t|tjtjtjtjtj	fƒr!|j
S |tttttttttttttttttttttt fv r=|S t!d|f ƒ‚)NzUnsupported type: %r)"Ú_type_from_pytype_lookupr.   r*   Ú
issubclassr   ÚGObjectÚGEnumÚGFlagsÚGBoxedÚ
GInterfaceÚ	__gtype__r   r   r   r   r   r	   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r0   )r    Útype_r   r   r!   r)   ù   s(   


üÿ
ûzProperty._type_from_pythonc                 C   s   |d ur|S | j  | jd ¡S rB   )Ú_default_lookupÚgetr*   )r    r,   r   r   r!   r+     s   zProperty._get_defaultc                 C   sp  | j }| j}|tkr|dvrtd|f ƒ‚|tkr#|d ur!tdƒ‚d S |tkr1|d ur/tdƒ‚d S | t¡rP|d u r>tdƒ‚t 	|¡ |¡sNtd||f ƒ‚d S | t
¡rgt 	|¡ |¡setd||f ƒ‚d S | t¡r”|d ur”t|tƒs}tdt|ƒ ƒ‚|D ]}t |ƒttfvr‘td	t|ƒ ƒ‚qd S | t¡r²|d ur´t|d
ƒrªt 	|¡ t¡s¶td||f ƒ‚d S d S d S )N)TFz%default must be True or False, not %rz)object types does not have default valuesz(GType types does not have default valuesz%enum properties needs a default valuez'enum value %s must be an instance of %rz(flags value %s must be an instance of %rzStrv value %s must be a listz'Strv value %s must contain only stringsrT   z*variant value %s must be an instance of %r)r*   r,   r   r0   r   r   Úis_ar   r   ÚGTyper   r   r.   ÚlistÚreprr/   Úbytesr   Úhasattr)r    Úptyper,   Úvalr   r   r!   r-     sV   ÿÿÿ
ÿÿ
ÿÿ
ÿÿÿþzProperty._check_defaultc                 C   ó   | j  | jd ¡S rB   )Ú_min_value_lookuprW   r*   r   r   r   r!   r;   3  ó   zProperty._get_minimumc                 C   r`   rB   )Ú_max_value_lookuprW   r*   r   r   r   r!   r=   6  rb   zProperty._get_maximumc                 C   s   t |d| j |ƒ d S ©NÚ_property_helper_)Úsetattrr'   ©r    rD   rF   r   r   r!   r8   =  s   zProperty._default_setterc                 C   s   t |d| j | jƒS rd   )Úgetattrr'   r,   ©r    rD   r   r   r!   r7   @  s   zProperty._default_getterc                 C   ó   t d| jt|ƒjf ƒ| _d S )Nz%s property of %s is read-only©r0   r'   r*   r#   r?   rg   r   r   r!   r5   C  ó   ÿzProperty._readonly_setterc                 C   rj   )Nz%s property of %s is write-onlyrk   ri   r   r   r!   r6   G  rl   zProperty._writeonly_getterc              	   C   s¸   | j }|ttttttttfv r| j	| j
| jf}n6|tks/|tks/| t¡s/| t¡s/| t¡r4| jf}n|ttfv r=d}n| t¡sG| t¡rJd}nt|ƒ‚| j | j| jf| | jf S )Nr   )r*   r   r	   r
   r   r   r   r   r   r<   r>   r,   r   r   rX   r   r   r   r   r   r   r   ÚNotImplementedErrorr1   r2   r4   )r    r^   Úargsr   r   r!   Úget_pspec_argsO  s&   
ÿÿÿþ
zProperty.get_pspec_args)5r#   r$   r%   r3   Úintr   Úboolr   Úfloatr   r/   r   r(   r   rM   r	   r   r   r   Ú
G_MAXFLOATÚG_MAXDOUBLEÚG_MININTr
   Ú	G_MINLONGr   ra   Ú	G_MAXUINTÚ
G_MAXULONGÚG_MAXINTÚ	G_MAXLONGrc   rV   r*   r&   r   ÚPARAM_READWRITErA   r"   rH   rJ   rL   r9   r@   r)   r+   r-   r;   r=   r8   r7   r5   r6   ro   r   r   r   r!   r   '   sr    7û	÷ø÷
þ8	
!r   c                    sø   ˆ j  di ¡}g }ˆ j  ¡ D ]1\}}t|tƒr?|js||_|j|v r3||j | ¡ kr,qtd|j ƒ‚| ¡ ||j< | |¡ q|sDdS |ˆ _	dˆ j v sQdˆ j v rj|D ]}|j
|jksa|j|jkritdˆ jf ƒ‚qSdd„ }|ˆ _‡ fd	d
„}|ˆ _dS )z“
    Scans the given class for instances of Property and merges them
    into the classes __gproperties__ dict if it exists or adds it if not.
    Ú__gproperties__z0Property %s was already found in __gproperties__NÚdo_get_propertyÚdo_set_propertyzGObject subclass %r defines do_get/set_property and it also uses a property with a custom setter or getter. This is not allowedc                 S   s   |j  dd¡}t| |d ƒS ©Nú-Ú_)r'   Úreplacerh   )r    Úpspecr'   r   r   r!   Úobj_get_propertyˆ  s   z,install_properties.<locals>.obj_get_propertyc                    s2   |j  dd¡}tˆ |d ƒ}|r| | |¡ d S d S r   )r'   r‚   rh   r:   )r    rƒ   rF   r'   Úprop©Úclsr   r!   Úobj_set_property�  s
   ÿz,install_properties.<locals>.obj_set_property)Ú__dict__rW   Úitemsr.   r   r'   ro   Ú
ValueErrorÚappendr|   rC   r7   r:   r8   r0   r#   r}   r~   )r‡   ÚgpropertiesÚpropsr'   r…   r„   rˆ   r   r†   r!   Úinstall_propertiesb  s:   


€ýÿÿ
r�   N)&r   r   Ú
_constantsr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rs   rt   ru   ry   rw   rv   rz   rx   r(   r   r�   r   r   r   r!   Ú<module>   s   h  =