ViewStack#

class ViewStack(**properties: Any)#

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#

class ViewStack
classmethod new() Widget#

Creates a new AdwViewStack.

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. The title will be used by ViewSwitcher to represent child, so it should be short.

Parameters:
  • child – the widget to add

  • name – the name for child

  • title – 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. The title and icon_name will be used by ViewSwitcher to represent child.

Added in version 1.2.

Parameters:
  • child – the widget to add

  • name – the name for child

  • title – a human-readable title for child

  • icon_name – an icon name for child

get_child_by_name(name: str) Widget | None#

Finds the child with name in self.

Parameters:

name – the name of the child to find

get_enable_transitions() bool#

Gets whether self uses a crossfade transition between pages.

Use transition_duration to control the duration, and transition_running to know when the transition is running.

Added in version 1.7.

get_hhomogeneous() bool#

Gets whether self is horizontally homogeneous.

get_page(child: Widget) ViewStackPage#

Gets the ViewStackPage object for child.

Parameters:

child – a child of self

get_pages() SelectionModel#

Returns a ListModel that contains the pages of the stack.

This can be used to keep an up-to-date view.

The model implements SectionModel and creates sections based on starts_section values.

The model also implements SelectionModel and 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 TRUE and then immediately to FALSE, so it’s possible to rely on its notifications to know that a transition has happened.

Added in version 1.7.

get_vhomogeneous() bool#

Gets whether self is vertically homogeneous.

get_visible_child() Widget | None#

Gets the currently visible child of self.

get_visible_child_name() str | None#

Returns the name of the currently visible child of self.

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 self uses a crossfade transition between pages.

Added in version 1.7.

Parameters:

enable_transitions – whether to enable page transitions

set_hhomogeneous(hhomogeneous: bool) None#

Sets self to 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 self horizontally homogeneous

set_transition_duration(duration: int) None#

Sets the transition animation duration for self.

Only used when enable_transitions is set to TRUE.

Added in version 1.7.

Parameters:

duration – the new duration, in milliseconds

set_vhomogeneous(vhomogeneous: bool) None#

Sets self to 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 self vertically homogeneous

set_visible_child(child: Widget) None#

Makes child the visible child of self.

Parameters:

child – a child of self

set_visible_child_name(name: str) None#

Makes the child with name visible.

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_duration to control the duration, and transition_running to 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 SectionModel and creates sections based on starts_section values.

The model also implements SelectionModel and can be used to track and change the visible page.

props.transition_duration: int#

The transition animation duration, in milliseconds.

Only used when enable_transitions is set to TRUE.

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 TRUE and then immediately to FALSE, 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: Widget#

The widget currently visible in the stack.

props.visible_child_name: str#

The name of the widget currently visible in the stack.

See visible_child.