Adw.Sidebar¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Widget (183), GObject.Object (37), Gtk.Accessible (18), Gtk.Buildable (1)
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (7), Gtk.Buildable (9)
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
|---|---|---|---|
r/w/en |
|||
r/w/en |
|||
r |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r |
|||
r/w/en |
|||
r |
Signals¶
- Inherited:
Name |
Short Description |
|---|---|
Emitted when an item at index has been activated. |
|
Emitted when content is dropped onto the item at index. |
|
Emitted when the pointer enters the item at index. |
|
Emitted when the dropped content is preloaded for the item at index. |
|
Emitted when a context menu is opened or closed for item. |
Fields¶
- Inherited:
Class Details¶
- class Adw.Sidebar(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Adaptive sidebar widget.
<picture> <source srcset=”sidebar-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”sidebar.png” alt=”sidebar”> </picture>
AdwSidebarcontains [class`SidebarSection`] objects, which in turn contain [class`SidebarItem`] objects.To add sections, use [method`Sidebar`.append], [method`Sidebar`.prepend] or [method`Sidebar`.insert].
To remove sections, use [method`Sidebar`.remove] or [method`Sidebar`.remove_all].
To inspect the items, use [method`Sidebar`.get_item] or [property`Sidebar`:py:data::items<Adw.Sidebar.props.items>].
To inspect sections themselves, use [method`Sidebar`.get_section] or [property`Sidebar`:py:data::sections<Adw.Sidebar.props.sections>].
- Selection and activation
AdwSidebarhas zero or one selected items. The index of the item can be accessed and changed via [property`Sidebar`:py:data::selected<Adw.Sidebar.props.selected>]. Set it to [const`Gtk`.INVALID_LIST_POSITION] to remove selection.Selection cannot be permanently disabled.
[property`Sidebar`:py:data::selected-item<Adw.Sidebar.props.selected_item>] can be used to access the selected item.
Connect to the [signal`Sidebar`:py:func:::activated<Adw.Sidebar.signals.activated>] signal to run code when an item has been activated. This can be used to toggle the visible pane when used in a split view.
See also: [class`ViewSwitcherSidebar`].
- Modes
<picture> <source srcset=”sidebar-modes-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”sidebar-modes.png” alt=”sidebar-modes”> </picture>
AdwSidebaris adaptive and can act as either a regular sidebar, or a page of boxed lists.Use the [property`Sidebar`:py:data::mode<Adw.Sidebar.props.mode>] to determine its look and behavior.
A typical use case involves using
AdwSidebarinside the sidebar pane of a [class`NavigationSplitView`], and switching mode to page whenever it’s collapsed, as follows:``xml <object class=”AdwWindow”>
<property name=”default-width”>800</property> <property name=”default-height”>600</property> <child>
- <object class=”AdwBreakpoint”>
<condition>max-width: 400sp</condition> <setter object=”split_view” property=”collapsed”>True</setter> <setter object=”sidebar” property=”mode”>page</setter>
</object>
</child> <property name=”content”>
- <object class=”AdwNavigationSplitView” id=”split_view”>
- <property name=”sidebar”>
- <object class=”AdwNavigationPage”>
<property name=”title” translatable=”yes”>Sidebar</property> <property name=”child”>
- <object class=”AdwToolbarView”>
- <child type=”top”>
<object class=”AdwHeaderBar”/>
</child> <property name=”content”>
- <object class=”AdwSidebar” id=”sidebar”>
<!– Calls adw_navigation_split_view_set_show_content (split_view, TRUE); –> <signal name=”activated” handler=”sidebar_activated_cb”/> <!– … –>
</object>
</property>
</object>
</property>
</object>
</property> <property name=”content”>
- <object class=”AdwNavigationPage”>
<property name=”title” translatable=”yes”>Content</property> <property name=”child”>
<!– … –>
</property>
</object>
</property>
</object>
</property>
</object> ``
When used with [class`OverlaySplitView`], the sidebar should stay in sidebar mode, as the sidebar pane is still a sidebar when collapsed.
- Search
AdwSidebarsupports filtering items via the [property`Sidebar`:py:data::filter<Adw.Sidebar.props.filter>] property.Use [property`Sidebar`:py:data::placeholder<Adw.Sidebar.props.placeholder>] to provide an empty state widget. It will be shown when all items have been filtered out, or the sidebar has no items otherwise.
- Context Menu
To create a context menu for the sidebar items, use the [property`Sidebar`:py:data::menu-model<Adw.Sidebar.props.menu_model>] property to provide a menu model, and the [signal`Sidebar`:py:func:::setup-menu<Adw.Sidebar.signals.setup_menu>] signal to set up actions for the given item.
To set or override the menu for just one section, use [property`SidebarSection`:py:data::menu-model<Adw.Sidebar.props.menu_model>] instead.
- Drag-and-Drop
AdwSidebaritems can have a drop target for arbitrary content.Use [method`Sidebar`.setup_drop_target] to set it up, specifying the supported content types and drag actions, then connect to [signal`Sidebar`:py:func:::drop<Adw.Sidebar.signals.drop>] to handle drops.
In some cases, it may be necessary to determine the used action based on the dragged content, or the hovered item.
To determine it based on the sidebar item, connect to the [signal`Sidebar`:py:func:::drop-enter<Adw.Sidebar.signals.drop_enter>] signal and return the action from its handler.
To determine it based on the content, set [property`Sidebar`:py:data::drop-preload<Adw.Sidebar.props.drop_preload>] to
TRUE, then connect to [signal`Sidebar`:py:func:::drop-value-loaded<Adw.Sidebar.signals.drop_value_loaded>] signal and return the action from its handler.In both cases the action will be passed as a parameter to the [signal`Sidebar`:py:func:::drop<Adw.Sidebar.signals.drop>] signal.
Regardless of whether a drop target was set up, dragging content over sidebar items activates them after a timeout. To disable this behavior for specific items, set [property`SidebarItem`:py:data::drag-motion-activate<Adw.Sidebar.props.drag_motion_activate>] to
FALSEon them.AdwSidebarallows adding sections as children.Example of an
AdwSidebarUI definition:``xml <object class=”AdwSidebar”>
- <child>
- <object class=”AdwSidebarSection”>
- <child>
- <object class=”AdwSidebarItem”>
<property name=”title” translatable=”yes”>Recent</property> <property name=”icon-name”>document-open-recent-symbolic</property>
</object>
</child> <child>
- <object class=”AdwSidebarItem”>
<property name=”title” translatable=”yes”>Starred</property> <property name=”icon-name”>starred-symbolic</property>
</object>
</child>
</object>
</child> <child>
- <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>
</child> <child>
- <object class=”AdwSidebarSection”>
- <child>
- <object class=”AdwSidebarItem”>
<property name=”title” translatable=”yes”>Trash</property> <property name=”icon-name”>user-trash-symbolic</property>
</object>
</child>
</object>
</child>
</object> ``
- CSS nodes
AdwSidebarhas a main CSS node with the namesidebar.Internally, it’s using a [class`Gtk`.ListBox] with the .navigation-sidebar style class in sidebar mode, or an [class`PreferencesPage`] in page mode.
- Accessibility
AdwSidebaruses the [enum`Gtk`.AccessibleRole.generic] role.New in version 1.9.
- classmethod new()¶
- Returns:
the newly created
AdwSidebar- Return type:
Creates a new
AdwSidebar.New in version 1.9.
- append(section)¶
- Parameters:
section (
Adw.SidebarSection) – a section to append
Appends section to self.
New in version 1.9.
- get_drop_preload()¶
- Returns:
whether drop data should be preloaded on hover
- Return type:
Gets whether drop data should be preloaded on hover.
New in version 1.9.
- get_filter()¶
- Returns:
the item filter
- Return type:
Gtk.FilterorNone
Gets the item filter for self.
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 sidebar, and is same as the one returned by [method`SidebarItem`.get_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.
The model implements [iface`Gtk`.SectionModel] and creates sections corresponding to the sidebar’s sections.
The model also implements [iface`Gtk`.SelectionModel] and can be used to track and change the selection.
To only track sections, use [property`Sidebar`:py:data::sections<Adw.Sidebar.props.sections>] instead.
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_mode()¶
- Returns:
the current mode
- Return type:
Gets self's look and behavior.
New in version 1.9.
- get_placeholder()¶
- Returns:
the placeholder widget
- Return type:
Gtk.WidgetorNone
Gets the placeholder widget for self.
New in version 1.9.
- get_section(index)¶
- Parameters:
index (
int) – index of the section- Returns:
the section at index
- Return type:
Gets the section at index within self.
Can return
NULLif index is larger or equal to the number of sections.New in version 1.9.
- get_sections()¶
- Returns:
a model containing the sections
- Return type:
Gets a list model with self's sections.
This can be used to keep an up-to-date view.
To track items, use [property`Sidebar`:py:data::items<Adw.Sidebar.props.items>] instead.
New in version 1.9.
- get_selected()¶
- Returns:
index of the currently selected item
- Return type:
Gets the index of the currently selected item.
See also: [method`Sidebar`.get_selected_item].
New in version 1.9.
- get_selected_item()¶
- Returns:
the selected item
- Return type:
Gets the currently selected item.
This is a convenience method, equivalent to calling [method`Sidebar`.get_item] with [property`Sidebar`:py:data::selected<Adw.Sidebar.props.selected>] provided as the index.
To change selection, use [method`Sidebar`.set_selected].
New in version 1.9.
- insert(section, position)¶
- Parameters:
section (
Adw.SidebarSection) – a section to insertposition (
int) – position to insert section at
Inserts section at position to self.
If position is -1, or larger than the total number of sections in self, the section will be appended to the end.
New in version 1.9.
- prepend(section)¶
- Parameters:
section (
Adw.SidebarSection) – a section to prepend
Prepends section to self.
New in version 1.9.
- remove(section)¶
- Parameters:
section (
Adw.SidebarSection) – a section to remove
Removes section from self.
New in version 1.9.
- remove_all()¶
Removes all sections from self.
New in version 1.9.
- set_drop_preload(preload)¶
- Parameters:
preload (
bool) – whether to preload drop data
Sets whether drop data should be preloaded on hover.
See [property`Gtk`.DropTarget:preload].
New in version 1.9.
- set_filter(filter)¶
- Parameters:
filter (
Gtk.FilterorNone) – the item filter
Sets the item filter for self.
Can be used to implement search within the sidebar.
Use [property`Sidebar`:py:data::placeholder<Adw.Sidebar.props.placeholder>] to provide an empty state.
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.Sidebar.signals.setup_menu>] signal to set up the menu actions for the particular item.
[property`Sidebar`:py:data::menu-model<Adw.Sidebar.props.menu_model>] will be preferred over this model if set.
New in version 1.9.
- set_mode(mode)¶
- Parameters:
mode (
Adw.SidebarMode) – the new mode
Sets self's look and behavior.
If set to [enum`Adw`.SidebarMode.sidebar], behaves like a sidebar: with a sidebar style and a persistent selection.
If set to [enum`Adw`.SidebarMode.page], behaves like a page of boxed lists. In this mode, the selection is invisible and only tracked to determine the initially selected item once switched back to sidebar mode.
The page mode is intended to be used with [class`NavigationSplitView`] when collapsed, as the sidebar pane becomes a page there.
When used with [class`OverlaySplitView`], the sidebar should stay in sidebar mode, as the sidebar pane is still a sidebar when collapsed.
New in version 1.9.
- set_placeholder(placeholder)¶
- Parameters:
placeholder (
Gtk.WidgetorNone) – the placeholder widget
Sets the placeholder widget for self.
This widget will be shown if self has no items, or all of its items have been filtered out by [property`Sidebar`:py:data::filter<Adw.Sidebar.props.filter>].
New in version 1.9.
- set_selected(selected)¶
- Parameters:
selected (
int) – index of the newly selected item
Selects the item at selected.
If set to [const`Gtk`.INVALID_LIST_POSITION], no item is selected.
If [property`Sidebar`:py:data::mode<Adw.Sidebar.props.mode>] is set to [enum`Adw`.SidebarMode.page], the selection is invisible, but still tracked, indicating which item will be selected once the mode is changed to [enum`Adw`.SidebarMode.sidebar].
See also: [property`Sidebar`:py:data::selected-item<Adw.Sidebar.props.selected_item>].
New in version 1.9.
- setup_drop_target(actions, types)¶
- Parameters:
actions (
Gdk.DragAction) – the supported actionstypes ([
GObject.GType] orNone) – all supported ``GType``s that can be dropped
Sets up a drop target on the items.
This allows to drag arbitrary content onto items.
The [signal`Sidebar`:py:func:::drop<Adw.Sidebar.signals.drop>] signal can be used to handle the drop.
New in version 1.9.
Signal Details¶
- Adw.Sidebar.signals.activated(sidebar, index)¶
- Signal Name:
activated- Flags:
- Parameters:
sidebar (
Adw.Sidebar) – The object which received the signalindex (
int) – the item index
Emitted when an item at index has been activated.
New in version 1.9.
- Adw.Sidebar.signals.drop(sidebar, index, value, preferred_action)¶
- Signal Name:
drop- Flags:
- Parameters:
sidebar (
Adw.Sidebar) – The object which received the signalindex (
int) – index of the item the content was dropped ontovalue (
GObject.Value) – theGValuebeing droppedpreferred_action (
Gdk.DragAction) – the preferred drop action
- Returns:
whether the drop was accepted
SinceL 1.9
- Return type:
Emitted when content is dropped onto the item at index.
The content must be of one of the types set up via [method`Sidebar`.setup_drop_target].
See [signal`Gtk`.DropTarget::drop].
- Adw.Sidebar.signals.drop_enter(sidebar, index)¶
- Signal Name:
drop-enter- Flags:
- Parameters:
sidebar (
Adw.Sidebar) – The object which received the signalindex (
int) – index of the hovered item
- Returns:
the preferred action for the drop
- Return type:
Emitted when the pointer enters the item at index.
Applications can use this to set their default drop action even when [property`Sidebar`:py:data::drop-preload<Adw.Sidebar.props.drop_preload>] is set to
FALSE.See [signal`Gtk`.DropTarget::enter].
New in version 1.9.
- Adw.Sidebar.signals.drop_value_loaded(sidebar, index, value)¶
- Signal Name:
drop-value-loaded- Flags:
- Parameters:
sidebar (
Adw.Sidebar) – The object which received the signalindex (
int) – index of the hovered itemvalue (
GObject.Value) – theGValuebeing dropped
- Returns:
the preferred action for the drop
- Return type:
Emitted when the dropped content is preloaded for the item at index.
In order for data to be preloaded, [property`Sidebar`:py:data::drop-preload<Adw.Sidebar.props.drop_preload>] must be set to
TRUE.The content must be of one of the types set up via [method`Sidebar`.setup_drop_target].
See [property`Gtk`.DropTarget:value].
New in version 1.9.
- Adw.Sidebar.signals.setup_menu(sidebar, item)¶
- Signal Name:
setup-menu- Flags:
- Parameters:
sidebar (
Adw.Sidebar) – The object which received the signalitem (
Adw.SidebarItemorNone) – an item in self
Emitted when a context menu is opened or closed for item.
If the menu has been closed, item 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 item.
Property Details¶
- Adw.Sidebar.props.drop_preload¶
- Name:
drop-preload- Type:
- Default Value:
- Flags:
Whether the drop data should be preloaded on hover.
See [property`Gtk`.DropTarget:preload].
New in version 1.9.
- Adw.Sidebar.props.filter¶
- Name:
filter- Type:
- Default Value:
- Flags:
The item filter.
Can be used to implement search within the sidebar.
Use [property`Sidebar`:py:data::placeholder<Adw.Sidebar.props.placeholder>] to provide an empty state.
New in version 1.9.
- Adw.Sidebar.props.items¶
- Name:
items- Type:
- Default Value:
- Flags:
A list model with the sidebar’s items.
This can be used to keep an up-to-date view.
The model implements [iface`Gtk`.SectionModel] and creates sections corresponding to the sidebar’s sections.
The model also implements [iface`Gtk`.SelectionModel] and can be used to track and change the selection.
To only track sections, use [property`Sidebar`:py:data::sections<Adw.Sidebar.props.sections>] instead.
New in version 1.9.
- Adw.Sidebar.props.menu_model¶
- Name:
menu-model- Type:
- Default Value:
- Flags:
Context menu model for the 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.Sidebar.signals.setup_menu>] signal to set up the menu actions for the particular item.
[property`Sidebar`:py:data::menu-model<Adw.Sidebar.props.menu_model>] will be preferred over this model if set.
New in version 1.9.
- Adw.Sidebar.props.mode¶
- Name:
mode- Type:
- Default Value:
- Flags:
Determines the sidebar’s look and behavior.
If set to [enum`Adw`.SidebarMode.sidebar], behaves like a sidebar: with a sidebar style and a persistent selection.
If set to [enum`Adw`.SidebarMode.page], behaves like a page of boxed lists. In this mode, the selection is invisible and only tracked to determine the initially selected item once switched back to sidebar mode.
The page mode is intended to be used with [class`NavigationSplitView`] when collapsed, as the sidebar pane becomes a page there.
When used with [class`OverlaySplitView`], the sidebar should stay in sidebar mode, as the sidebar pane is still a sidebar when collapsed.
New in version 1.9.
- Adw.Sidebar.props.placeholder¶
- Name:
placeholder- Type:
- Default Value:
- Flags:
The placeholder widget.
This widget will be shown if the sidebar has no items, or all of its items have been filtered out by [property`Sidebar`:py:data::filter<Adw.Sidebar.props.filter>].
New in version 1.9.
- Adw.Sidebar.props.sections¶
- Name:
sections- Type:
- Default Value:
- Flags:
A list model with the sidebar’s sections.
This can be used to keep an up-to-date view.
To track items, use [property`Sidebar`:py:data::items<Adw.Sidebar.props.items>] instead.
New in version 1.9.
- Adw.Sidebar.props.selected¶
- Name:
selected- Type:
- Default Value:
4294967295- Flags:
The index of the currently selected item.
If set to [const`Gtk`.INVALID_LIST_POSITION], no item is selected.
If [property`Sidebar`:py:data::mode<Adw.Sidebar.props.mode>] is set to [enum`Adw`.SidebarMode.page], the selection is invisible, but still tracked, indicating which item will be selected once the mode is changed to [enum`Adw`.SidebarMode.sidebar].
See also: [property`Sidebar`:py:data::selected-item<Adw.Sidebar.props.selected_item>].
New in version 1.9.
- Adw.Sidebar.props.selected_item¶
- Name:
selected-item- Type:
- Default Value:
- Flags:
The currently selected item.
This is a convenience property, equivalent to calling [method`Sidebar`.get_item] with [property`Sidebar`:py:data::selected<Adw.Sidebar.props.selected>] provided as the index.
To change selection, use [property`Sidebar`:py:data::selected<Adw.Sidebar.props.selected>].
New in version 1.9.