Top |
GObject * | g_binding_get_source () |
const gchar * | g_binding_get_source_property () |
GObject * | g_binding_get_target () |
const gchar * | g_binding_get_target_property () |
GBindingFlags | g_binding_get_flags () |
void | g_binding_unbind () |
GBinding * | g_object_bind_property () |
gboolean | (*GBindingTransformFunc) () |
GBinding * | g_object_bind_property_full () |
GBinding * | g_object_bind_property_with_closures () |
GBindingFlags | flags | Read / Write / Construct Only |
GObject * | source | Read / Write / Construct Only |
gchar * | source-property | Read / Write / Construct Only |
GObject * | target | Read / Write / Construct Only |
gchar * | target-property | Read / Write / Construct Only |
GBinding is the representation of a binding between a property on a GObject instance (or source) and another property on another GObject instance (or target). Whenever the source property changes, the same value is applied to the target property; for instance, the following binding:
1 2 3 |
g_object_bind_property (object1, "property-a", object2, "property-b", G_BINDING_DEFAULT); |
will cause the property named "property-b" of object2
to be updated
every time g_object_set()
or the specific accessor changes the value of
the property "property-a" of object1
.
It is possible to create a bidirectional binding between two properties of two GObject instances, so that if either property changes, the other is updated as well, for instance:
1 2 3 |
g_object_bind_property (object1, "property-a", object2, "property-b", G_BINDING_BIDIRECTIONAL); |
will keep the two properties in sync.
It is also possible to set a custom transformation function (in both directions, in case of a bidirectional binding) to apply a custom transformation from the source value to the target value before applying it; for instance, the following binding:
1 2 3 4 5 6 |
g_object_bind_property_full (adjustment1, "value", adjustment2, "value", G_BINDING_BIDIRECTIONAL, celsius_to_fahrenheit, fahrenheit_to_celsius, NULL, NULL); |
will keep the "value" property of the two adjustments in sync; the
celsius_to_fahrenheit
function will be called whenever the "value"
property of adjustment1
changes and will transform the current value
of the property before applying it to the "value" property of adjustment2
.
Vice versa, the fahrenheit_to_celsius
function will be called whenever
the "value" property of adjustment2
changes, and will transform the
current value of the property before applying it to the "value" property
of adjustment1
.
Note that GBinding does not resolve cycles by itself; a cycle like
1 2 3 |
object1:propertyA -> object2:propertyB object2:propertyB -> object3:propertyC object3:propertyC -> object1:propertyA |
might lead to an infinite loop. The loop, in this particular case,
can be avoided if the objects emit the “notify” signal only
if the value has effectively been changed. A binding is implemented
using the “notify” signal, so it is susceptible to all the
various ways of blocking a signal emission, like g_signal_stop_emission()
or g_signal_handler_block()
.
A binding will be severed, and the resources it allocates freed, whenever either one of the GObject instances it refers to are finalized, or when the GBinding instance loses its last reference.
Bindings for languages with garbage collection can use
g_binding_unbind()
to explicitly release a binding between the source
and target properties, instead of relying on the last reference on the
binding, source, and target instances to drop.
GBinding is available since GObject 2.26
GObject *
g_binding_get_source (GBinding *binding
);
Retrieves the GObject instance used as the source of the binding.
Since: 2.26
const gchar *
g_binding_get_source_property (GBinding *binding
);
Retrieves the name of the property of “source” used as the source of the binding.
Since: 2.26
GObject *
g_binding_get_target (GBinding *binding
);
Retrieves the GObject instance used as the target of the binding.
Since: 2.26
const gchar *
g_binding_get_target_property (GBinding *binding
);
Retrieves the name of the property of “target” used as the target of the binding.
Since: 2.26
GBindingFlags
g_binding_get_flags (GBinding *binding
);
Retrieves the flags passed when constructing the GBinding.
Since: 2.26
void
g_binding_unbind (GBinding *binding
);
Explicitly releases the binding between the source and the target
property expressed by binding
.
This function will release the reference that is being held on
the binding
instance; if you want to hold on to the GBinding instance
after calling g_binding_unbind()
, you will need to hold a reference
to it.
Since: 2.38
GBinding * g_object_bind_property (gpointer source
,const gchar *source_property
,gpointer target
,const gchar *target_property
,GBindingFlags flags
);
Creates a binding between source_property
on source
and target_property
on target
. Whenever the source_property
is changed the target_property
is
updated using the same value. For instance:
1 |
g_object_bind_property (action, "active", widget, "sensitive", 0); |
Will result in the "sensitive" property of the widget GObject instance to be updated with the same value of the "active" property of the action GObject instance.
If flags
contains G_BINDING_BIDIRECTIONAL
then the binding will be mutual:
if target_property
on target
changes then the source_property
on source
will be updated as well.
The binding will automatically be removed when either the source
or the
target
instances are finalized. To remove the binding without affecting the
source
and the target
you can just call g_object_unref()
on the returned
GBinding instance.
A GObject can have multiple bindings.
the GBinding instance representing the binding between the two GObject instances. The binding is released whenever the GBinding reference count reaches zero.
[transfer none]
Since: 2.26
gboolean (*GBindingTransformFunc) (GBinding *binding
,const GValue *from_value
,GValue *to_value
,gpointer user_data
);
A function to be called to transform from_value
to to_value
. If
this is the transform_to
function of a binding, then from_value
is the source_property
on the source
object, and to_value
is the
target_property
on the target
object. If this is the
transform_from
function of a G_BINDING_BIDIRECTIONAL
binding,
then those roles are reversed.
Since: 2.26
GBinding * g_object_bind_property_full (gpointer source
,const gchar *source_property
,gpointer target
,const gchar *target_property
,GBindingFlags flags
,GBindingTransformFunc transform_to
,GBindingTransformFunc transform_from
,gpointer user_data
,GDestroyNotify notify
);
Complete version of g_object_bind_property()
.
Creates a binding between source_property
on source
and target_property
on target
, allowing you to set the transformation functions to be used by
the binding.
If flags
contains G_BINDING_BIDIRECTIONAL
then the binding will be mutual:
if target_property
on target
changes then the source_property
on source
will be updated as well. The transform_from
function is only used in case
of bidirectional bindings, otherwise it will be ignored
The binding will automatically be removed when either the source
or the
target
instances are finalized. To remove the binding without affecting the
source
and the target
you can just call g_object_unref()
on the returned
GBinding instance.
A GObject can have multiple bindings.
The same user_data
parameter will be used for both transform_to
and transform_from
transformation functions; the notify
function will
be called once, when the binding is removed. If you need different data
for each transformation function, please use
g_object_bind_property_with_closures()
instead.
source |
the source GObject. |
[type GObject.Object] |
source_property |
the property on |
|
target |
the target GObject. |
[type GObject.Object] |
target_property |
the property on |
|
flags |
flags to pass to GBinding |
|
transform_to |
the transformation function
from the |
[scope notified][allow-none] |
transform_from |
the transformation function
from the |
[scope notified][allow-none] |
user_data |
custom data to be passed to the transformation functions,
or |
|
notify |
function to be called when disposing the binding, to free the resources used by the transformation functions |
the GBinding instance representing the binding between the two GObject instances. The binding is released whenever the GBinding reference count reaches zero.
[transfer none]
Since: 2.26
GBinding * g_object_bind_property_with_closures (gpointer source
,const gchar *source_property
,gpointer target
,const gchar *target_property
,GBindingFlags flags
,GClosure *transform_to
,GClosure *transform_from
);
Creates a binding between source_property
on source
and target_property
on target
, allowing you to set the transformation functions to be used by
the binding.
This function is the language bindings friendly version of
g_object_bind_property_full()
, using GClosures instead of
function pointers.
[rename-to g_object_bind_property_full]
source |
the source GObject. |
[type GObject.Object] |
source_property |
the property on |
|
target |
the target GObject. |
[type GObject.Object] |
target_property |
the property on |
|
flags |
flags to pass to GBinding |
|
transform_to |
a GClosure wrapping the transformation function
from the |
|
transform_from |
a GClosure wrapping the transformation function
from the |
the GBinding instance representing the binding between the two GObject instances. The binding is released whenever the GBinding reference count reaches zero.
[transfer none]
Since: 2.26
typedef struct _GBinding GBinding;
GBinding is an opaque structure whose members cannot be accessed directly.
Since: 2.26
Flags to be passed to g_object_bind_property()
or
g_object_bind_property_full()
.
This enumeration can be extended at later date.
The default binding; if the source property changes, the target property is updated with its value. |
||
Bidirectional binding; if either the property of the source or the property of the target changes, the other is updated. |
||
Synchronize the values of the source and target properties when creating the binding; the direction of the synchronization is always from the source to the target. |
||
If the two properties being bound are
booleans, setting one to |
Since: 2.26
“flags”
property“flags” GBindingFlags
Flags to be used to control the GBinding
Flags: Read / Write / Construct Only
Since: 2.26
“source”
property“source” GObject *
The GObject that should be used as the source of the binding
Flags: Read / Write / Construct Only
Since: 2.26
“source-property”
property“source-property” gchar *
The name of the property of “source” that should be used as the source of the binding
Flags: Read / Write / Construct Only
Default value: NULL
Since: 2.26
“target”
property“target” GObject *
The GObject that should be used as the target of the binding
Flags: Read / Write / Construct Only
Since: 2.26