ParamSpec
- class ParamSpec(*args, **kwargs)
Subclasses: ParamSpecBoolean
, ParamSpecBoxed
, ParamSpecChar
, ParamSpecDouble
, ParamSpecEnum
, ParamSpecFlags
, ParamSpecFloat
, ParamSpecGType
, ParamSpecInt
, ParamSpecInt64
, ParamSpecLong
, ParamSpecObject
, ParamSpecOverride
, ParamSpecParam
, ParamSpecPointer
, ParamSpecString
, ParamSpecUChar
, ParamSpecUInt
, ParamSpecUInt64
, ParamSpecULong
, ParamSpecUnichar
, ParamSpecValueArray
, ParamSpecVariant
GParamSpec
encapsulates the metadata required to specify parameters, such as GObject
properties.
Parameter names
A property name consists of one or more segments consisting of ASCII letters
and digits, separated by either the -
or _
character. The first
character of a property name must be a letter. These are the same rules as
for signal naming (see signal_new
).
When creating and looking up a GParamSpec
, either separator can be
used, but they cannot be mixed. Using -
is considerably more
efficient, and is the ‘canonical form’. Using _
is discouraged.
Methods
- class ParamSpec
-
- get_default_value() Any
Gets the default value of
pspec
as a pointer to aValue
.The
Value
will remain valid for the life ofpspec
.Added in version 2.38.
- get_name() str
Get the name of a
ParamSpec
.The name is always an “interned” string (as per
intern_string()
). This allows for pointer-value comparisons.
- get_qdata(quark: int) None
Gets back user data pointers stored via
set_qdata()
.- Parameters:
quark – a
Quark
, naming the user data pointer
- get_redirect_target() ParamSpec | None
If the paramspec redirects operations to another paramspec, returns that paramspec. Redirect is used typically for providing a new implementation of a property in a derived type while preserving all the properties from the parent type. Redirection is established by creating a property of type
GParamSpecOverride
. Seeoverride_property()
for an example of the use of this capability.Added in version 2.4.
- is_valid_name(name: str) bool
Validate a property name for a
ParamSpec
. This can be useful for dynamically-generated properties which need to be validated at run-time before actually trying to create them.See [canonical parameter names][canonical-parameter-names] for details of the rules for valid names.
Added in version 2.66.
- Parameters:
name – the canonical name of the property
- set_qdata(quark: int, data: None) None
Sets an opaque, named pointer on a
ParamSpec
. The name is specified through aQuark
(retrieved e.g. viaquark_from_static_string()
), and the pointer can be gotten back from thepspec
withget_qdata()
. Setting a previously set user data pointer, overrides (frees) the old pointer set, usingNone
as pointer essentially removes the data stored.- Parameters:
quark – a
Quark
, naming the user data pointerdata – an opaque user data pointer
- sink() None
The initial reference count of a newly created
ParamSpec
is 1, even though no one has explicitly calledref()
on it yet. So the initial reference count is flagged as “floating”, until someone callsg_param_spec_ref (pspec); g_param_spec_sink (pspec);
in sequence on it, taking over the initial reference count (thus ending up with apspec
that has a reference count of 1 still, but is not flagged “floating” anymore).
Virtual Methods
- class ParamSpec
- do_finalize() None
The instance finalization function (optional), should chain up to the finalize method of the parent class.
- do_value_is_valid(value: Any) bool
Checks if contents of
value
comply with the specifications set out by this type, without modifying the value. This vfunc is optional. If it isn’t set, GObject will usevalue_validate
. Since 2.74- Parameters:
value
- do_value_set_default(value: Any) None
Resets a
value
to the default value for this type (recommended, the default isreset()
), seeparam_value_set_default()
.- Parameters:
value
- do_value_validate(value: Any) bool
Ensures that the contents of
value
comply with the specifications set out by this type (optional), seeparam_value_validate()
.- Parameters:
value
- do_values_cmp(value1: Any, value2: Any) int
Compares
value1
withvalue2
according to this type (recommended, the default is memcmp()), seeparam_values_cmp()
.- Parameters:
value1
value2