Adw.ToggleGroup¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Widget (183), GObject.Object (37), Gtk.Accessible (17), Gtk.Buildable (1), Gtk.Orientable (2)
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9)
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r |
|||
r |
Signals¶
- Inherited:
Fields¶
- Inherited:
Class Details¶
- class Adw.ToggleGroup(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
A group of exclusive toggles.
<picture> <source srcset=”toggle-group-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”toggle-group.png” alt=”toggle-group”> </picture>
AdwToggleGroup
presents a set of exclusive toggles, represented as [class`Toggle`] objects. Each toggle can display an icon, a label, an icon and a label, or a custom child.Toggles are indexed by their position, with the first toggle being equivalent to 0, and so on. Use the [property`ToggleGroup`:py:data::active<Adw.ToggleGroup.props.active>] to get that position.
Toggles can also have optional names, set via the [property`Toggle`:py:data::name<Adw.ToggleGroup.props.name>] property. The name of the active toggle can be accessed via the [property`ToggleGroup`:py:data::active-name<Adw.ToggleGroup.props.active_name>] property.
AdwToggle
objects can be retrieved via their index or name, using [method`ToggleGroup`.get_toggle] or [method`ToggleGroup`.get_toggle_by_name] respectively.AdwToggleGroup
also provides a [iface`Gtk`.SelectionModel] of its toggles via the [property`ToggleGroup`:py:data::toggles<Adw.ToggleGroup.props.toggles>] property.AdwToggleGroup
is orientable, and the toggles can be displayed horizontally or vertically. This is mostly useful for icon-only toggles.Use the [property`ToggleGroup`:py:data::homogeneous<Adw.ToggleGroup.props.homogeneous>] property to make the toggles take the same size, and the [property`ToggleGroup`:py:data::can-shrink<Adw.ToggleGroup.props.can_shrink>] to control whether the toggles can ellipsize.
Example of an
AdwToggleGroup
UI definition:- ``xml
- <object class=”AdwToggleGroup”>
<property name=”active-name”>picture</property> <child>
- <object class=”AdwToggle”>
<property name=”icon-name”>camera-photo-symbolic</property> <property name=”tooltip” translatable=”yes”>Picture Mode</property> <property name=”name”>picture</property>
</object>
</child> <child>
- <object class=”AdwToggle”>
<property name=”icon-name”>camera-video-symbolic</property> <property name=”tooltip” translatable=”yes”>Recording Mode</property> <property name=”name”>recording</property>
</object>
</child>
</object>
See also: [class`InlineViewSwitcher`].
- CSS nodes
AdwToggleGroup
has a main CSS node with the nametoggle-group
.Its toggles have CSS nodes with the name
toggle
, and its separators have nodes with the nameseparator
.Toggle nodes will have a different style classes depending on their content:
.text-button
for labels,.image-button
for icons,.image-text-button
for both or no style class for custom children.The hidden separators use the
.hidden
style class.- Style classes
AdwToggleGroup
can use the .flat style class to remove its background and make it look like a group of buttons.<picture> <source srcset=”toggle-group-flat-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”toggle-group-flat.png” alt=”toggle-group-flat”> </picture>
It can also use the .round style class to make its toggles and the group itself rounded.
<picture> <source srcset=”toggle-group-round-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”toggle-group-round.png” alt=”toggle-group-round”> </picture>
They can also be combined with each other.
<picture> <source srcset=”toggle-group-flat-round-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”toggle-group-flat-round.png” alt=”toggle-group-flat-round”> </picture>
- Accessibility
AdwToggleGroup
uses theGTK_ACCESSIBLE_ROLE_RADIO_GROUP
role. Its toggles use theGTK_ACCESSIBLE_ROLE_RADIO
role.New in version 1.7.
- classmethod new()¶
- Returns:
the newly created
AdwToggleGroup
- Return type:
Creates a new
AdwToggleGroup
.New in version 1.7.
- add(toggle)¶
- Parameters:
toggle (
Adw.Toggle
) – the toggle to add
Adds a toggle to self.
New in version 1.7.
- get_active()¶
- Returns:
the active toggle index
- Return type:
Gets the index of the active toggle in self.
Returns
GTK_INVALID_LIST_POSITION
if no toggle is active.New in version 1.7.
- get_active_name()¶
-
Gets the name of the active toggle in self.
Can be
NULL
if the currently active toggle doesn’t have a name.See [property`Toggle`:py:data::name<Adw.ToggleGroup.props.name>].
New in version 1.7.
- get_can_shrink()¶
- Returns:
whether the toggles can shrink
- Return type:
Gets whether the toggles can be smaller than the natural size of their contents.
New in version 1.7.
- get_homogeneous()¶
- Returns:
whether all toggles take the same size
- Return type:
Gets whether all toggles take the same size.
New in version 1.7.
- get_n_toggles()¶
- Returns:
the number of toggles
- Return type:
Gets the number of toggles within self.
New in version 1.7.
- get_toggle(index)¶
- Parameters:
index (
int
) – toggle’s index- Returns:
the toggle
- Return type:
Adw.Toggle
orNone
Gets the toggle with index from self.
New in version 1.7.
- get_toggle_by_name(name)¶
- Parameters:
name (
str
) – toggle name- Returns:
the toggle
- Return type:
Adw.Toggle
orNone
Gets the toggle with the name name from self.
New in version 1.7.
- get_toggles()¶
- Returns:
a
GtkSelectionModel
for the group’s toggles- Return type:
Returns a [iface`Gio`.ListModel] that contains the toggles of the group.
This can be used to keep an up-to-date view. The model also implements [iface`Gtk`.SelectionModel] and can be used to track and change the active toggle.
- remove(toggle)¶
- Parameters:
toggle (
Adw.Toggle
) – a toggle to remove
Removes toggle from self.
New in version 1.7.
- remove_all()¶
Removes all toggles from self.
New in version 1.7.
- set_active(active)¶
- Parameters:
active (
int
) – toggle index
Sets the active toggle for self.
If the index is larger than the number of toggles in self, unsets the current active toggle.
New in version 1.7.
- set_active_name(name)¶
-
Sets the active toggle for self.
The name can be set via [property`Toggle`:py:data::name<Adw.ToggleGroup.props.name>].
If name is
NULL
, unset the current active toggle instead.New in version 1.7.
Property Details¶
- Adw.ToggleGroup.props.active¶
- Name:
active
- Type:
- Default Value:
4294967295
- Flags:
The index of the active toggle.
Setting the index to a larger value than the number of toggles in the group unsets the current active toggle.
If no toggle is active, the property will be set to [const`Gtk`.INVALID_LIST_POSITION].
New in version 1.7.
- Adw.ToggleGroup.props.active_name¶
- Name:
active-name
- Type:
- Default Value:
- Flags:
The name of the active toggle.
The name can be set via [property`Toggle`:py:data::name<Adw.ToggleGroup.props.name>]. If the currently active toggle doesn’t have a name, the property will be set to
NULL
.Set it to
NULL
to unset the current active toggle.New in version 1.7.
- Adw.ToggleGroup.props.can_shrink¶
- Name:
can-shrink
- Type:
- Default Value:
- Flags:
Whether the toggles can be smaller than the natural size of their contents.
If set to
TRUE
, the toggle labels will ellipsize.See [property`Gtk`.Button:can-shrink].
New in version 1.7.
- Adw.ToggleGroup.props.homogeneous¶
- Name:
homogeneous
- Type:
- Default Value:
- Flags:
Whether all toggles take the same size.
New in version 1.7.
- Adw.ToggleGroup.props.n_toggles¶
-
The number of toggles within the group.
New in version 1.7.
- Adw.ToggleGroup.props.toggles¶
- Name:
toggles
- Type:
- Default Value:
- Flags:
A selection model with the groups’s toggles.
This can be used to keep an up-to-date view. The model also implements [iface`Gtk`.SelectionModel] and can be used to track and change the active toggle.
New in version 1.7.