Gtk.PopoverMenu¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Popover (21), Gtk.Widget (183), GObject.Object (37), Gtk.Accessible (17), Gtk.Buildable (1), Gtk.Native (6)
- Structs:
class |
|
class |
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
|---|---|---|---|
r/w/en |
|||
r/w |
|||
r/w |
Signals¶
- Inherited:
Fields¶
- Inherited:
Class Details¶
- class Gtk.PopoverMenu(**kwargs)¶
- Bases:
- Abstract:
No
A subclass of
GtkPopoverthat implements menu behavior.<picture> <source srcset=”menu-dark.png” media=”(prefers-color-scheme: dark)”> <img alt=”An example
Gtk.PopoverMenu" src=”menu.png”> </picture>GtkPopoverMenutreats its children like menus and allows switching between them. It can open submenus as traditional, nested submenus, or in a more touch-friendly sliding fashion. The property [property`Gtk`.PopoverMenu:flags] controls this appearance.GtkPopoverMenuis meant to be used primarily with menu models, using [ctor`Gtk`.PopoverMenu.new_from_model]. If you need to put other widgets such as aGtkSpinButtonor aGtkSwitchinto a popover, you can use [method`Gtk`.PopoverMenu.add_child].For more dialog-like behavior, use a plain
GtkPopover.- Menu models
The XML format understood by
GtkBuilderforGMenuModelconsists of a toplevel<menu>element, which contains one or more<item>elements. Each<item>element contains<attribute>and<link>elements with a mandatory name attribute.<link>elements have the same content model as<menu>. Instead of<link name="submenu">or<link name="section">, you can use<submenu>or<section>elements.``xml <menu id=’app-menu’>
- <section>
- <item>
<attribute name=’label’ translatable=’yes’>_New Window</attribute> <attribute name=’action’>app.new</attribute>
</item> <item>
<attribute name=’label’ translatable=’yes’>_About Sunny</attribute> <attribute name=’action’>app.about</attribute>
</item> <item>
<attribute name=’label’ translatable=’yes’>_Quit</attribute> <attribute name=’action’>app.quit</attribute>
</item>
</section>
</menu> ``
Attribute values can be translated using gettext, like other
GtkBuildercontent.<attribute>elements can be marked for translation with atranslatable="yes"attribute. It is also possible to specify message context and translator comments, using the context and comments attributes. To make use of this, theGtkBuildermust have been given the gettext domain to use.The following attributes are used when constructing menu items:
“label”: a user-visible string to display
“use-markup”: whether the text in the menu item includes Pango markup
“action”: the prefixed name of the action to trigger
“target”: the parameter to use when activating the action
“icon” and “verb-icon”: names of icons that may be displayed
“submenu-action”: name of an action that may be used to track whether a submenu is open
“hidden-when”: a string used to determine when the item will be hidden. Possible values include “action-disabled”, “action-missing”, “macos-menubar”. This is mainly useful for exported menus, see [method`Gtk`.Application.set_menubar].
“custom”: a string used to match against the ID of a custom child added with [method`Gtk`.PopoverMenu.add_child], [method`Gtk`.PopoverMenuBar.add_child], or in the ui file with
<child type="ID">.
The following attributes are used when constructing sections:
“label”: a user-visible string to use as section heading
“display-hint”: a string used to determine special formatting for the section. Possible values include “horizontal-buttons”, “circular-buttons” and “inline-buttons”. They all indicate that section should be displayed as a horizontal row of buttons.
“text-direction”: a string used to determine the
GtkTextDirectionto use when “display-hint” is set to “horizontal-buttons”. Possible values include “rtl”, “ltr”, and “none”.
The following attributes are used when constructing submenus:
“label”: a user-visible string to display
“icon”: icon name to display
Menu items will also show accelerators, which are usually associated with actions via [method`Gtk`.Application.set_accels_for_action], [method`WidgetClass`.add_binding_action] or [method`Gtk`.ShortcutController.add_shortcut].
- Shortcuts and Gestures
GtkPopoverMenusupports the following keyboard shortcuts:<kbd>Space</kbd> activates the default widget.
- CSS Nodes
GtkPopoverMenuis just a subclass ofGtkPopoverthat adds custom content to it, therefore it has the same CSS nodes. It is one of the cases that add a.menustyle class to the mainpopovernode.Menu items have nodes with name
buttonand class.model. If a section display-hint is set, the section gets a nodeboxwith classhorizontalplus a class with the same text as the display hint. Note that said box may not be the direct ancestor of the itembutton``s. Thus, for example, to style items in an ``inline-buttonssection, select.inline-buttons button.model. Other things that may be of interest to style in menus includelabelnodes.- Accessibility
GtkPopoverMenuuses the [enum`Gtk`.AccessibleRole.menu] role, and its items use the [enum`Gtk`.AccessibleRole.menu_item], [enum`Gtk`.AccessibleRole.checkbox] or [enum`Gtk`.AccessibleRole.menu_item_radio] roles, depending on the action they are connected to.- classmethod new_from_model(model)[source]¶
- Parameters:
model (
Gio.MenuModelorNone) – aGMenuModel- Returns:
the new
GtkPopoverMenu- Return type:
Creates a
GtkPopoverMenuand populates it according to model.The created buttons are connected to actions found in the
GtkApplicationWindowto which the popover belongs - typically by means of being attached to a widget that is contained within the ``GtkApplicationWindow``s widget hierarchy.Actions can also be added using [method`Gtk`.Widget.insert_action_group] on the menus attach widget or on any of its parent widgets.
This function creates menus with sliding submenus. See [ctor`Gtk`.PopoverMenu.new_from_model_full] for a way to control this.
- classmethod new_from_model_full(model, flags)[source]¶
- Parameters:
model (
Gio.MenuModel) – aGMenuModelflags (
Gtk.PopoverMenuFlags) – flags that affect how the menu is created
- Returns:
the new
GtkPopoverMenu- Return type:
Creates a
GtkPopoverMenuand populates it according to model.The created buttons are connected to actions found in the action groups that are accessible from the parent widget. This includes the
GtkApplicationWindowto which the popover belongs. Actions can also be added using [method`Gtk`.Widget.insert_action_group] on the parent widget or on any of its parent widgets.
- add_child(child, id)[source]¶
- Parameters:
child (
Gtk.Widget) – theGtkWidgetto addid (
str) – the ID to insert child at
- Returns:
Trueif id was found and the widget added- Return type:
Adds a custom widget to a generated menu.
For this to work, the menu model of self must have an item with a
customattribute that matches id.
- get_flags()[source]¶
- Returns:
the
GtkPopoverMenuFlags- Return type:
Returns the flags that self uses to create/display a menu from its model.
New in version 4.14.
- get_menu_model()[source]¶
- Returns:
the menu model of self
- Return type:
Returns the menu model used to populate the popover.
- remove_child(child)[source]¶
- Parameters:
child (
Gtk.Widget) – theGtkWidgetto remove- Returns:
Trueif the widget was removed- Return type:
Removes a widget that has previously been added with [method`Gtk`.PopoverMenu.add_child()]
- set_flags(flags)[source]¶
- Parameters:
flags (
Gtk.PopoverMenuFlags) – a set ofGtkPopoverMenuFlags
Sets the flags that self uses to create/display a menu from its model.
If a model is set and the flags change, contents are rebuilt, so if setting properties individually, set flags before model to avoid a redundant rebuild.
New in version 4.14.
- set_menu_model(model)[source]¶
- Parameters:
model (
Gio.MenuModelorNone) – aGMenuModel
Sets a new menu model on self.
The existing contents of self are removed, and the self is populated with new contents according to model.
Property Details¶
- Gtk.PopoverMenu.props.flags¶
- Name:
flags- Type:
- Default Value:
- Flags:
The flags that popover uses to create/display a menu from its model.
If a model is set and the flags change, contents are rebuilt, so if setting properties individually, set flags before model to avoid a redundant rebuild.
New in version 4.14.
- Gtk.PopoverMenu.props.menu_model¶
- Name:
menu-model- Type:
- Default Value:
- Flags:
The model from which the menu is made.