ViewStack#
Superclasses: Widget, InitiallyUnowned, Object
Implemented Interfaces: Accessible, Buildable, ConstraintTarget
A view container for ViewSwitcher.
AdwViewStack is a container which only shows one page at a time.
It is typically used to hold an application’s main views.
It doesn’t provide a way to transition between pages.
Instead, a separate widget such as ViewSwitcher,
InlineViewSwitcher or ViewSwitcherSidebar can be used with
AdwViewStack to provide this functionality.
AdwViewStack pages can have a title, an icon, an attention request, and a
numbered badge that ViewSwitcher will use to let users identify which
page is which. Set them using the title,
icon_name,
needs_attention, and
badge_number properties.
AdwViewStack pages can also be grouped into sections, using the
starts_section and
section_title properties. Currently, only
ViewSwitcherSidebar displays groups.
Unlike Stack, transitions between views can only be animated via
a crossfade and size changes are always interpolated. Animations are disabled
by default. Use enable_transitions to enable them.
AdwViewStack maintains a ViewStackPage object for each added child,
which holds additional per-child properties. You obtain the
ViewStackPage for a child with get_page and you
can obtain a SelectionModel containing all the pages with
get_pages.
AdwViewStack as GtkBuildable#
To set child-specific properties in a .ui file, create
ViewStackPage objects explicitly, and set the child widget as a
property on it:
<object class="AdwViewStack" id="stack">
<child>
<object class="AdwViewStackPage">
<property name="name">overview</property>
<property name="title">Overview</property>
<property name="child">
<object class="AdwStatusPage">
<property name="title">Welcome!</property>
</object>
</property>
</object>
</child>
</object>
CSS nodes#
AdwViewStack has a single CSS node named stack.
Accessibility#
AdwViewStack uses the tab-panel for the stack
pages which are the accessible parent objects of the child widgets.
Constructors#
Methods#
- class ViewStack
- add(child: Widget) ViewStackPage#
Adds a child to
self.- Parameters:
child – the widget to add
- add_named(child: Widget, name: str | None = None) ViewStackPage#
Adds a child to
self.The child is identified by the
name.- Parameters:
child – the widget to add
name – the name for
child
- add_titled(child: Widget, name: str | None, title: str) ViewStackPage#
Adds a child to
self.The child is identified by the
name. Thetitlewill be used byViewSwitcherto representchild, so it should be short.- Parameters:
child – the widget to add
name – the name for
childtitle – a human-readable title for
child
- add_titled_with_icon(child: Widget, name: str | None, title: str, icon_name: str) ViewStackPage#
Adds a child to
self.The child is identified by the
name. Thetitleandicon_namewill be used byViewSwitcherto representchild.Added in version 1.2.
- Parameters:
child – the widget to add
name – the name for
childtitle – a human-readable title for
childicon_name – an icon name for
child
- get_child_by_name(name: str) Widget | None#
Finds the child with
nameinself.- Parameters:
name – the name of the child to find
- get_enable_transitions() bool#
Gets whether
selfuses a crossfade transition between pages.Use
transition_durationto control the duration, andtransition_runningto know when the transition is running.Added in version 1.7.
- get_page(child: Widget) ViewStackPage#
Gets the
ViewStackPageobject forchild.- Parameters:
child – a child of
self
- get_pages() SelectionModel#
Returns a
ListModelthat contains the pages of the stack.This can be used to keep an up-to-date view.
The model implements
SectionModeland creates sections based onstarts_sectionvalues.The model also implements
SelectionModeland can be used to track and change the visible page.
- get_transition_duration() int#
Gets the transition animation duration for
self.Added in version 1.7.
- get_transition_running() bool#
Gets whether a transition is currently running for
self.If a transition is impossible, the property value will be set to
TRUEand then immediately toFALSE, so it’s possible to rely on its notifications to know that a transition has happened.Added in version 1.7.
- remove(child: Widget) None#
Removes a child widget from
self.- Parameters:
child – the child to remove
- set_enable_transitions(enable_transitions: bool) None#
Sets whether
selfuses a crossfade transition between pages.Added in version 1.7.
- Parameters:
enable_transitions – whether to enable page transitions
- set_hhomogeneous(hhomogeneous: bool) None#
Sets
selfto be horizontally homogeneous or not.If the stack is horizontally homogeneous, it allocates the same width for all children.
If it’s
FALSE, the stack may change width when a different child becomes visible.- Parameters:
hhomogeneous – whether to make
selfhorizontally homogeneous
- set_transition_duration(duration: int) None#
Sets the transition animation duration for
self.Only used when
enable_transitionsis set toTRUE.Added in version 1.7.
- Parameters:
duration – the new duration, in milliseconds
- set_vhomogeneous(vhomogeneous: bool) None#
Sets
selfto be vertically homogeneous or not.If the stack is vertically homogeneous, it allocates the same height for all children.
If it’s
FALSE, the stack may change height when a different child becomes visible.- Parameters:
vhomogeneous – whether to make
selfvertically homogeneous
- set_visible_child(child: Widget) None#
Makes
childthe visible child ofself.- Parameters:
child – a child of
self
- set_visible_child_name(name: str) None#
Makes the child with
namevisible.See
visible_child.- Parameters:
name – the name of the child
Properties#
- class ViewStack
- props.enable_transitions: bool#
Whether the stack uses a crossfade transition between pages.
Use
transition_durationto control the duration, andtransition_runningto know when the transition is running.Added in version 1.7.
- props.hhomogeneous: bool#
Whether the stack is horizontally homogeneous.
If the stack is horizontally homogeneous, it allocates the same width for all children.
If it’s
FALSE, the stack may change width when a different child becomes visible.
- props.pages: SelectionModel#
A selection model with the stack’s pages.
This can be used to keep an up-to-date view.
The model implements
SectionModeland creates sections based onstarts_sectionvalues.The model also implements
SelectionModeland can be used to track and change the visible page.
- props.transition_duration: int#
The transition animation duration, in milliseconds.
Only used when
enable_transitionsis set toTRUE.Added in version 1.7.
- props.transition_running: bool#
Whether a transition is currently running.
If a transition is impossible, the property value will be set to
TRUEand then immediately toFALSE, so it’s possible to rely on its notifications to know that a transition has happened.Added in version 1.7.
- props.vhomogeneous: bool#
Whether the stack is vertically homogeneous.
If the stack is vertically homogeneous, it allocates the same height for all children.
If it’s
FALSE, the stack may change height when a different child becomes visible.
- props.visible_child_name: str#
The name of the widget currently visible in the stack.
See
visible_child.