3 <_:@sddlZddlZddlmZddlmZmZmZmZm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZejZejZejZej Z ej!Z!ej"Z"ej#Z#ej$Z$ej%d kre&Z'e(Z)ne*Z'e+Z)Gddde,Z-dd Z.dS) N)_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@sNeZdZdZeeeeee e e e e eeiZedededee e e eeeeed/iZeeeeed1ed3eee eeeeeiZedededededede dede di Z Gd d d e!Z"d d d d dde#j$d d f d d Z%ddZ&ddZ'ddZ(ddZ)ddZ*ddZ+ddZ,ddZ-ddZ.d d!Z/d"d#Z0d$d%Z1d&d'Z2d(d)Z3d*d+Z4d,d-Z5d S)4PropertyaCreates 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 r?r@gc@seZdZddZdS)zProperty.__metaclass__cCsdS)Nz)selfr"r"'/usr/lib64/python3.6/_propertyhelper.py__repr__szProperty.__metaclass__.__repr__N)__name__ __module__ __qualname__r%r"r"r"r$ __metaclass__sr)Nc Cs<d|_|dkrt}|j||_|j||_|jt|tsDt d||_ t|ts\t d||_ ||_ ||_ |r| r|j}n*|r| r|j}n| r| r|j}|j}|j|||_|dk r||jkrt d|j|jfn|j}||_| dk r$| |jkr,t d|j|jfn|j} | |_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 isinstance _basestring TypeErrornickblurb__doc__flags_readonly_setter_writeonly_getter_default_getter_default_settergetterfset _get_minimumminimum _get_maximummaximum_exc) r#r<setterr-r/r4r5r7r?rAr"r"r$__init__sL          zProperty.__init__cCsd|jp dtj|jfS)Nzz(uninitialized))r*rZ type_namer-)r#r"r"r$r%szProperty.__repr__c Cs\|dkr |Sd|_y|j|}Wn tk r@tjd}YnX|jrX|j}d|_||S)N)rBfget Exception traceback print_exc)r#instanceklassvalueexcr"r"r$__get__s zProperty.__get__cCs:|dkr td|_|j|j||jr6|j}d|_|dS)N)r3rBZ set_propertyr*)r#rIrKrLr"r"r$__set__szProperty.__set__cCs |j|S)z;Allows application of the getter along with init arguments.)r<)r#rEr"r"r$__call__szProperty.__call__cCs |jr|j|_|j|_||_|S)z8Set the getter function to fget. For use as a decorator.)r6r5rE)r#rEr"r"r$r<s zProperty.gettercCs||_|js|jj|_|S)z8Set the setter function to fset. For use as a decorator.)r=r*rEr&)r#r=r"r"r$rCs zProperty.settercCs||jkr|j|St|trBt|tjtjtjtjtj frB|j S|t t t ttttttttttttttttttt fkrz|St!d|fdS)NzUnsupported type: %r)"_type_from_pytype_lookupr1r- issubclassrZGObjectZGEnumZGFlagsZGBoxedZ GInterface __gtype__rrrrr r rr r r rrrrrrrrrrrrr3)r#Ztype_r"r"r$r,s"     zProperty._type_from_pythoncCs|dk r |S|jj|jdS)N)_default_lookupgetr-)r#r/r"r"r$r.&szProperty._get_defaultcCs||j}|j}|tkr.|d kr.td|fnJ|tkrJ|dk rFtdn.|tkrf|dk rbtdntj|tr|dkrtdntj||std||fntj|t rtj||std||fntj|t o|dk r2t |t std t |xx|D](}t|ttfkrtd t|qWnFtj|trx|dk rxt|d  shtj|t rxtd ||fdS)NTFz%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 stringsrRz*variant value %s must be an instance of %r)TF)r-r/rr3rrrZ type_is_arrrr1listreprstrbytesrhasattr)r#ptyper/valr"r"r$r0+s>         zProperty._check_defaultcCs|jj|jdS)N)_min_value_lookuprTr-)r#r"r"r$r>LszProperty._get_minimumcCs|jj|jdS)N)_max_value_lookuprTr-)r#r"r"r$r@OszProperty._get_maximumcCst|d|j|dS)N_property_helper_)setattrr*)r#rIrKr"r"r$r;VszProperty._default_settercCst|d|j|jS)Nr^)getattrr*r/)r#rIr"r"r$r:YszProperty._default_gettercCstd|jt|jf|_dS)Nz%s property of %s is read-only)r3r*r-r&rB)r#rIrKr"r"r$r8\szProperty._readonly_settercCstd|jt|jf|_dS)Nz%s property of %s is write-only)r3r*r-r&rB)r#rIr"r"r$r9`szProperty._writeonly_getterc Cs|j}|ttttttttfkr0|j |j |j f}nl|t ks^|t ks^|jts^|jts^|jtrh|j f}n4|ttfkrzf}n"|jts|jtrf}nt||j|j|jf||jfS)N)r-r r r r r rrrr?rAr/rrZis_arrrrrrrNotImplementedErrorr4r5r7)r#rZargsr"r"r$get_pspec_argshs    zProperty.get_pspec_argsllllll)6r&r'r(r6_longr intr boolrfloatrrWrr+rrPr r rr G_MAXFLOAT G_MAXDOUBLEG_MININT G_MINLONGr r\ G_MAXUINT G_MAXULONGG_MAXINT G_MAXLONGr]rSr-r)rZPARAM_READWRITErDr%rMrNrOr<rCr,r.r0r>r@r;r:r8r9rcr"r"r"r$r2sh66   !rcsjjdi}g}xpjjD]b\}}t|tr|js<||_|j|krh||j|jkrZqtd|j|j||j<|j|qW|sdS|_ djksdjkrx4|D],}|j |j ks|j |j krtdjfqWdd}|_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|jjdd}t||dS)N-_)r*replacer`)r#pspecr*r"r"r$obj_get_propertysz,install_properties..obj_get_propertycs.|jjdd}t|d}|r*|j||dS)Nrsrt)r*rur`r=)r#rvrKr*prop)clsr"r$obj_set_propertys z,install_properties..obj_set_property)__dict__rTitemsr1rr*rc ValueErrorappendrprEr:r=r;r3r&rqrr)ryZ gpropertiesZpropsr*rxrwrzr")ryr$install_properties{s2    r)rr)/sysrGr!rZ _constantsrrrrrr r r r r rrrrrrrrrrrrrrrhrirjrnrlrkrorm version_inforWr2rerdZ basestringZlongr+rrr"r"r"r$s( h K