ToggleGroup#
Added in version 1.7.
Superclasses: Widget, InitiallyUnowned, Object
Implemented Interfaces: Accessible, Buildable, ConstraintTarget, Orientable
A group of exclusive toggles.
AdwToggleGroup presents a set of exclusive toggles, represented as
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 active to get that position.
Toggles can also have optional names, set via the name
property. The name of the active toggle can be accessed via the
active_name property.
AdwToggle objects can be retrieved via their index or name, using
get_toggle or get_toggle_by_name
respectively. AdwToggleGroup also provides a SelectionModel of
its toggles via the toggles property.
AdwToggleGroup is orientable, and the toggles can be displayed horizontally
or vertically. This is mostly useful for icon-only toggles.
Use the homogeneous property to make the toggles take
the same size, and the can_shrink to control whether
the toggles can ellipsize.
Example of an AdwToggleGroup UI definition:
<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: InlineViewSwitcher.
CSS nodes#
AdwToggleGroup has a main CSS node with the name toggle-group.
Its toggles have CSS nodes with the name toggle, and its separators have nodes
with the name separator.
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-classes.html#flat_1>`__ style class
to remove its background and make it look like a group of buttons.
It can also use the `.round <style-classes.html#round>`__ style class to make
its toggles and the group itself rounded.
They can also be combined with each other.
Accessibility#
AdwToggleGroup uses the radio-group role. Its
toggles use the radio role.
Constructors#
Methods#
- class ToggleGroup
- add(toggle: Toggle) None#
Adds a toggle to
self.Added in version 1.7.
- Parameters:
toggle – the toggle to add
- get_active() int#
Gets the index of the active toggle in
self.Returns
INVALID_LIST_POSITIONif no toggle is active.Added in version 1.7.
- get_active_name() str | None#
Gets the name of the active toggle in
self.Can be
NULLif the currently active toggle doesn’t have a name.See
name.Added in version 1.7.
- get_can_shrink() bool#
Gets whether the toggles can be smaller than the natural size of their contents.
Added in version 1.7.
- get_toggle(index: int) Toggle | None#
Gets the toggle with
indexfromself.Added in version 1.7.
- Parameters:
index – toggle’s index
- get_toggle_by_name(name: str) Toggle | None#
Gets the toggle with the name
namefromself.Added in version 1.7.
- Parameters:
name – toggle name
- get_toggles() SelectionModel#
Returns a
ListModelthat contains the toggles of the group.This can be used to keep an up-to-date view. The model also implements
SelectionModeland can be used to track and change the active toggle.
- remove(toggle: Toggle) None#
Removes
togglefromself.Added in version 1.7.
- Parameters:
toggle – a toggle to remove
- set_active(active: int) None#
Sets the active toggle for
self.If the index is larger than the number of toggles in
self, unsets the current active toggle.Added in version 1.7.
- Parameters:
active – toggle index
- set_active_name(name: str | None = None) None#
Sets the active toggle for
self.The name can be set via
name.If
nameisNULL, unset the current active toggle instead.Added in version 1.7.
- Parameters:
name – toggle name
- set_can_shrink(can_shrink: bool) None#
Sets whether the toggles can be smaller than the natural size of their contents.
If
can_shrinkisTRUE, the toggle labels will ellipsize.See
can_shrink.Added in version 1.7.
- Parameters:
can_shrink – whether the toggles can shrink
Properties#
- class ToggleGroup
-
- props.toggles: SelectionModel#
The type of the None singleton.
Added in version 1.7.