o b^S7@sddlmZddlmZmZmZmZmZmZm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZmZejZejZejZejZejZej Z ej!Z!ej"Z"Gddde#Z$ddZ%dS))_gi) TYPE_NONETYPE_INTERFACE TYPE_CHAR TYPE_UCHAR TYPE_BOOLEANTYPE_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@sJeZdZdZeeeeee e e e e iZedededee e e eeeeediZeeeeededeee eeeeeiZedededededede dede di ZGdd d e Z!d d d d dde"j#d d f d d Z$d dZ%ddZ&ddZ'ddZ(ddZ)ddZ*ddZ+ddZ,ddZ-dd Z.d!d"Z/d#d$Z0d%d&Z1d'd(Z2d)d*Z3d+d,Z4d S)-PropertyaCreates 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 lllgc@seZdZddZdS)zProperty.__metaclass__cCsdS)Nzselfrr4/usr/lib/python3/dist-packages/gi/_propertyhelper.py__repr__szProperty.__metaclass__.__repr__N)__name__ __module__ __qualname__r"rrrr! __metaclass__s r&Nc Cs0d|_|dur t}|||_|||_|t|ts"t d||_ t|ts.t d||_ ||_ ||_ |r?|s?|j}n|rG|sG|j}n |sQ|sQ|j}|j}||||_|duro||krnt d|j|fn|}||_| dur| |krt d|j|fn|} | |_d|_dS)Nznick must be a stringzblurb must be a stringz+Minimum for type %s cannot be lower than %dz,Maximum for type %s cannot be higher than %d)nameobject_type_from_pythontype _get_defaultdefault_check_default isinstancestr TypeErrornickblurb__doc__flags_readonly_setter_writeonly_getter_default_getter_default_settergetterfset _get_minimumminimum _get_maximummaximum_exc) r r9setterr*r,r1r2r4r<r>rrr!__init__sX          zProperty.__init__cCsd|jpd|jjfS)Nzz(uninitialized))r'r*rrrr!r"szProperty.__repr__cCs6|dur|Sd|_||}|jr|j}d|_||SN)r?fget)r instanceklassvalueexcrrr!__get__s zProperty.__get__cCs:|durtd|_||j||jr|j}d|_|dSrB)r0r? set_propertyr')r rDrFrGrrr!__set__szProperty.__set__cCs ||S)z;Allows application of the getter along with init arguments.)r9r rCrrr!__call__s zProperty.__call__cCs |jr |j|_|j|_||_|S)z8Set the getter function to fget. For use as a decorator.)r3r2rCrKrrr!r9s zProperty.gettercCs||_|js |jj|_|S)z8Set the setter function to fset. For use as a decorator.)r:r'rCr#)r r:rrr!r@s zProperty.settercCs||jvr |j|St|tr!t|tjtjtjtjtj fr!|j S|t t t ttttttttttttttttttt fvr=|St!d|f)NzUnsupported type: %r)"_type_from_pytype_lookupr.r* issubclassrGObjectGEnumGFlagsGBoxed GInterface __gtype__rrrrrr rr r r r rrrrrrrrrrrr0)r type_rrr!r)s(    zProperty._type_from_pythoncCs|dur|S|j|jdSrB)_default_lookupgetr*)r r,rrr!r+ szProperty._get_defaultcCsp|j}|j}|tkr|dvrtd|f|tkr#|dur!tddS|tkr1|dur/tddS|trP|dur>tdt ||sNtd||fdS|t rgt ||setd||fdS|t r|durt |t s}tdt||D]}t|ttfvrtd t|qdS|tr|durt|d rt |tstd ||fdSdSdS) 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 %rzStrv value %s must be a listz'Strv value %s must contain only stringsrTz*variant value %s must be an instance of %r)r*r,rr0rris_arrGTyperrr.listreprr/bytesrhasattr)r ptyper,valrrr!r-sV   zProperty._check_defaultcC|j|jdSrB)_min_value_lookuprWr*rrrr!r;3zProperty._get_minimumcCr`rB)_max_value_lookuprWr*rrrr!r=6rbzProperty._get_maximumcCst|d|j|dSN_property_helper_)setattrr'r rDrFrrr!r8=szProperty._default_settercCst|d|j|jSrd)getattrr'r,r rDrrr!r7@szProperty._default_gettercCtd|jt|jf|_dS)Nz%s property of %s is read-onlyr0r'r*r#r?rgrrr!r5C zProperty._readonly_settercCrj)Nz%s property of %s is write-onlyrkrirrr!r6GrlzProperty._writeonly_getterc Cs|j}|ttttttttfvr|j |j |j f}n6|t ks/|t ks/|ts/|ts/|tr4|j f}n|ttfvr=d}n|tsG|trJd}nt||j|j|jf||jfS)Nr)r*rr r r r r rrr<r>r,rrrXrrrrrrrNotImplementedErrorr1r2r4)r r^argsrrr!get_pspec_argsOs&   zProperty.get_pspec_args)5r#r$r%r3intrboolrfloatrr/rr(rrMr r r r G_MAXFLOAT G_MAXDOUBLEG_MININTr G_MINLONGr ra G_MAXUINT G_MAXULONGG_MAXINT G_MAXLONGrcrVr*r&rPARAM_READWRITErAr"rHrJrLr9r@r)r+r-r;r=r8r7r5r6rorrrr!r'sr7     8    ! rcsjdi}g}jD]1\}}t|tr?|js||_|j|vr3||j|kr,qtd|j|||j<||q|sDdS|_ djvsQdjvrj|D]}|j |j ksa|j |j kritdjfqSdd}|_fd d }|_dS) 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__Ndo_get_propertydo_set_propertyzGObject subclass %r defines do_get/set_property and it also uses a property with a custom setter or getter. This is not allowedcSs|jdd}t||dSN-_)r'replacerh)r pspecr'rrr!obj_get_propertys z,install_properties..obj_get_propertycs2|jdd}t|d}|r|||dSdSr)r'rrhr:)r rrFr'propclsrr!obj_set_propertys  z,install_properties..obj_set_property)__dict__rWitemsr.rr'ro ValueErrorappendr|rCr7r:r8r0r#r}r~)r gpropertiespropsr'rrrrrr!install_propertiesbs:     rN)&rr _constantsrrrrrrr r r r r rrrrrrrrrrrrrrsrtruryrwrvrzrxr(rrrrrr!s h =