Adw.CssClassBinding

g Adw.CssClassBinding Adw.CssClassBinding GObject.Object GObject.Object GObject.Object->Adw.CssClassBinding

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

get_flags ()

get_source ()

get_source_property ()

get_target ()

get_target_css_class ()

unbind ()

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

flags

GObject.BindingFlags

r/w/co

source

GObject.Object

r/w/co

source-property

str

r/w/co

target

Gtk.Widget

r/w/co

target-css-class

str

r/w/co

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Adw.CssClassBinding(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Adw.CssClassBindingClass

A binding between a [class`GObject`.Object] property and a CSS class on a [class`Gtk`.Widget].

To create a binding, use [func`Adw`.bind_property_to_css_class].

Whenever the source property changes, a CSS class is toggled on the target object; for instance, given the following binding:

``c adw_bind_property_to_css_class (source, “property”,

target, “css-class”, G_BINDING_DEFAULT);

``

when property is a boolean property, css-class will be set every time the value of property is changed to TRUE, and vice versa.

Using [func`Adw`.bind_property_to_css_class_full], it’s possible to define a custom mapping between a property and the boolean enable state, that is, defining a mapping between any arbitrary property type and a boolean type. This allows for any property, not just boolean properties, to be bound to a CSS class; for instance, the following binding

``c adw_bind_property_to_css_class_full (source, “property”,

target, “css-class”, G_BINDING_DEFAULT, int_to_bool, bool_to_int, NULL, NULL);

``

will map an integer-typed property to a boolean value, and use the value of that boolean to toggle the CSS class.

It is possible to invert the type of a boolean without using a custom map function by using the [flags`GObject`.BindingFlags.INVERT_BOOLEAN] flag.

A binding will be removed, and any allocated resources freed, whenever either one of the source or target instances are finalized, or when the binding instances loses its last reference.

Languages with garbage collection, or developers wanting to fully control the lifecycle of a binding may use [method`CssClassBinding`.unbind] to expliticly release a binding, instead of relying on the last reference on the binding, source, and target instances to drop.

Added in version 1.10.

get_flags()
Returns:

the binding flags

Return type:

GObject.BindingFlags

Gets the flags passed when constructing the binding.

Added in version 1.10.

get_source()
Returns:

the source, or NULL if it doesn’t exist anymore

Return type:

GObject.Object or None

Gets the object instance passed as the source of the binding.

While a binding can outlive the source as the binding doesn’t hold a strong reference to the source, the binding will try to finalize itself when it does not have a valid source. If the source, however, is destroyed before the binding is fully finalized then this function will return NULL.

Added in version 1.10.

get_source_property()
Returns:

the name of the source property

Return type:

str

Gets the name of the property bound from [property`CssClassBinding`:py:data::source<Adw.CssClassBinding.props.source>].

Added in version 1.10.

get_target()
Returns:

the target, or NULL if it doesn’t exist anymore

Return type:

Gtk.Widget or None

Gets the widget instance passed as the target of the binding.

While a binding can outlive the target as the binding doesn’t hold a strong reference to the target, the binding will try to finalize itself when it does not have a valid target. If the target, however, is destroyed before the binding is fully finalized then this function will return NULL.

Added in version 1.10.

get_target_css_class()
Returns:

the name of the target CSS class

Return type:

str

Gets the CSS class to toggle on [property`CssClassBinding`:py:data::target<Adw.CssClassBinding.props.target>].

Added in version 1.10.

unbind()

Explicitly releases the binding between the source and the target.

This function will release the reference that is being held on self if the binding is still bound; if you want to hold on to the binding instance after calling this method, you will need to manually hold a reference to it.

Note that this function does not take ownership of self, it only unrefs the instance that was initially created by [func`Adw`.bind_property_to_css_class] and is owned by the binding.

Added in version 1.10.

Property Details

Adw.CssClassBinding.props.flags
Name:

flags

Type:

GObject.BindingFlags

Default Value:

GObject.BindingFlags.DEFAULT

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

Flags to be used to control the binding.

Added in version 1.10.

Adw.CssClassBinding.props.source
Name:

source

Type:

GObject.Object

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The object to use as the source of the CSS class binding.

Added in version 1.10.

Adw.CssClassBinding.props.source_property
Name:

source-property

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The name of the property that shoudl be used as the source of the binding.

Added in version 1.10.

Adw.CssClassBinding.props.target
Name:

target

Type:

Gtk.Widget

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The widget to use as the target of the CSS class binding.

Added in version 1.10.

Adw.CssClassBinding.props.target_css_class
Name:

target-css-class

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The name of the CSS class that should be toggled on the target object.

Added in version 1.10.