SidebarSection#
Added in version 1.9.
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:
Constructors#
- class SidebarSection
- classmethod new() → SidebarSection#
Creates a new
AdwSidebarSection.Added in version 1.9.
Methods#
- class SidebarSection
- append(item: SidebarItem) → None#
Appends
itemtoself.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
modeltoself.If
selfwas already bound to a model, that previous binding is destroyed.The contents of
selfare cleared and then filled with items that represent items frommodel.selfis updated whenevermodelchanges.If
modelisNULL,selfis left empty.Calling
prepend,insert,append,removeorremove_allwhile 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
SidebarItemfor model items, orNULLin casemodelis alsoNULLuser_data – user data passed to
create_widget_func
- get_item(index: int) → SidebarItem | None#
Gets the item at
indexwithinself.The index starts from 0 at the top of the section, and is same as the one returned by
get_section_index.Can return
NULLifindexis 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.
- insert(item: SidebarItem, position: int) → None#
Inserts
itematpositiontoself.If
positionis -1, or larger than the total number of items inself, 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
itemat
- prepend(item: SidebarItem) → None#
Prepends
itemtoself.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
itemfromself.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_menusignal to set up the menu actions for the particular item.If not set,
menu_modelwill be used instead.Added in version 1.9.
- Parameters:
menu_model – a menu model
Properties#
- class SidebarSection