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rt	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rt|ts}tdt| |D ]}t |ttfvrtd	t| qd S |tr|d urt|d
rt	|tst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  =