
    fS7                     T   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e#      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
                 H   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  r8t        d| j                  | j)                         fz        | j)                         }|| _        |	;|	| j-                         kD  r8t        d| j                  | j-                         fz        | j-                         }	|	| _        d | _        y )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	((1$$344	%%455
 
 &**FF++F))F))FF 	**,,AYY 1 1 3456 6 '')G**,,BYY 1 1 3456 6 '')G	r(   c                 X    d| j                   xs dd| j                  j                   dS )Nz<GObject Property z(uninitialized)z (z)>)r.   r1   r$   s    r&   r'   zProperty.__repr__   s'    II***IINN 	r(   c                     || S d | _         | j                  |      }| j                   r| j                   }d | _         ||S N)rF   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 rK   )r7   rF   set_propertyr.   )r%   rM   rO   rP   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.)r@   r%   rL   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:   r9   rL   rV   s     r&   r@   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.)rA   r.   rL   r)   )r%   rA   s     r&   rG   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_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077%!$!$!$!$	!1 2
 ??"y.)ZL)!:{!;!:{K$j)\K K Le=>>r(   c                 V    ||S | j                   j                  | j                  d       S rK   )_default_lookupgetr1   )r%   r3   s     r&   r2   zProperty._get_default  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              r_|]t        |t              st        d	t        |      z        |D ]0  }t        |      t        t         fvst        d
t        |      z         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 %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;BDF Fm#" KLL #j " JKK #ZZ	" GHHYYw',,U3!(%!1 2 2 4 ZZ
#99W%**51!(%!1 2 2 2 ZZ	"w':gt, >g NOO ^9S%L0#$MPST[P\$\]]^ ZZ%'*=7K0		'8J8O8OP\8]!(%!1 2 2 9^ +>%r(   c                 N    | j                   j                  | j                  d       S rK   )_min_value_lookuprf   r1   r$   s    r&   rB   zProperty._get_minimum3      %%))$))T::r(   c                 N    | j                   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   |       y N_property_helper_)setattrr.   r%   rM   rO   s      r&   r?   zProperty._default_setter=  s    -		95Ar(   c                 J    t        |d| j                  z   | j                        S rv   )getattrr.   r3   r%   rM   s     r&   r>   zProperty._default_getter@  s    x!4tyy!@$,,OOr(   c                 j    t        | j                  dt        |      j                  d      | _        y )N property of z is read-onlyr7   r.   r1   r)   rF   ry   s      r&   r<   zProperty._readonly_setterC  &    IItH~..0 1	r(   c                 j    t        | j                  dt        |      j                  d      | _        y )Nr~   z is write-onlyr   r|   s     r&   r=   zProperty._writeonly_getterG  r   r(   c           	      r   | j                   }|t        t        t        t        t
        t        t        t        fv r$| j                  | j                  | j                  f}n|t        k(  sH|t        k(  s?|j                  t              s*|j                  t               s|j                  t"              r| j                  f}nI|t$        t&        fv rd}n8|j                  t(              s|j                  t*              rd}nt-        |      | j                   | j.                  | j0                  f|z   | j2                  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<<t||;D{"e|&;jj#uzz*'=jj&LL?D}j11DZZ$

:(>D%e,,		499djj1D8DJJ=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   '   sL   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 #4dD#*=*=t6p
	!?(9
2B;;BP11Ir(   r   c                      j                   j                  di       }g } j                   j                         D ]  \  }}t        |t              s|j
                  s||_        |j
                  |v r9||j
                     |j                         k(  rYt        d|j
                  z        |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)
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                 T    |j                   j                  dd      }t        | |d       S N-_)r.   replacer{   )r%   pspecr.   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   )r.   r   r{   rA   )r%   r   rO   r.   propclss        r&   obj_set_propertyz,install_properties.<locals>.obj_set_property  s=    zz!!#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  sT   
 ,,""#4b9KEll((* 
ddH% 99 	 yyK'tyy)T-@-@-BB !SVZV_V_!_``%)%8%8%:K		"LL  %CCLL(,=,M 	%DyyD000DIIAUAU4U \\$% %	%) +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 ^^
oo<<<<MM	MM	MM	^^
xIv xIv	0+r(   