Gtk.MenuShell¶
| Subclasses: | Gtk.Menu,Gtk.MenuBar | 
|---|
Methods¶
| Inherited: | Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10) | 
|---|---|
| Structs: | Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5) | 
| activate_item(menu_item, force_deactivate) | |
| append(child) | |
| bind_model(model, action_namespace, with_separators) | |
| cancel() | |
| deactivate() | |
| deselect() | |
| get_parent_shell() | |
| get_selected_item() | |
| get_take_focus() | |
| insert(child, position) | |
| prepend(child) | |
| select_first(search_sensitive) | |
| select_item(menu_item) | |
| set_take_focus(take_focus) | 
Virtual Methods¶
| Inherited: | Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10) | 
|---|
| do_activate_current(force_hide) | |
| do_cancel() | |
| do_deactivate() | |
| do_get_popup_delay() | |
| do_insert(child, position) | |
| do_move_current(direction) | |
| do_move_selected(distance) | |
| do_select_item(menu_item) | |
| do_selection_done() | 
Properties¶
| Inherited: | Gtk.Container (3), Gtk.Widget (39) | 
|---|
| Name | Type | Flags | Short Description | 
|---|---|---|---|
| take-focus | bool | r/w/en | A boolean that determines whether the menu grabs the keyboard focus | 
Style Properties¶
| Inherited: | Gtk.Widget (17) | 
|---|
Signals¶
| Inherited: | Gtk.Container (4), Gtk.Widget (69), GObject.Object (1) | 
|---|
| Name | Short Description | 
|---|---|
| activate-current | An action signal that activates the current menu item within the menu shell. | 
| cancel | An action signal which cancels the selection within the menu shell. | 
| cycle-focus | A keybinding signal which moves the focus in the given direction. | 
| deactivate | This signal is emitted when a menu shell is deactivated. | 
| insert | The ::insertsignal is emitted when a newGtk.MenuItemis added to aGtk.MenuShell. | 
| move-current | An keybinding signal which moves the current menu item in the direction specified by direction. | 
| move-selected | The ::move-selectedsignal is emitted to move the selection to another item. | 
| selection-done | This signal is emitted when a selection has been completed within a menu shell. | 
Fields¶
| Inherited: | Gtk.Container (4), Gtk.Widget (69), GObject.Object (1) | 
|---|
| Name | Type | Access | Description | 
|---|---|---|---|
| container | Gtk.Container | r | 
Class Details¶
- 
class Gtk.MenuShell(**kwargs)¶
- Bases: - Gtk.Container- Abstract: - Yes - Structure: - Gtk.MenuShellClass- A - Gtk.MenuShellis the abstract base class used to derive the- Gtk.Menuand- Gtk.MenuBarsubclasses.- A - Gtk.MenuShellis a container of- Gtk.MenuItemobjects arranged in a list which can be navigated, selected, and activated by the user to perform application functions. A- Gtk.MenuItemcan 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. - 
activate_item(menu_item, force_deactivate)[source]¶
- Parameters: - menu_item (Gtk.Widget) – theGtk.MenuItemto activate
- force_deactivate (bool) – ifTrue, force the deactivation of the menu shell after the menu item is activated
 - Activates the menu item within the menu shell. 
- menu_item (
 - 
append(child)[source]¶
- Parameters: - child ( - Gtk.MenuItem) – The- Gtk.MenuItemto add- Adds a new - Gtk.MenuItemto the end of the menu shell’s item list.
 - 
bind_model(model, action_namespace, with_separators)[source]¶
- Parameters: - model (Gio.MenuModelorNone) – theGio.MenuModelto bind to orNoneto remove binding
- action_namespace (strorNone) – the namespace for actions in model
- with_separators (bool) –Trueif toplevel items in shell should have separators between them
 - Establishes a binding between a - Gtk.MenuShelland a- Gio.MenuModel.- The contents of shell are removed and then refilled with menu items according to model. When model changes, shell is updated. Calling this function twice on shell with different model will cause the first binding to be replaced with a binding to the new model. If model is - Nonethen any previous binding is undone and all children are removed.- with_separators determines if toplevel items (eg: sections) have separators inserted between them. This is typically desired for menus but doesn’t make sense for menubars. - If action_namespace is non- - Nonethen the effect is as if all actions mentioned in the model have their names prefixed with the namespace, plus a dot. For example, if the action “quit” is mentioned and action_namespace is “app” then the effective action name is “app.quit”.- This function uses - Gtk.Actionableto define the action name and target values on the created menu items. If you want to use an action group other than “app” and “win”, or if you want to use a- Gtk.MenuShelloutside of a- Gtk.ApplicationWindow, then you will need to attach your own action group to the widget hierarchy using- Gtk.Widget.insert_action_group(). As an example, if you created a group with a “quit” action and inserted it with the name “mygroup” then you would use the action name “mygroup.quit” in your- Gio.MenuModel.- For most cases you are probably better off using - Gtk.Menu.new_from_model() or- Gtk.MenuBar.new_from_model() or just directly passing the- Gio.MenuModelto- Gtk.Application.set_app_menu() or- Gtk.Application.set_menubar().- New in version 3.6. 
- model (
 - 
deactivate()[source]¶
- Deactivates the menu shell. - Typically this results in the menu shell being erased from the screen. 
 - 
get_parent_shell()[source]¶
- Returns: - the parent - Gtk.MenuShell- Return type: - Gtk.Widget- Gets the parent menu shell. - The parent menu shell of a submenu is the - Gtk.Menuor- Gtk.MenuBarfrom which it was opened up.- New in version 3.0. 
 - 
get_selected_item()[source]¶
- Returns: - the currently selected item - Return type: - Gtk.Widget- Gets the currently selected item. - New in version 3.0. 
 - 
get_take_focus()[source]¶
- Returns: - Trueif the menu shell will take the keyboard focus on popup.- Return type: - bool- Returns - Trueif the menu shell will take the keyboard focus on popup.- New in version 2.8. 
 - 
insert(child, position)[source]¶
- Parameters: - child (Gtk.Widget) – TheGtk.MenuItemto add
- position (int) – The position in the item list where child is added. Positions are numbered from 0 to n-1
 - Adds a new - Gtk.MenuItemto the menu shell’s item list at the position indicated by position.
- child (
 - 
prepend(child)[source]¶
- Parameters: - child ( - Gtk.Widget) – The- Gtk.MenuItemto add- Adds a new - Gtk.MenuItemto the beginning of the menu shell’s item list.
 - 
select_first(search_sensitive)[source]¶
- Parameters: - search_sensitive ( - bool) – if- True, search for the first selectable menu item, otherwise select nothing if the first item isn’t sensitive. This should be- Falseif the menu is being popped up initially.- Select the first visible or selectable child of the menu shell; don’t select tearoff items unless the only item is a tearoff item. - New in version 2.2. 
 - 
select_item(menu_item)[source]¶
- Parameters: - menu_item ( - Gtk.Widget) – The- Gtk.MenuItemto select- Selects the menu item from the menu shell. 
 - 
set_take_focus(take_focus)[source]¶
- Parameters: - take_focus ( - bool) –- Trueif the menu shell should take the keyboard focus on popup- If take_focus is - True(the default) the menu shell will take the keyboard focus so that it will receive all keyboard events which is needed to enable keyboard navigation in menus.- Setting take_focus to - Falseis useful only for special applications like virtual keyboard implementations which should not take keyboard focus.- The take_focus state of a menu or menu bar is automatically propagated to submenus whenever a submenu is popped up, so you don’t have to worry about recursively setting it for your entire menu hierarchy. Only when programmatically picking a submenu and popping it up manually, the take_focus property of the submenu needs to be set explicitly. - Note that setting it to - Falsehas side-effects:- If the focus is in some other app, it keeps the focus and keynav in the menu doesn’t work. Consequently, keynav on the menu will only work 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 be guaranteed that they will work.- See also - Gdk.keyboard_grab()- New in version 2.8. 
 - 
do_cancel() virtual¶
- Cancels the selection within the menu shell. - New in version 2.4. 
 - 
do_deactivate() virtual¶
- Deactivates the menu shell. - Typically this results in the menu shell being erased from the screen. 
 - 
do_insert(child, position) virtual¶
- Parameters: - child (Gtk.Widget) – TheGtk.MenuItemto add
- position (int) – The position in the item list where child is added. Positions are numbered from 0 to n-1
 - Adds a new - Gtk.MenuItemto the menu shell’s item list at the position indicated by position.
- child (
 - 
do_move_current(direction) virtual¶
- Parameters: - direction ( - Gtk.MenuDirectionType) –
 - 
do_select_item(menu_item) virtual¶
- Parameters: - menu_item ( - Gtk.Widget) – The- Gtk.MenuItemto select- Selects the menu item from the menu shell. 
 - 
do_selection_done() virtual¶
 
Signal Details¶
- 
Gtk.MenuShell.signals.activate_current(menu_shell, force_hide)¶
- Signal Name: - activate-current- Flags: - Parameters: - menu_shell (Gtk.MenuShell) – The object which received the signal
- force_hide (bool) – ifTrue, hide the menu after activating the menu item
 - An action signal that activates the current menu item within the menu shell. 
- menu_shell (
- 
Gtk.MenuShell.signals.cancel(menu_shell)¶
- Signal Name: - cancel- Flags: - RUN_LAST,- ACTION- Parameters: - menu_shell ( - Gtk.MenuShell) – The object which received the signal- An action signal which cancels the selection within the menu shell. Causes the - Gtk.MenuShell- ::selection-donesignal to be emitted.
- 
Gtk.MenuShell.signals.cycle_focus(menu_shell, direction)¶
- Signal Name: - cycle-focus- Flags: - Parameters: - menu_shell (Gtk.MenuShell) – The object which received the signal
- direction (Gtk.DirectionType) – the direction to cycle in
 - A keybinding signal which moves the focus in the given direction. 
- menu_shell (
- 
Gtk.MenuShell.signals.deactivate(menu_shell)¶
- Signal Name: - deactivate- Flags: - RUN_FIRST- Parameters: - menu_shell ( - Gtk.MenuShell) – The object which received the signal- This signal is emitted when a menu shell is deactivated. 
- 
Gtk.MenuShell.signals.insert(menu_shell, child, position)¶
- Signal Name: - insert- Flags: - Parameters: - menu_shell (Gtk.MenuShell) – The object which received the signal
- child (Gtk.Widget) – theGtk.MenuItemthat is being inserted
- position (int) – the position at which the insert occurs
 - The - ::insertsignal is emitted when a new- Gtk.MenuItemis added to a- Gtk.MenuShell. A separate signal is used instead of- Gtk.Container- ::addbecause of the need for an additional position parameter.- The inverse of this signal is the - Gtk.Container- ::removedsignal.- New in version 3.2. 
- menu_shell (
- 
Gtk.MenuShell.signals.move_current(menu_shell, direction)¶
- Signal Name: - move-current- Flags: - Parameters: - menu_shell (Gtk.MenuShell) – The object which received the signal
- direction (Gtk.MenuDirectionType) – the direction to move
 - An keybinding signal which moves the current menu item in the direction specified by direction. 
- menu_shell (
- 
Gtk.MenuShell.signals.move_selected(menu_shell, distance)¶
- Signal Name: - move-selected- Flags: - Parameters: - menu_shell (Gtk.MenuShell) – The object which received the signal
- distance (int) – +1 to move to the next item, -1 to move to the previous
 - Returns: - Return type: - The - ::move-selectedsignal is emitted to move the selection to another item.- New in version 2.12. 
- menu_shell (
- 
Gtk.MenuShell.signals.selection_done(menu_shell)¶
- Signal Name: - selection-done- Flags: - RUN_FIRST- Parameters: - menu_shell ( - Gtk.MenuShell) – The object which received the signal- This signal is emitted when a selection has been completed within a menu shell. 
Property Details¶
- 
Gtk.MenuShell.props.take_focus¶
- Name: - take-focus- Type: - bool- Default Value: - True- Flags: - READABLE,- WRITABLE,- EXPLICIT_NOTIFY- A boolean that determines whether the menu and its submenus grab the keyboard focus. See - Gtk.MenuShell.set_take_focus() and- Gtk.MenuShell.get_take_focus().- New in version 2.8.