
    b^S7                        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e#          Z$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                   >   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	e           Z!d
d
d
d
dde"j#        d
d
f	dZ$d Z%d Z&d Z'd Z(d Z)d Z*d Z+d Z,d Z-d Z.d Z/d Z0d Z1d Z2d Z3d 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                       e Zd Zd ZdS )Property.__metaclass__c                     dS )Nz<class 'GObject.Property'> selfs    4/usr/lib/python3/dist-packages/gi/_propertyhelper.py__repr__zProperty.__metaclass__.__repr__   s    //    N)__name__
__module____qualname__r'   r#   r(   r&   __metaclass__r!      s#        	0 	0 	0 	0 	0r(   r,   Nc
                    d | _         |t          }|                     |          | _        |                     |          | _        |                                  t          |t                    st          d          || _
        t          |t                    st          d          || _        || _        || _        |r
|s| j        }n|r
|s| j        }n|s|s| j        }| j        }|                     |           || _        |D||                                 k     r+t          d| j        |                                 fz            n|                                 }|| _        |	D|	|                                 k    r+t          d| j        |                                 fz            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%   r@   setterr1   r3   r8   r9   r;   rC   rE   s
             r&   __init__zProperty.__init__   s    	<D**400	((11$$$ 	53444	%%% 	64555
 
  	*& 	**FF 	*F 	*+FF 	* 	*)F)FF 	**,,,,AY 1 1 3 3456 6 6 -
 ''))G**,,,,BY 1 1 3 3456 6 6 -
 ''))G			r(   c                 6    d| j         pdd| j        j         dS )Nz<GObject Property z(uninitialized)z (z)>)r.   r1   r$   s    r&   r'   zProperty.__repr__   s*     I****INNN 	r(   c                 t    || S d | _         |                     |          }| j         r| j         }d | _         ||S N)rF   fget)r%   instanceklassvalueexcs        r&   __get__zProperty.__get__   sG    K			(##9 	)CDIIr(   c                     |t           d | _        |                    | j        |           | j        r| j        }d | _        |d S rK   )r7   rF   set_propertyr.   )r%   rM   rO   rP   s       r&   __set__zProperty.__set__   sS    O	di///9 	)CDII	 	r(   c                 ,    |                      |          S )z;Allows application of the getter along with init arguments.)r@   r%   rL   s     r&   __call__zProperty.__call__   s    {{4   r(   c                 R    |j         r|j         | _        |j         | _         || _        | S )z8Set the getter function to fget. For use as a decorator.)r:   r9   rL   rV   s     r&   r@   zProperty.getter   s*    < 	(DJ<DL	r(   c                 D    || _         | j        s| j        j        | _        | S )z8Set the setter function to fset. For use as a decorator.)rA   r.   rL   r)   )r%   rA   s     r&   rG   zProperty.setter   s&    	 y 	+	*DIr(   c                 ,   || j         v r| j         |         S t          |t                    rNt          |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.          t0          t2          t4          t6          t8          t:          t<          t>          t@          fv r|S tC          d|          )NzUnsupported type: )"_type_from_pytype_lookupr5   r1   
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   r7   )r%   type_s     r&   r0   zProperty._type_from_python   s    D111077%% 	?!$!$!$!$	!1 2 2	? ?"y.)ZL)!:{!;!:{K$j)\K K K L)ee=>>>r(   c                 J    ||S | j                             | j        d           S rK   )_default_lookupgetr1   )r%   r3   s     r&   r2   zProperty._get_default  s(    N#''	4888r(   c                 f   | j         }| j        }|t          k    r|dvrt          d|          |t          k    r|t          d          d S |t
          k    r|t          d          d S |                    t                    rO|t          d          t          j	        |                              |          st          d|d|          d S |                    t                    r>t          j	        |                              |          st          d|d|          d S |                    t                    ry|wt          |t                    st          d	t          |          z            |D ]>}t          |          t          t           fvrt          d
t          |          z            ?d S |                    t"                    rS|St%          |d          r,t          j	        |                              t"                    st          d|d|          d S d S d S )N)TFz#default must be True or False, not z)object types does not have default valuesz(GType types does not have default valuesz%enum properties needs a default valuezenum value z must be an instance of zflags value zStrv value %s must be a listz'Strv value %s must contain only stringsrb   zvariant value )r1   r3   r   r7   r   r   is_ar   r   GTyper   r   r5   listreprr6   bytesr   hasattr)r%   ptyper3   vals       r&   r4   zProperty._check_default  s   	,\!!wm'C'C);B7DF F Fm##" KLLL #"j  " JKKK #"ZZ	"" 	2 GHHHYw'',,U33 2i!(%%!1 2 2 22 2 ZZ
## 	29W%%**511 2i!(%%!1 2 2 22 2 ZZ	"" 		2w':gt,, P >g NOOO ^ ^99S%L00#$MPST[P\P\$\]]] 1^ ^ ZZ%% 	2'*=7K00 2	'8J8J8O8OP\8]8] 2i!(%%!1 2 2 2	2 	2*=*=2 2r(   c                 B    | j                             | j        d           S rK   )_min_value_lookuprf   r1   r$   s    r&   rB   zProperty._get_minimum3      %))$)T:::r(   c                 B    | j                             | j        d           S rK   )_max_value_lookuprf   r1   r$   s    r&   rD   zProperty._get_maximum6  rr   r(   c                 8    t          |d| j        z   |           d S N_property_helper_)setattrr.   r%   rM   rO   s      r&   r?   zProperty._default_setter=  s"    -	95AAAAAr(   c                 >    t          |d| j        z   | j                  S rv   )getattrr.   r3   r%   rM   s     r&   r>   zProperty._default_getter@  s    x!4ty!@$,OOOr(   c                 h    t          | j        dt          |          j        d          | _        d S )N property of z is read-onlyr7   r.   r1   r)   rF   ry   s      r&   r<   zProperty._readonly_setterC  6    IIItH~~...0 1 1			r(   c                 h    t          | j        dt          |          j        d          | _        d S )Nr~   z is write-onlyr   r|   s     r&   r=   zProperty._writeonly_getterG  r   r(   c           	      n   | j         }|t          t          t          t          t
          t          t          t          fv r| j	        | j
        | j        f}n|t          k    sY|t          k    sN|                    t                    s4|                    t                     s|                    t"                    r	| j        f}nY|t$          t&          fv rd}nF|                    t(                    s|                    t*                    rd}nt-          |          | j         | j        | j        f|z   | j        fz   S )Nr#   )r1   r	   r
   r   r   r   r   r   r   rC   rE   r3   r   r   rh   r   r   r   r   r   r   r   NotImplementedErrorr8   r9   r;   )r%   rn   argss      r&   get_pspec_argszProperty.get_pspec_argsO  s   	Xy)Zj+G G G<t|;DD{""e|&;&;jj## '<',zz*'='= '<jj&& '< L?DD}j111DDZZ$$ 	-

:(>(> 	-DD%e,,,	49dj1D8DJ=HHr(   )5r)   r*   r+   r:   intr	   boolr   floatr   r6   r   r/   r   r[   r
   r   r   r   
G_MAXFLOATG_MAXDOUBLEG_MININTr   	G_MINLONGr   rq   	G_MAXUINT
G_MAXULONGG_MAXINT	G_MAXLONGrt   re   r1   r,   r   PARAM_READWRITErH   r'   rQ   rT   rW   r@   rG   r0   r2   r4   rB   rD   r?   r>   r<   r=   r   r#   r(   r&   r   r   '   s5       5 5n 	Xl{[  	1AQZKk\(9H
 	9JK[J[(9	 	!11AAQRCS
O0 0 0 0 0 0 0 0 #4dD#*=t6 6 6 6p  
  	 	 	! ! !    ? ? ?(9 9 9
2 2 2B; ; ;; ; ;B B BP P P1 1 11 1 1I I I I Ir(   r   c                      j                             di           }g } j                                         D ]\  }}t          |t                    r|j        s||_        |j        |v r;||j                 |                                k    rUt          d|j        z            |                                ||j        <   |                    |           |sdS | _	        d j         v s	d j         v r=|D ]:}|j
        |j        k    s|j        |j        k    rt          d j        d          ;d }| _         f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 zl defines do_get/set_property and it also uses a property with a custom setter or getter. This is not allowedc                 Z    |j                             dd          }t          | |d           S N-_)r.   replacer{   )r%   pspecr.   s      r&   obj_get_propertyz,install_properties.<locals>.obj_get_property  s+    z!!#s++tT4(((r(   c                     |j                             dd          }t          |d           }|r|                    | |           d S d S r   )r.   r   r{   rA   )r%   r   rO   r.   propclss        r&   obj_set_propertyz,install_properties.<locals>.obj_set_property  sW    z!!#s++sD$'' 	#IIdE"""""	# 	#r(   )__dict__rf   itemsr5   r   r.   r   
ValueErrorappendr   rL   r>   rA   r?   r7   r)   r   r   )r   gpropertiespropsr.   r   r   r   s   `      r&   install_propertiesr   b  s   
 ,""#4b99KEl((**  
ddH%% 	 9 ! 	 yK''ty)T-@-@-B-BBB !SVZV_!_```%)%8%8%:%:K	"LL %CCL((,=,M,M 	% 	%DyD000DIAU4U4Ui \\\$% % % 5V) ) ) +C# # # # #
 +C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   r   r   r   r   r   r   r   r   r/   r   r   r#   r(   r&   <module>r      s  (      7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 ^
o<<M	M	M	^
xI xI xI xI xIv xI xI xIv	0+ 0+ 0+ 0+ 0+r(   