a 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)Nzselfrr8/usr/lib64/python3.9/site-packages/gi/_propertyhelper.py__repr__szProperty.__metaclass__.__repr__N)__name__ __module__ __qualname__r"rrrr! __metaclass__sr&Nc Cs4d|_|durt}|||_|||_|t|tsDt d||_ t|ts\t d||_ ||_ ||_ |r~|s~|j}n$|r|s|j}n|s|s|j}|j}||||_|dur||krt d|j|fn|}||_| dur| |kr$t 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__sT         zProperty.__init__cCsd|jp d|jjfS)Nzz(uninitialized))r'r*rrrr!r"szProperty.__repr__cCs6|dur |Sd|_||}|jr2|j}d|_||SN)r?fget)r instanceklassvalueexcrrr!__get__s zProperty.__get__cCs:|dur td|_||j||jr6|j}d|_|dSrB)r0r?Z set_propertyr')r rDrFrGrrr!__set__szProperty.__set__cCs ||S)z;Allows application of the getter along with init arguments.)r9r rCrrr!__call__szProperty.__call__cCs |jr|j|_|j|_||_|S)z8Set the getter function to fget. For use as a decorator.)r3r2rCrJrrr!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|trBt|tjtjtjtjtj frB|j S|t t t ttttttttttttttttttt fvrz|St!d|fdS)NzUnsupported type: %r)"_type_from_pytype_lookupr.r* issubclassrZGObjectZGEnumZGFlagsZGBoxedZ 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_defaultcCsz|j}|j}|tkr.|dvr.td|fnH|tkrJ|durFtdn,|tkrf|durbtdn|tr|durtdn t ||std||fn|t rt ||std||fn|t r2|dur2t |t stdt||D](}t|ttfvrtd t|qnD|trv|durvt|d rft |tsvtd ||fdS) 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 stringsrNz*variant value %s must be an instance of %r)r*r,rr0rris_arrZGTyperrr.listreprr/bytesrhasattr)r ptyper,valrrr!r-sF      zProperty._check_defaultcCs|j|jdSrB)_min_value_lookuprQr*rrrr!r;3szProperty._get_minimumcCs|j|jdSrB)_max_value_lookuprQr*rrrr!r=6szProperty._get_maximumcCst|d|j|dSNZ_property_helper_)setattrr'r rDrFrrr!r8=szProperty._default_settercCst|d|j|jSr[)getattrr'r,r rDrrr!r7@szProperty._default_gettercCstd|jt|jf|_dS)Nz%s property of %s is read-onlyr0r'r*r#r?r]rrr!r5Cs zProperty._readonly_settercCstd|jt|jf|_dS)Nz%s property of %s is write-onlyr`r_rrr!r6Gs zProperty._writeonly_getterc Cs|j}|ttttttttfvr0|j |j |j f}nl|t ks^|t ks^|ts^|ts^|trh|j f}n4|ttfvrzd}n"|ts|trd}nt||j|j|jf||jfS)Nr)r*rr r r r r rrr<r>r,rrrRrrrrrrrNotImplementedErrorr1r2r4)r rWargsrrr!get_pspec_argsOs&   zProperty.get_pspec_args)5r#r$r%r3intrboolrfloatrr/rr(rrLr r r r G_MAXFLOAT G_MAXDOUBLEG_MININTr G_MINLONGr rY G_MAXUINT G_MAXULONGG_MAXINT G_MAXLONGrZrPr*r&rZPARAM_READWRITErAr"rHrIrKr9r@r)r+r-r;r=r8r7r5r6rcrrrr!r'sp7     8    !rcsjdi}g}jD]b\}}t|tr|js:||_|j|vrf||j|krXqtd|j|||j<||q|sdS|_ djvsdjvr|D],}|j |j ks|j |j krtdjfqdd}|_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'replacer^)r pspecr'rrr!obj_get_propertysz,install_properties..obj_get_propertycs.|jdd}t|d}|r*|||dSrr)r'rur^r:)r rvrFr'propclsrr!obj_set_propertys z,install_properties..obj_set_property)__dict__rQitemsr.rr'rc ValueErrorappendrorCr7r:r8r0r#rprq)rzZ gpropertiesZpropsr'rxrwr{rryr!install_propertiesbs6    rN)&rrZ _constantsrrrrrrr r r r r rrrrrrrrrrrrrrgrhrirmrkrjrnrlr(rrrrrr!s h=