SidebarSection#

Added in version 1.9.

class SidebarSection(**properties: Any)#

Superclasses: Object

Implemented Interfaces: Buildable

A section within Sidebar.

AdwSidebarSection contains SidebarItem objects.

Section can optionally have a title, set with the title property. If a title is not set, the section will have a separator in front of it, or just spacing in the page mode.

To add items, use append, prepend or insert.

To remove items, use remove or remove_all.

To inspect the items, use get_item or items.

To get the sidebar the section is in, use:obj:sidebar.

Binding models#

AdwSidebarSection can show items from a provided ListModel, using bind_model. It works the same way as bind_model, except the provided function creates an SidebarItem rather than a ListBoxRow.

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


AdwSidebarSection allows adding items as children.

Example of an AdwSidebarSection UI definition:

<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:

https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1-latest/sidebar-section.png

Constructors#

class SidebarSection
classmethod new() SidebarSection#

Creates a new AdwSidebarSection.

Added in version 1.9.

Methods#

class SidebarSection
append(item: SidebarItem) None#

Appends item to self.

Cannot be used while a model is bound via bind_model.

Added in version 1.9.

Parameters:

item – an item to append

bind_model(model: ListModel | None = None, create_item_func: Callable[[Object, Any], SidebarItem] | None = None, user_data: Any = None) None#

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 prepend, insert, append, remove or 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.

Added in version 1.9.

Parameters:
  • model – the model to be bound

  • create_item_func – a function that creates SidebarItem for model items, or NULL in case model is also NULL

  • user_data – user data passed to create_widget_func

get_item(index: int) SidebarItem | 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 get_section_index.

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

Added in version 1.9.

Parameters:

index – index of the item

get_items() ListModel#

Gets a list model with self's items.

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

Added in version 1.9.

get_menu_model() MenuModel | None#

Gets the context menu model for self's items.

Added in version 1.9.

get_sidebar() Sidebar | None#

Gets the sidebar self is in.

Added in version 1.9.

get_title() str | None#

Gets the title of self.

Added in version 1.9.

insert(item: SidebarItem, position: int) None#

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 bind_model.

Added in version 1.9.

Parameters:
  • item – an item to insert

  • position – position to insert item at

prepend(item: SidebarItem) None#

Prepends item to self.

Cannot be used while a model is bound via bind_model.

Added in version 1.9.

Parameters:

item – an item to prepend

remove(item: SidebarItem) None#

Removes item from self.

Cannot be used while a model is bound via bind_model.

Added in version 1.9.

Parameters:

item – an item to remove

remove_all() None#

Removes all items from self.

Cannot be used while a model is bound via bind_model.

Added in version 1.9.

set_menu_model(menu_model: MenuModel | None = None) None#

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 setup_menu signal to set up the menu actions for the particular item.

If not set, menu_model will be used instead.

Added in version 1.9.

Parameters:

menu_model – a menu model

set_title(title: str | None = None) None#

Sets the title of self.

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

Added in version 1.9.

Parameters:

title – the title

Properties#

class SidebarSection
props.items: ListModel#

The type of the None singleton.

Added in version 1.9.

props.menu_model: MenuModel#

The type of the None singleton.

Added in version 1.9.

props.sidebar: Sidebar#

The type of the None singleton.

Added in version 1.9.

props.title: str#

The type of the None singleton.

Added in version 1.9.