GObject.Binding¶
| Subclasses: | None |
|---|
Methods¶
| Inherited: | GObject.Object (37) |
|---|---|
| Structs: | GObject.ObjectClass (5) |
get_flags () |
|
get_source () |
|
get_source_property () |
|
get_target () |
|
get_target_property () |
|
unbind () |
Virtual Methods¶
| Inherited: | GObject.Object (7) |
|---|
Properties¶
| Name | Type | Flags | Short Description |
|---|---|---|---|
flags |
GObject.BindingFlags |
r/w/co | The binding flags |
source |
GObject.Object |
r/w/co | The source of the binding |
source-property |
str |
r/w/co | The property on the source to bind |
target |
GObject.Object |
r/w/co | The target of the binding |
target-property |
str |
r/w/co | The property on the target to bind |
Signals¶
| Inherited: | GObject.Object (1) |
|---|
Fields¶
| Inherited: | GObject.Object (1) |
|---|
Class Details¶
-
class
GObject.Binding(**kwargs)¶ Bases: GObject.ObjectAbstract: No GObject.Bindingis the representation of a binding between a property on aGObject.Objectinstance (or source) and another property on anotherGObject.Objectinstance (or target). Whenever the source property changes, the same value is applied to the target property; for instance, the following binding: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.Objectinstances, so that if either property changes, the other is updated as well, for instance: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:
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
GObject.Bindingdoes not resolve cycles by itself; a cycle likeobject1: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
GObject.Object::notifysignal only if the value has effectively been changed. A binding is implemented using theGObject.Object::notifysignal, so it is susceptible to all the various ways of blocking a signal emission, likeGObject.signal_stop_emission() orGObject.signal_handler_block().A binding will be severed, and the resources it allocates freed, whenever either one of the
GObject.Objectinstances it refers to are finalized, or when theGObject.Bindinginstance loses its last reference.Bindings for languages with garbage collection can use
GObject.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.GObject.Bindingis available sinceGObject.Object2.26New in version 2.26.
-
get_flags()[source]¶ Returns: the GObject.BindingFlagsused by theGObject.BindingReturn type: GObject.BindingFlagsRetrieves the flags passed when constructing the
GObject.Binding.New in version 2.26.
-
get_source()[source]¶ Returns: the source GObject.ObjectReturn type: GObject.ObjectRetrieves the
GObject.Objectinstance used as the source of the binding.New in version 2.26.
-
get_source_property()[source]¶ Returns: the name of the source property Return type: strRetrieves the name of the property of
GObject.Binding:sourceused as the source of the binding.New in version 2.26.
-
get_target()[source]¶ Returns: the target GObject.ObjectReturn type: GObject.ObjectRetrieves the
GObject.Objectinstance used as the target of the binding.New in version 2.26.
-
get_target_property()[source]¶ Returns: the name of the target property Return type: strRetrieves the name of the property of
GObject.Binding:targetused as the target of the binding.New in version 2.26.
-
unbind()[source]¶ Explicitly releases the binding between the source and the target property expressed by self.
This function will release the reference that is being held on the self instance; if you want to hold on to the
GObject.Bindinginstance after callingGObject.Binding.unbind(), you will need to hold a reference to it.New in version 2.38.
-
Property Details¶
-
GObject.Binding.props.flags¶ Name: flagsType: GObject.BindingFlagsDefault Value: GObject.BindingFlags.DEFAULTFlags: READABLE,WRITABLE,CONSTRUCT_ONLYFlags to be used to control the
GObject.BindingNew in version 2.26.
-
GObject.Binding.props.source¶ Name: sourceType: GObject.ObjectDefault Value: NoneFlags: READABLE,WRITABLE,CONSTRUCT_ONLYThe
GObject.Objectthat should be used as the source of the bindingNew in version 2.26.
-
GObject.Binding.props.source_property¶ Name: source-propertyType: strDefault Value: NoneFlags: READABLE,WRITABLE,CONSTRUCT_ONLYThe name of the property of
GObject.Binding:sourcethat should be used as the source of the binding.This should be in canonical form to get the best performance.
New in version 2.26.
-
GObject.Binding.props.target¶ Name: targetType: GObject.ObjectDefault Value: NoneFlags: READABLE,WRITABLE,CONSTRUCT_ONLYThe
GObject.Objectthat should be used as the target of the bindingNew in version 2.26.
-
GObject.Binding.props.target_property¶ Name: target-propertyType: strDefault Value: NoneFlags: READABLE,WRITABLE,CONSTRUCT_ONLYThe name of the property of
GObject.Binding:targetthat should be used as the target of the binding.This should be in canonical form to get the best performance.
New in version 2.26.