Gtk.MenuShell


Gtk.MenuShell — A base class for menu objects

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.MenuShell
                    ├── Gtk.MenuBar
                    ╰── Gtk.Menu

Functions:


Signals:

  • “activate-current” (menushell, force_hide, user_data)
  • “cancel” (menushell, user_data)
  • “cycle-focus” (menushell, direction, user_data)
  • “deactivate” (menushell, user_data)
  • “insert” (menu_shell, child, position, user_data)
  • “move-current” (menushell, direction, user_data)
  • “move-selected” (menu_shell, distance, user_data)
  • “selection-done” (menushell, user_data)

Description:

A Gtk.MenuShell is the abstract base class used to derive the Gtk.Menu and Gtk.MenuBar subclasses.

A Gtk.MenuShell is a container of GtkMenuItem objects arranged in a list which can be navigated, selected, and activated by the user to perform application functions. A Gtk.MenuItem can have a submenu associated with it, allowing for nested hierarchical menus.

Terminology

A menu item can be selected, this means that it is displayed in the prelight state, and if it has a submenu, that submenu will be popped up.

A menu is active when it is visible onscreen and the user is selecting from it. A menubar is not active until the user clicks on one of its menuitems. When a menu is active, passing the mouse over a submenu will pop it up.

There is also is a concept of the current menu and a current menu item. The current menu item is the selected menu item that is furthest down in the hierarchy. (Every active menu shell does not necessarily contain a selected menu item, but if it does, then the parent menu shell must also contain a selected menu item.) The current menu is the menu that contains the current menu item. It will always have a GTK grab and receive all key presses.


Function Details:

append()

append (self, child:Gtk.MenuItem)

Adds a new Gtk.MenuItem to the end of the menu shell'sitem list.


prepend()

prepend (self, child:Gtk.Widget)

Adds a new Gtk.MenuItem to the beginning of the menu shell'sitem list.


insert()

insert (self, child:Gtk.Widget, position:int)

Adds a new Gtk.MenuItem to the menu shell’s item listat the position indicated by position.


deactivate()

deactivate (self)

Deactivates the menu shell. Typically this results in the menu shell being erasedfrom the screen.


select_item()

select_item (self, menu_item:Gtk.Widget)

Selects the menu item from the menu shell.


select_first()

select_first (self, search_sensitive:bool)

Select the first visible or selectable child of the menu shell;don’t select tearoff items unless the only item is a tearoffitem.

  • Since: 2.2

deselect()

deselect (self)

Deselects the currently selected item from the menu shell,if any.


activate_item()

activate_item (self, menu_item:Gtk.Widget, force_deactivate:bool)

Activates the menu item within the menu shell.


cancel()

cancel (self)

Cancels the selection within the menu shell.

  • Since: 2.4

set_take_focus()

set_take_focus (self, take_focus:bool)

If take_focus is True (the default) the menu shell will takethe keyboard focus so that it will receive all keyboard eventswhich is needed to enable keyboard navigation in menus. Setting take_focus to FALSE is useful only for special applicationslike virtual keyboard implementations which should not take keyboardfocus. The take_focus state of a menu or menu bar is automaticallypropagated to submenus whenever a submenu is popped up, so youdon’t have to worry about recursively setting it for your entiremenu hierarchy. Only when programmatically picking a submenu andpopping it up manually, the take_focus property of the submenuneeds to be set explicitly. Note that setting it to FALSE has side-effects: If the focus is in some other app, it keeps the focus and keynav inthe menu doesn’t work. Consequently, keynav on the menu will onlywork if the focus is on some toplevel owned by the onscreen keyboard. To avoid confusing the user, menus with take_focus set to FALSEshould not display mnemonics or accelerators, since it cannot beguaranteed that they will work. See also gdk_keyboard_grab()

  • Since: 2.8

get_take_focus()

get_take_focus (self) -> bool

Returns True if the menu shell will take the keyboard focus on popup.

  • Returns: True if the menu shell will take the keyboard focus on popup.

  • Since: 2.8


get_selected_item()

get_selected_item (self) -> Gtk.Widget

Gets the currently selected item.

  • Returns: the currently selected item.

  • Since: 3.0


get_parent_shell()

get_parent_shell (self) -> Gtk.Widget

Gets the parent menu shell. The parent menu shell of a submenu is the Gtk.Menu or Gtk.MenuBarfrom which it was opened up.

  • Returns: the parent Gtk.MenuShell.

  • Since: 3.0


bind_model()

bind_model (self, model:Gio.MenuModel=None, action_namespace:str=None, with_separators:bool)

Establishes a binding between a Gtk.MenuShell and a GMenuModel. The contents of shell are removed and then refilled with menu itemsaccording to model. When model changes, shell is updated.Calling this function twice on shell with different model willcause the first binding to be replaced with a binding to the newmodel. If model is None then any previous binding is undone andall children are removed. with_separators determines if toplevel items (eg: sections) haveseparators inserted between them. This is typically desired formenus but doesn’t make sense for menubars. If action_namespace is non-None then the effect is as if allactions mentioned in the model have their names prefixed with thenamespace, plus a dot. For example, if the action “quit” ismentioned and action_namespace is “app” then the effective actionname is “app.quit”. This function uses Gtk.Actionable to define the action name andtarget values on the created menu items. If you want to use anaction group other than “app” and “win”, or if you want to use aGtk.MenuShell outside of a Gtk.ApplicationWindow, then you will needto attach your own action group to the widget hierarchy usingGtk.Widget:insert_action_group`()`. As an example, if you created agroup with a “quit” action and inserted it with the name “mygroup”then you would use the action name “mygroup.quit” in yourGMenuModel. For most cases you are probably better off usingGtk.Menu:new_from_model() or Gtk.MenuBar:new_from_model`()` or justdirectly passing the GMenuModel toGtk.Application:set_app_menu() or`Gtk.Application:set_menubar()`.

  • Since: 3.6

results matching ""

    No results matching ""