Adw.TabView

g Adw.TabView Adw.TabView GObject.GInterface GObject.GInterface Gtk.Accessible Gtk.Accessible GObject.GInterface->Gtk.Accessible Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.ConstraintTarget Gtk.ConstraintTarget GObject.GInterface->Gtk.ConstraintTarget GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.Widget Gtk.Widget GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Accessible->Gtk.Widget Gtk.Buildable->Gtk.Widget Gtk.ConstraintTarget->Gtk.Widget Gtk.Widget->Adw.TabView

Subclasses:

None

Methods

Inherited:

Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1)

Structs:

Gtk.WidgetClass (18), GObject.ObjectClass (5)

class

new ()

add_page (child, parent)

add_shortcuts (shortcuts)

append (child)

append_pinned (child)

close_other_pages (page)

close_page (page)

close_page_finish (page, confirm)

close_pages_after (page)

close_pages_before (page)

get_default_icon ()

get_is_transferring_page ()

get_menu_model ()

get_n_pages ()

get_n_pinned_pages ()

get_nth_page (position)

get_page (child)

get_page_position (page)

get_pages ()

get_selected_page ()

get_shortcuts ()

insert (child, position)

insert_pinned (child, position)

invalidate_thumbnails ()

prepend (child)

prepend_pinned (child)

remove_shortcuts (shortcuts)

reorder_backward (page)

reorder_first (page)

reorder_forward (page)

reorder_last (page)

reorder_page (page, position)

select_next_page ()

select_previous_page ()

set_default_icon (default_icon)

set_menu_model (menu_model)

set_page_pinned (page, pinned)

set_selected_page (selected_page)

set_shortcuts (shortcuts)

transfer_page (page, other_view, position)

Virtual Methods

Inherited:

Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9)

Properties

Inherited:

Gtk.Widget (34), Gtk.Accessible (1)

Name

Type

Flags

Short Description

default-icon

Gio.Icon

r/w/en

is-transferring-page

bool

r

menu-model

Gio.MenuModel

r/w/en

n-pages

int

r

n-pinned-pages

int

r

pages

Gtk.SelectionModel

r

selected-page

Adw.TabPage

r/w/en

shortcuts

Adw.TabViewShortcuts

r/w/en

Signals

Inherited:

Gtk.Widget (13), GObject.Object (1)

Name

Short Description

close-page

Emitted after [method`TabView`.close_page] has been called for page.

create-window

Emitted when a tab should be transferred into a new window.

indicator-activated

Emitted after the indicator icon on page has been activated.

page-attached

Emitted when a page has been created or transferred to self.

page-detached

Emitted when a page has been removed or transferred to another view.

page-reordered

Emitted after page has been reordered to position.

setup-menu

Emitted when a context menu is opened or closed for page.

Fields

Inherited:

Gtk.Widget (13), GObject.Object (1)

Class Details

class Adw.TabView(**kwargs)
Bases:

Gtk.Widget

Abstract:

No

Structure:

Adw.TabViewClass

A dynamic tabbed container.

AdwTabView is a container which shows one child at a time. While it provides keyboard shortcuts for switching between pages, it does not provide a visible tab switcher and relies on external widgets for that, such as [class`TabBar`], [class`TabOverview`] and [class`TabButton`].

AdwTabView maintains a [class`TabPage`] object for each page, which holds additional per-page properties. You can obtain the AdwTabPage for a page with [method`TabView`.get_page], and as the return value for [method`TabView`.append] and other functions for adding children.

AdwTabView only aims to be useful for dynamic tabs in multi-window document-based applications, such as web browsers, file managers, text editors or terminals. It does not aim to replace [class`Gtk`.Notebook] for use cases such as tabbed dialogs.

As such, it does not support disabling page reordering or detaching.

AdwTabView adds a number of global page switching and reordering shortcuts. The [property`TabView`:py:data::shortcuts<Adw.TabView.props.shortcuts>] property can be used to manage them.

See [flags`TabViewShortcuts`] for the list of the available shortcuts. All of the shortcuts are enabled by default.

[method`TabView`.add_shortcuts] and [method`TabView`.remove_shortcuts] can be used to manage shortcuts in a convenient way, for example:

``c adw_tab_view_remove_shortcuts (view, ADW_TAB_VIEW_SHORTCUT_CONTROL_HOME |

ADW_TAB_VIEW_SHORTCUT_CONTROL_END);

``

CSS nodes

AdwTabView has a main CSS node with the name tabview.

Accessibility

AdwTabView uses the GTK_ACCESSIBLE_ROLE_TAB_PANEL for the tab pages which are the accessible parent objects of the child widgets.

classmethod new()
Returns:

the newly created AdwTabView

Return type:

Adw.TabView

Creates a new AdwTabView.

add_page(child, parent)
Parameters:
Returns:

the page object representing child

Return type:

Adw.TabPage

Adds child to self with parent as the parent.

This function can be used to automatically position new pages, and to select the correct page when this page is closed while being selected (see [method`TabView`.close_page]).

If parent is NULL, this function is equivalent to [method`TabView`.append].

add_shortcuts(shortcuts)
Parameters:

shortcuts (Adw.TabViewShortcuts) – the shortcuts to add

Adds shortcuts for self.

See [property`TabView`:py:data::shortcuts<Adw.TabView.props.shortcuts>] for details.

New in version 1.2.

append(child)
Parameters:

child (Gtk.Widget) – a widget to add

Returns:

the page object representing child

Return type:

Adw.TabPage

Inserts child as the last non-pinned page.

append_pinned(child)
Parameters:

child (Gtk.Widget) – a widget to add

Returns:

the page object representing child

Return type:

Adw.TabPage

Inserts child as the last pinned page.

close_other_pages(page)
Parameters:

page (Adw.TabPage) – a page of self

Requests to close all pages other than page.

close_page(page)
Parameters:

page (Adw.TabPage) – a page of self

Requests to close page.

Calling this function will result in the [signal`TabView`:py:func:::close-page<Adw.TabView.signals.close_page>] signal being emitted for page. Closing the page can then be confirmed or denied via [method`TabView`.close_page_finish].

If the page is waiting for a [method`TabView`.close_page_finish] call, this function will do nothing.

The default handler for [signal`TabView`:py:func:::close-page<Adw.TabView.signals.close_page>] will immediately confirm closing the page if it’s non-pinned, or reject it if it’s pinned. This behavior can be changed by registering your own handler for that signal.

If page was selected, another page will be selected instead:

If the [property`TabPage`:py:data::parent<Adw.TabView.props.parent>] value is NULL, the next page will be selected when possible, or if the page was already last, the previous page will be selected instead.

If it’s not NULL, the previous page will be selected if it’s a descendant (possibly indirect) of the parent. If both the previous page and the parent are pinned, the parent will be selected instead.

close_page_finish(page, confirm)
Parameters:
  • page (Adw.TabPage) – a page of self

  • confirm (bool) – whether to confirm or deny closing page

Completes a [method`TabView`.close_page] call for page.

If confirm is TRUE, page will be closed. If it’s FALSE, it will be reverted to its previous state and [method`TabView`.close_page] can be called for it again.

This function should not be called unless a custom handler for [signal`TabView`:py:func:::close-page<Adw.TabView.signals.close_page>] is used.

close_pages_after(page)
Parameters:

page (Adw.TabPage) – a page of self

Requests to close all pages after page.

close_pages_before(page)
Parameters:

page (Adw.TabPage) – a page of self

Requests to close all pages before page.

get_default_icon()
Returns:

the default icon of self.

Return type:

Gio.Icon

Gets the default icon of self.

get_is_transferring_page()
Returns:

whether a page is being transferred

Return type:

bool

Whether a page is being transferred.

The corresponding property will be set to TRUE when a drag-n-drop tab transfer starts on any AdwTabView, and to FALSE after it ends.

During the transfer, children cannot receive pointer input and a tab can be safely dropped on the tab view.

get_menu_model()
Returns:

the tab context menu model for self

Return type:

Gio.MenuModel or None

Gets the tab context menu model for self.

get_n_pages()
Returns:

the number of pages in self

Return type:

int

Gets the number of pages in self.

get_n_pinned_pages()
Returns:

the number of pinned pages in self

Return type:

int

Gets the number of pinned pages in self.

See [method`TabView`.set_page_pinned].

get_nth_page(position)
Parameters:

position (int) – the index of the page in self, starting from 0

Returns:

the page object at position

Return type:

Adw.TabPage

Gets the [class`TabPage`] representing the child at position.

get_page(child)
Parameters:

child (Gtk.Widget) – a child in self

Returns:

the page object for child

Return type:

Adw.TabPage

Gets the [class`TabPage`] object representing child.

get_page_position(page)
Parameters:

page (Adw.TabPage) – a page of self

Returns:

the position of page in self

Return type:

int

Finds the position of page in self, starting from 0.

get_pages()
Returns:

a GtkSelectionModel for the pages of self

Return type:

Gtk.SelectionModel

Returns a [iface`Gio`.ListModel] that contains the pages of self.

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 selected page.

get_selected_page()
Returns:

the selected page

Return type:

Adw.TabPage or None

Gets the currently selected page in self.

get_shortcuts()
Returns:

the shortcut mask

Return type:

Adw.TabViewShortcuts

Gets the enabled shortcuts for self.

New in version 1.2.

insert(child, position)
Parameters:
  • child (Gtk.Widget) – a widget to add

  • position (int) – the position to add child at, starting from 0

Returns:

the page object representing child

Return type:

Adw.TabPage

Inserts a non-pinned page at position.

It’s an error to try to insert a page before a pinned page, in that case [method`TabView`.insert_pinned] should be used instead.

insert_pinned(child, position)
Parameters:
  • child (Gtk.Widget) – a widget to add

  • position (int) – the position to add child at, starting from 0

Returns:

the page object representing child

Return type:

Adw.TabPage

Inserts a pinned page at position.

It’s an error to try to insert a pinned page after a non-pinned page, in that case [method`TabView`.insert] should be used instead.

invalidate_thumbnails()

Invalidates thumbnails for all pages in self.

This is a convenience method, equivalent to calling [method`TabPage`.invalidate_thumbnail] on each page.

New in version 1.3.

prepend(child)
Parameters:

child (Gtk.Widget) – a widget to add

Returns:

the page object representing child

Return type:

Adw.TabPage

Inserts child as the first non-pinned page.

prepend_pinned(child)
Parameters:

child (Gtk.Widget) – a widget to add

Returns:

the page object representing child

Return type:

Adw.TabPage

Inserts child as the first pinned page.

remove_shortcuts(shortcuts)
Parameters:

shortcuts (Adw.TabViewShortcuts) – the shortcuts to reomve

Removes shortcuts from self.

See [property`TabView`:py:data::shortcuts<Adw.TabView.props.shortcuts>] for details.

New in version 1.2.

reorder_backward(page)
Parameters:

page (Adw.TabPage) – a page of self

Returns:

whether page was moved

Return type:

bool

Reorders page to before its previous page if possible.

reorder_first(page)
Parameters:

page (Adw.TabPage) – a page of self

Returns:

whether page was moved

Return type:

bool

Reorders page to the first possible position.

reorder_forward(page)
Parameters:

page (Adw.TabPage) – a page of self

Returns:

whether page was moved

Return type:

bool

Reorders page to after its next page if possible.

reorder_last(page)
Parameters:

page (Adw.TabPage) – a page of self

Returns:

whether page was moved

Return type:

bool

Reorders page to the last possible position.

reorder_page(page, position)
Parameters:
  • page (Adw.TabPage) – a page of self

  • position (int) – the position to insert the page at, starting at 0

Returns:

whether page was moved

Return type:

bool

Reorders page to position.

It’s a programmer error to try to reorder a pinned page after a non-pinned one, or a non-pinned page before a pinned one.

select_next_page()
Returns:

whether the selected page was changed

Return type:

bool

Selects the page after the currently selected page.

If the last page was already selected, this function does nothing.

select_previous_page()
Returns:

whether the selected page was changed

Return type:

bool

Selects the page before the currently selected page.

If the first page was already selected, this function does nothing.

set_default_icon(default_icon)
Parameters:

default_icon (Gio.Icon) – the default icon

Sets the default page icon for self.

If a page doesn’t provide its own icon via [property`TabPage`:py:data::icon<Adw.TabView.props.icon>], a default icon may be used instead for contexts where having an icon is necessary.

[class`TabBar`] will use default icon for pinned tabs in case the page is not loading, doesn’t have an icon and an indicator. Default icon is never used for tabs that aren’t pinned.

[class`TabOverview`] will use default icon for pages with missing thumbnails.

By default, the adw-tab-icon-missing-symbolic icon is used.

set_menu_model(menu_model)
Parameters:

menu_model (Gio.MenuModel or None) – a menu model

Sets the tab context menu model for self.

When a context menu is shown for a tab, it will be constructed from the provided menu model. Use the [signal`TabView`:py:func:::setup-menu<Adw.TabView.signals.setup_menu>] signal to set up the menu actions for the particular tab.

set_page_pinned(page, pinned)
Parameters:
  • page (Adw.TabPage) – a page of self

  • pinned (bool) – whether page should be pinned

Pins or unpins page.

Pinned pages are guaranteed to be placed before all non-pinned pages; at any given moment the first [property`TabView`:py:data::n-pinned-pages<Adw.TabView.props.n_pinned_pages>] pages in self are guaranteed to be pinned.

When a page is pinned or unpinned, it’s automatically reordered: pinning a page moves it after other pinned pages; unpinning a page moves it before other non-pinned pages.

Pinned pages can still be reordered between each other.

[class`TabBar`] will display pinned pages in a compact form, never showing the title or close button, and only showing a single icon, selected in the following order:

[property`TabPage`:py:data::indicator-icon<Adw.TabView.props.indicator_icon>]

A spinner if [property`TabPage`:py:data::loading<Adw.TabView.props.loading>] is TRUE

[property`TabPage`:py:data::icon<Adw.TabView.props.icon>]

[property`TabView`:py:data::default-icon<Adw.TabView.props.default_icon>]

[class`TabOverview`] will not show a thumbnail for pinned pages, and replace the close button with an unpin button. Unlike AdwTabBar, it will still display the page’s title, icon and indicator separately.

Pinned pages cannot be closed by default, see [signal`TabView`:py:func:::close-page<Adw.TabView.signals.close_page>] for how to override that behavior.

Changes the value of the [property`TabPage`:py:data::pinned<Adw.TabView.props.pinned>] property.

set_selected_page(selected_page)
Parameters:

selected_page (Adw.TabPage) – a page in self

Sets the currently selected page in self.

set_shortcuts(shortcuts)
Parameters:

shortcuts (Adw.TabViewShortcuts) – the new shortcuts

Sets the enabled shortcuts for self.

See [flags`TabViewShortcuts`] for the list of the available shortcuts. All of the shortcuts are enabled by default.

[method`TabView`.add_shortcuts] and [method`TabView`.remove_shortcuts] provide a convenient way to manage individual shortcuts.

New in version 1.2.

transfer_page(page, other_view, position)
Parameters:
  • page (Adw.TabPage) – a page of self

  • other_view (Adw.TabView) – the tab view to transfer the page to

  • position (int) – the position to insert the page at, starting at 0

Transfers page from self to other_view.

The page object will be reused.

It’s a programmer error to try to insert a pinned page after a non-pinned one, or a non-pinned page before a pinned one.

Signal Details

Adw.TabView.signals.close_page(tab_view, page)
Signal Name:

close-page

Flags:

RUN_LAST

Parameters:
Returns:

whether propagation should be stopped

Return type:

bool

Emitted after [method`TabView`.close_page] has been called for page.

The handler is expected to call [method`TabView`.close_page_finish] to confirm or reject the closing.

The default handler will immediately confirm closing for non-pinned pages, or reject it for pinned pages, equivalent to the following example:

```c static bool close_page_cb (Adw.TabView *view, Adw.TabPage *page, object user_data) { Adw.TabView.close_page_finish (view, page, !:obj:Adw.TabPage.get_pinned (page));

return Gdk.EVENT_STOP; } ```

The [method`TabView`.close_page_finish] call doesn’t have to happen inside the handler, so can be used to do asynchronous checks before confirming the closing.

A typical reason to connect to this signal is to show a confirmation dialog for closing a tab.

The signal handler should return GDK_EVENT_STOP to stop propagation or GDK_EVENT_CONTINUE to invoke the default handler.

Adw.TabView.signals.create_window(tab_view)
Signal Name:

create-window

Flags:

RUN_LAST

Parameters:

tab_view (Adw.TabView) – The object which received the signal

Returns:

the AdwTabView from the new window

Return type:

Adw.TabView or None

Emitted when a tab should be transferred into a new window.

This can happen after a tab has been dropped on desktop.

The signal handler is expected to create a new window, position it as needed and return its AdwTabView that the page will be transferred into.

Adw.TabView.signals.indicator_activated(tab_view, page)
Signal Name:

indicator-activated

Flags:

RUN_LAST

Parameters:

Emitted after the indicator icon on page has been activated.

See [property`TabPage`:py:data::indicator-icon<Adw.TabView.props.indicator_icon>] and [property`TabPage`:py:data::indicator-activatable<Adw.TabView.props.indicator_activatable>].

Adw.TabView.signals.page_attached(tab_view, page, position)
Signal Name:

page-attached

Flags:

RUN_LAST

Parameters:
  • tab_view (Adw.TabView) – The object which received the signal

  • page (Adw.TabPage) – a page of self

  • position (int) – the position of the page, starting from 0

Emitted when a page has been created or transferred to self.

A typical reason to connect to this signal would be to connect to page signals for things such as updating window title.

Adw.TabView.signals.page_detached(tab_view, page, position)
Signal Name:

page-detached

Flags:

RUN_LAST

Parameters:
  • tab_view (Adw.TabView) – The object which received the signal

  • page (Adw.TabPage) – a page of self

  • position (int) – the position of the removed page, starting from 0

Emitted when a page has been removed or transferred to another view.

A typical reason to connect to this signal would be to disconnect signal handlers connected in the [signal`TabView`:py:func:::page-attached<Adw.TabView.signals.page_attached>] handler.

It is important not to try and destroy the page child in the handler of this function as the child might merely be moved to another window; use child dispose handler for that or do it in sync with your [method`TabView`.close_page_finish] calls.

Adw.TabView.signals.page_reordered(tab_view, page, position)
Signal Name:

page-reordered

Flags:

RUN_LAST

Parameters:
  • tab_view (Adw.TabView) – The object which received the signal

  • page (Adw.TabPage) – a page of self

  • position (int) – the position page was moved to, starting at 0

Emitted after page has been reordered to position.

Adw.TabView.signals.setup_menu(tab_view, page)
Signal Name:

setup-menu

Flags:

RUN_LAST

Parameters:

Emitted when a context menu is opened or closed for page.

If the menu has been closed, page will be set to NULL.

It can be used to set up menu actions before showing the menu, for example disable actions not applicable to page.

Property Details

Adw.TabView.props.default_icon
Name:

default-icon

Type:

Gio.Icon

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Default page icon.

If a page doesn’t provide its own icon via [property`TabPage`:py:data::icon<Adw.TabView.props.icon>], a default icon may be used instead for contexts where having an icon is necessary.

[class`TabBar`] will use default icon for pinned tabs in case the page is not loading, doesn’t have an icon and an indicator. Default icon is never used for tabs that aren’t pinned.

[class`TabOverview`] will use default icon for pages with missing thumbnails.

By default, the adw-tab-icon-missing-symbolic icon is used.

Adw.TabView.props.is_transferring_page
Name:

is-transferring-page

Type:

bool

Default Value:

False

Flags:

READABLE

Whether a page is being transferred.

This property will be set to TRUE when a drag-n-drop tab transfer starts on any AdwTabView, and to FALSE after it ends.

During the transfer, children cannot receive pointer input and a tab can be safely dropped on the tab view.

Adw.TabView.props.menu_model
Name:

menu-model

Type:

Gio.MenuModel

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Tab context menu model.

When a context menu is shown for a tab, it will be constructed from the provided menu model. Use the [signal`TabView`:py:func:::setup-menu<Adw.TabView.signals.setup_menu>] signal to set up the menu actions for the particular tab.

Adw.TabView.props.n_pages
Name:

n-pages

Type:

int

Default Value:

0

Flags:

READABLE

The number of pages in the tab view.

Adw.TabView.props.n_pinned_pages
Name:

n-pinned-pages

Type:

int

Default Value:

0

Flags:

READABLE

The number of pinned pages in the tab view.

See [method`TabView`.set_page_pinned].

Adw.TabView.props.pages
Name:

pages

Type:

Gtk.SelectionModel

Default Value:

None

Flags:

READABLE

A selection model with the tab view’s pages.

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 selected page.

Adw.TabView.props.selected_page
Name:

selected-page

Type:

Adw.TabPage

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The currently selected page.

Adw.TabView.props.shortcuts
Name:

shortcuts

Type:

Adw.TabViewShortcuts

Default Value:

Adw.TabViewShortcuts.CONTROL_TAB | Adw.TabViewShortcuts.CONTROL_SHIFT_TAB | Adw.TabViewShortcuts.CONTROL_PAGE_UP | Adw.TabViewShortcuts.CONTROL_PAGE_DOWN | Adw.TabViewShortcuts.CONTROL_HOME | Adw.TabViewShortcuts.CONTROL_END | Adw.TabViewShortcuts.CONTROL_SHIFT_PAGE_UP | Adw.TabViewShortcuts.CONTROL_SHIFT_PAGE_DOWN | Adw.TabViewShortcuts.CONTROL_SHIFT_HOME | Adw.TabViewShortcuts.CONTROL_SHIFT_END | Adw.TabViewShortcuts.ALT_DIGITS | Adw.TabViewShortcuts.ALT_ZERO | Adw.TabViewShortcuts.ALL_SHORTCUTS

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The enabled shortcuts.

See [flags`TabViewShortcuts`] for the list of the available shortcuts. All of the shortcuts are enabled by default.

[method`TabView`.add_shortcuts] and [method`TabView`.remove_shortcuts] provide a convenient way to manage individual shortcuts.

New in version 1.2.