Adw.SidebarSection

g Adw.SidebarSection Adw.SidebarSection GObject.GInterface GObject.GInterface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable GObject.Object GObject.Object GObject.Object->Adw.SidebarSection Gtk.Buildable->Adw.SidebarSection

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gtk.Buildable (1)

Structs:

GObject.ObjectClass (5)

class

new ()

append (item)

bind_model (model, create_item_func, *user_data)

get_item (index)

get_items ()

get_menu_model ()

get_sidebar ()

get_title ()

insert (item, position)

prepend (item)

remove (item)

remove_all ()

set_menu_model (menu_model)

set_title (title)

Virtual Methods

Inherited:

GObject.Object (7), Gtk.Buildable (9)

Properties

Name

Type

Flags

Short Description

items

Gio.ListModel

r

menu-model

Gio.MenuModel

r/w/en

sidebar

Adw.Sidebar

r

title

str

r/w/en

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Adw.SidebarSection(**kwargs)
Bases:

GObject.Object, Gtk.Buildable

Abstract:

No

Structure:

Adw.SidebarSectionClass

A section within [class`Sidebar`].

AdwSidebarSection contains [class`SidebarItem`] objects.

Section can optionally have a title, set with the [property`SidebarSection`:py:data::title<Adw.SidebarSection.props.title>] property. If a title is not set, the section will have a separator in front of it, or just spacing in the [enum`Adw`.SidebarMode.page] mode.

To add items, use [method`SidebarSection`.append], [method`SidebarSection`.prepend] or [method`SidebarSection`.insert].

To remove items, use [method`SidebarSection`.remove] or [method`SidebarSection`.remove_all].

To inspect the items, use [method`SidebarSection`.get_item] or [property`SidebarSection`:py:data::items<Adw.SidebarSection.props.items>].

To get the sidebar the section is in, use[property`SidebarSection`:py:data::sidebar<Adw.SidebarSection.props.sidebar>].

Binding models

AdwSidebarSection can show items from a provided [iface`Gio`.ListModel], using [method`SidebarSection`.bind_model]. It works the same way as [method`Gtk`.ListBox.bind_model], except the provided function creates an [class`SidebarItem`] rather than a [class`Gtk`.ListBoxRow].

While a model is bound, adding or removing items manually is not allowed. Inspecting them is still allowed, but discouraged.

Adw.SidebarSection as Gtk.Buildable

AdwSidebarSection allows adding items as children.

Example of an AdwSidebarSection UI definition:

``xml <object class=”AdwSidebarSection”>

<property name=”title” translatable=”yes”>Places</property> <child>

<object class=”AdwSidebarItem”>

<property name=”title” translatable=”yes”>Music</property> <property name=”icon-name”>folder-music-symbolic</property>

</object>

</child> <child>

<object class=”AdwSidebarItem”>

<property name=”title” translatable=”yes”>Pictures</property> <property name=”icon-name”>folder-pictures-symbolic</property>

</object>

</child> <child>

<object class=”AdwSidebarItem”>

<property name=”title” translatable=”yes”>Videos</property> <property name=”icon-name”>folder-videos-symbolic</property>

</object>

</child>

</object> ``

Result:

<picture> <source srcset=”sidebar-section-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”sidebar-section.png” alt=”sidebar-section”> </picture>

New in version 1.9.

classmethod new()
Returns:

the newly created AdwSidebarSection

Return type:

Adw.SidebarSection

Creates a new AdwSidebarSection.

New in version 1.9.

append(item)
Parameters:

item (Adw.SidebarItem) – an item to append

Appends item to self.

Cannot be used while a model is bound via [method`SidebarSection`.bind_model].

New in version 1.9.

bind_model(model, create_item_func, *user_data)
Parameters:

Binds model to self.

If self was already bound to a model, that previous binding is destroyed.

The contents of self are cleared and then filled with items that represent items from model. self is updated whenever model changes.

If model is NULL, self is left empty.

Calling [method`SidebarSection`.prepend], [method`SidebarSection`.insert], [method`SidebarSection`.append], [method`SidebarSection`.remove] or [method`SidebarSection`.remove_all] while a model is bound is not allowed.

Accessing items and modifying them is allowed, but the changes will be erased whenever that part of the model changes, so it’s not recommended.

New in version 1.9.

get_item(index)
Parameters:

index (int) – index of the item

Returns:

the item at index

Return type:

Adw.SidebarItem or None

Gets the item at index within self.

The index starts from 0 at the top of the section, and is same as the one returned by [method`SidebarItem`.get_section_index].

Can return NULL if index is larger or equal to the number of items.

New in version 1.9.

get_items()
Returns:

a model containing the items

Return type:

Gio.ListModel

Gets a list model with self's items.

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

New in version 1.9.

get_menu_model()
Returns:

the context menu model

Return type:

Gio.MenuModel or None

Gets the context menu model for self's items.

New in version 1.9.

get_sidebar()
Returns:

the sidebar of self

Return type:

Adw.Sidebar or None

Gets the sidebar self is in.

New in version 1.9.

get_title()
Returns:

the title

Return type:

str or None

Gets the title of self.

New in version 1.9.

insert(item, position)
Parameters:
  • item (Adw.SidebarItem) – an item to insert

  • position (int) – position to insert item at

Inserts item at position to self.

If position is -1, or larger than the total number of items in self, the item will be appended to the end.

Cannot be used while a model is bound via [method`SidebarSection`.bind_model].

New in version 1.9.

prepend(item)
Parameters:

item (Adw.SidebarItem) – an item to prepend

Prepends item to self.

Cannot be used while a model is bound via [method`SidebarSection`.bind_model].

New in version 1.9.

remove(item)
Parameters:

item (Adw.SidebarItem) – an item to remove

Removes item from self.

Cannot be used while a model is bound via [method`SidebarSection`.bind_model].

New in version 1.9.

remove_all()

Removes all items from self.

Cannot be used while a model is bound via [method`SidebarSection`.bind_model].

New in version 1.9.

set_menu_model(menu_model)
Parameters:

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

Sets the context menu model for self's items.

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

If not set, [property`Sidebar`:py:data::menu-model<Adw.SidebarSection.props.menu_model>] will be used instead.

New in version 1.9.

set_title(title)
Parameters:

title (str or None) – the title

Sets the title of self.

If set, it will be displayed instead of the separator before the section.

New in version 1.9.

Property Details

Adw.SidebarSection.props.items
Name:

items

Type:

Gio.ListModel

Default Value:

None

Flags:

READABLE

A list model with the section’s items.

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

New in version 1.9.

Adw.SidebarSection.props.menu_model
Name:

menu-model

Type:

Gio.MenuModel

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Context menu model for the section items.

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

If not set, [property`Sidebar`:py:data::menu-model<Adw.SidebarSection.props.menu_model>] will be used instead.

New in version 1.9.

Adw.SidebarSection.props.sidebar
Name:

sidebar

Type:

Adw.Sidebar

Default Value:

None

Flags:

READABLE

The sidebar the section is in.

New in version 1.9.

Adw.SidebarSection.props.title
Name:

title

Type:

str

Default Value:

''

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Title of the section.

If set, it will be displayed instead of the separator before the section.

New in version 1.9.