
    gi7                     R   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j6                  Zej8                  Zej:                  Zej<                  Zej>                  Zej@                  Z ejB                  Z!ejD                  Z" G d d      Z#d Z$y)   )_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"jF                  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 Z4y
)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y)Property.__metaclass__c                      y)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    	0r(   r,   Nc
                 \   d | _         |t        }| j                  |      | _        | j	                  |      | _        | j                          t        |t              st        d      || _
        t        |t              st        d      || _        || _        || _        |r|s| j                  }n-|r|s| j                  }n|s|s| j                   }| j"                  }| j%                  |       || _        |@|| j)                         k  r=d| j                  dd| j)                         d}
t        |
      | j)                         }|| _        |	@|	| j-                         kD  r=d| j                  dd| j-                         d}
t        |
      | j-                         }	|	| _        d | _        y )	Nznick must be a stringzblurb must be a stringzMinimum for type sz cannot be lower than dzMaximum for type z cannot be higher than )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%   rB   setterr3   r5   r:   r;   r=   rE   rG   msgs              r&   __init__zProperty.__init__   s    	<D**40	((1$$344	%%455
 
 &**FF++F))F))FF 	**,,)$))A6LTM^M^M`abLcdn$'')G**,,)$))A6MdN_N_NabcMden$'')G	r(   c                 X    d| j                   xs d d| j                  j                    dS )Nz<GObject Property z(uninitialized)z (z)>)r0   r3   r$   s    r&   r'   zProperty.__repr__   s,    #DII$B1B#C2diinnEUUWXXr(   c                     || S d | _         | j                  |      }| j                   r| j                   }d | _         ||S N)rH   fget)r%   instanceklassvalueexcs        r&   __get__zProperty.__get__   sC    K			(#99))CDIIr(   c                     |t         d | _        |j                  | j                  |       | j                  r| j                  }d | _        |y rN   )r9   rH   set_propertyr0   )r%   rP   rR   rS   s       r&   __set__zProperty.__set__   sI    O	dii/99))CDII r(   c                 $    | j                  |      S )z;Allows application of the getter along with init arguments.)rB   r%   rO   s     r&   __call__zProperty.__call__   s    {{4  r(   c                 p    |j                   r"|j                   | _        |j                   | _         || _        | S )z8Set the getter function to fget. For use as a decorator.)r<   r;   rO   rY   s     r&   rB   zProperty.getter   s+    <<DJ<<DL	r(   c                 b    || _         | j                  s| j                  j                  | _        | S )z8Set the setter function to fset. For use as a decorator.)rC   r0   rO   r)   )r%   rC   s     r&   rI   zProperty.setter  s(    	 yy		**DIr(   c                 &   || j                   v r| j                   |   S t        |t              rct        |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_lookupr7   r3   
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   r9   )r%   type_s     r&   r2   zProperty._type_from_python  s    D1110077eT"zCKKCJJ

CNNS(
 ??"-
 
0 L,UI677r(   c                 V    ||S | j                   j                  | j                  d       S rN   )_default_lookupgetr3   )r%   r5   s     r&   r4   zProperty._get_default4  s*    N##''		488r(   c                    | j                   }| j                  }|t        k(  r|dvrt        d|      |t        k(  r|t        d      y |t
        k(  r|t        d      y |j                  t              rC|t        d      t        j                  |      j                  |      st        d| d|      y |j                  t              r6t        j                  |      j                  |      st        d| d|      y |j                  t              rO|Mt        |t              st        d	|d
      |D ](  }t        |      t        t        fvst        d	|d       y |j                  t               rI|Ft#        |d      r(t        j                  |      j                  t               st        d| d|      y y y )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 z must be a listz must contain only stringsre   zvariant value )r3   r5   r   r9   r   r   is_ar   r   GTyper   r   r7   listr8   bytesr   hasattr)r%   ptyper5   vals       r&   r6   zProperty._check_default9  s   		,,L g]&BA'MNNM!" KLL #j " JKK #ZZ	" GHH99W%**51!'*B5)L  2 ZZ
#99W%**51"7)+CE9M  2 ZZ	"w':gt,+g[ HII Y9S%L0#k'<V$WXXY JJ|$#G[1yy)..|< nWI5MeYWXX = $ %r(   c                 N    | j                   j                  | j                  d       S rN   )_min_value_lookupri   r3   r$   s    r&   rD   zProperty._get_minimum`      %%))$))T::r(   c                 N    | j                   j                  | j                  d       S rN   )_max_value_lookupri   r3   r$   s    r&   rF   zProperty._get_maximumc  rt   r(   c                 8    t        |d| j                  z   |       y N_property_helper_)setattrr0   r%   rP   rR   s      r&   rA   zProperty._default_setterj  s    -		95Ar(   c                 J    t        |d| j                  z   | j                        S rx   )getattrr0   r5   r%   rP   s     r&   r@   zProperty._default_getterm  s    x!4tyy!@$,,OOr(   c                 j    t        | j                   dt        |      j                   d      | _        y )N property of z is read-onlyr9   r0   r3   r)   rH   r{   s      r&   r>   zProperty._readonly_setterp  s-    yyktH~'>'>&?}M
	r(   c                 j    t        | j                   dt        |      j                   d      | _        y )Nr   z is write-onlyr   r~   s     r&   r?   zProperty._writeonly_getteru  s-    yyktH~'>'>&?~N
	r(   c           	      `   | j                   }|t        t        t        t        t
        t        t        t        fv r$| j                  | j                  | j                  f}n|t        t        fv s?|j                  t              s*|j                  t               s|j                  t"              r| j                  f}nF|t$        t&        fv s*|j                  t(              s|j                  t*              rd}nt-        |      | j                   | j.                  | j0                  g|| j2                  S )Nr#   )r3   r	   r
   r   r   r   r   r   r   rE   rG   r5   r   r   rk   r   r   r   r   r   r   r   NotImplementedErrorr:   r;   r=   )r%   rp   argss      r&   get_pspec_argszProperty.get_pspec_args~  s    			
 	
 <<t||;Dk<00zz)$zz*%zz,'LL?DmZ00zz+&zz*%D%e,,		499djjD4DDDr(   )5r)   r*   r+   r<   intr	   boolr   floatr   r8   r   r1   r   r^   r
   r   r   r   
G_MAXFLOATG_MAXDOUBLEG_MININTr   	G_MINLONGr   rs   	G_MAXUINT
G_MAXULONGG_MAXINT	G_MAXLONGrv   rh   r3   r,   r   PARAM_READWRITErK   r'   rT   rW   rZ   rB   rI   r2   r4   r6   rD   rF   rA   r@   r>   r?   r   r#   r(   r&   r   r   9   sU   6r 	Xl{[  	1AQZKk\(9H
 	9JIYJ[(9	 	!11AAQRCS
O0 0 !!=~Y	! 8D9
%YN;;BP


Er(   r   c                      j                   j                  di       }g } j                   j                         D ]  \  }}t        |t              s|j
                  s||_        |j
                  |v r:||j
                     |j                         k(  rYt        d|j
                   d      |j                         ||j
                  <   |j                  |        |sy| _	        d j                   v sd j                   v rR|D ]M  }|j                  |j                  k7  s|j                  |j                  k7  s6t        d j                  d       d	 }| _         fd
}| _        y)zScans the given class for instances of Property and merges them
    into the classes __gproperties__ dict if it exists or adds it if not.
    __gproperties__z	Property z% 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                 T    |j                   j                  dd      }t        | |d       S N-_)r0   replacer}   )r%   pspecr0   s      r&   obj_get_propertyz,install_properties.<locals>.obj_get_property  s'    zz!!#s+tT4((r(   c                     |j                   j                  dd      }t        |d       }|r|j                  | |       y y r   )r0   r   r}   rC   )r%   r   rR   r0   propclss        r&   obj_set_propertyz,install_properties.<locals>.obj_set_property  s=    zz!!#s+sD$'IIdE" r(   )__dict__ri   itemsr7   r   r0   r   
ValueErrorappendr   rO   r@   rC   rA   r9   r)   r   r   )r   gpropertiespropsr0   r   r   r   s   `      r&   install_propertiesr     sd    ,,""#4b9KEll((* 
ddH% 99 	 yyK'tyy)T-@-@-BB 		{*OP  &*%8%8%:K		"LL!$ %CCLL(,=,M 	DyyD000DIIAUAU4U''7 86 6 	) +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&   <module>r      s   &       6 ^^
oo<<<<MM	MM	MM	^^
bE bEJ3+r(   