Adw.SidebarSection¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
Name |
Type |
Flags |
Short Description |
|---|---|---|---|
r |
|||
r/w/en |
|||
r |
|||
r/w/en |
Signals¶
- Inherited:
Fields¶
- Inherited:
Class Details¶
- class Adw.SidebarSection(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
A section within [class`Sidebar`].
AdwSidebarSectioncontains [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
AdwSidebarSectioncan 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.
AdwSidebarSectionallows adding items as children.Example of an
AdwSidebarSectionUI 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:
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:
model (
Gio.ListModelorNone) – the model to be boundcreate_item_func (
Adw.SidebarSectionCreateItemFuncorNone) – a function that creates [class`SidebarItem`] for model items, orNULLin case model is alsoNULLuser_data (
objectorNone) – user data passed to create_widget_func
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:
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
NULLif 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:
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:
Gets the context menu model for self's items.
New in version 1.9.
- get_sidebar()¶
- Returns:
the sidebar of self
- Return type:
Adw.SidebarorNone
Gets the sidebar self is in.
New in version 1.9.
- get_title()¶
-
Gets the title of self.
New in version 1.9.
- insert(item, position)¶
- Parameters:
item (
Adw.SidebarItem) – an item to insertposition (
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.MenuModelorNone) – 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.
Property Details¶
- Adw.SidebarSection.props.items¶
- Name:
items- Type:
- Default Value:
- Flags:
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:
- Default Value:
- Flags:
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:
- Default Value:
- Flags:
The sidebar the section is in.
New in version 1.9.
- Adw.SidebarSection.props.title¶
- Name:
title- Type:
- Default Value:
''- Flags:
Title of the section.
If set, it will be displayed instead of the separator before the section.
New in version 1.9.