Gtk.MenuShell¶
- Subclasses:
Methods¶
- Inherited:
Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10)
- Structs:
Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
|
|
|
|
|
|
|
|
|
|
|
|
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
A boolean that determines whether the menu grabs the keyboard focus |
Style Properties¶
- Inherited:
Signals¶
- Inherited:
Name |
Short Description |
---|---|
An action signal that activates the current menu item within the menu shell. |
|
An action signal which cancels the selection within the menu shell. |
|
A keybinding signal which moves the focus in the given direction. |
|
This signal is emitted when a menu shell is deactivated. |
|
The |
|
An keybinding signal which moves the current menu item in the direction specified by direction. |
|
The |
|
This signal is emitted when a selection has been completed within a menu shell. |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
container |
r |
Class Details¶
- class Gtk.MenuShell(**kwargs)¶
- Bases:
- Abstract:
Yes
- Structure:
A
Gtk.MenuShell
is the abstract base class used to derive theGtk.Menu
andGtk.MenuBar
subclasses.A
Gtk.MenuShell
is a container ofGtk.MenuItem
objects arranged in a list which can be navigated, selected, and activated by the user to perform application functions. AGtk.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.
- activate_item(menu_item, force_deactivate)[source]¶
- Parameters:
menu_item (
Gtk.Widget
) – theGtk.MenuItem
to activateforce_deactivate (
bool
) – ifTrue
, force the deactivation of the menu shell after the menu item is activated
Activates the menu item within the menu shell.
- append(child)[source]¶
- Parameters:
child (
Gtk.MenuItem
) – TheGtk.MenuItem
to add
Adds a new
Gtk.MenuItem
to the end of the menu shell’s item list.
- bind_model(model, action_namespace, with_separators)[source]¶
- Parameters:
model (
Gio.MenuModel
orNone
) – theGio.MenuModel
to bind to orNone
to remove bindingaction_namespace (
str
orNone
) – the namespace for actions in modelwith_separators (
bool
) –True
if toplevel items in shell should have separators between them
Establishes a binding between a
Gtk.MenuShell
and aGio.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
None
then 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-
None
then 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.Actionable
to 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 aGtk.MenuShell
outside of aGtk.ApplicationWindow
, then you will need to attach your own action group to the widget hierarchy usingGtk.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 yourGio.MenuModel
.For most cases you are probably better off using
Gtk.Menu.new_from_model
() orGtk.MenuBar.new_from_model
() or just directly passing theGio.MenuModel
toGtk.Application.set_app_menu
() orGtk.Application.set_menubar
().New in version 3.6.
- 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:
Gets the parent menu shell.
The parent menu shell of a submenu is the
Gtk.Menu
orGtk.MenuBar
from which it was opened up.New in version 3.0.
- get_selected_item()[source]¶
- Returns:
the currently selected item
- Return type:
Gets the currently selected item.
New in version 3.0.
- get_take_focus()[source]¶
-
Returns
True
if the menu shell will take the keyboard focus on popup.New in version 2.8.
- insert(child, position)[source]¶
- Parameters:
child (
Gtk.Widget
) – TheGtk.MenuItem
to addposition (
int
) – The position in the item list where child is added. Positions are numbered from 0 to n-1
Adds a new
Gtk.MenuItem
to the menu shell’s item list at the position indicated by position.
- prepend(child)[source]¶
- Parameters:
child (
Gtk.Widget
) – TheGtk.MenuItem
to add
Adds a new
Gtk.MenuItem
to the beginning of the menu shell’s item list.
- select_first(search_sensitive)[source]¶
- Parameters:
search_sensitive (
bool
) – ifTrue
, search for the first selectable menu item, otherwise select nothing if the first item isn’t sensitive. This should beFalse
if 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
) – TheGtk.MenuItem
to select
Selects the menu item from the menu shell.
- set_take_focus(take_focus)[source]¶
-
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
False
is 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
False
has 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
False
should 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.MenuItem
to addposition (
int
) – The position in the item list where child is added. Positions are numbered from 0 to n-1
Adds a new
Gtk.MenuItem
to the menu shell’s item list at the position indicated by position.
- do_move_current(direction) virtual¶
- Parameters:
direction (
Gtk.MenuDirectionType
) –
- do_select_item(menu_item) virtual¶
- Parameters:
menu_item (
Gtk.Widget
) – TheGtk.MenuItem
to 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 signalforce_hide (
bool
) – ifTrue
, hide the menu after activating the menu item
An action signal that activates the current menu item within the menu shell.
- Gtk.MenuShell.signals.cancel(menu_shell)¶
- Signal Name:
cancel
- Flags:
- 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-done
signal 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 signaldirection (
Gtk.DirectionType
) – the direction to cycle in
A keybinding signal which moves the focus in the given direction.
- Gtk.MenuShell.signals.deactivate(menu_shell)¶
- Signal Name:
deactivate
- Flags:
- 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 signalchild (
Gtk.Widget
) – theGtk.MenuItem
that is being insertedposition (
int
) – the position at which the insert occurs
The
::insert
signal is emitted when a newGtk.MenuItem
is added to aGtk.MenuShell
. A separate signal is used instead ofGtk.Container
::add
because of the need for an additional position parameter.The inverse of this signal is the
Gtk.Container
::removed
signal.New in version 3.2.
- Gtk.MenuShell.signals.move_current(menu_shell, direction)¶
- Signal Name:
move-current
- Flags:
- Parameters:
menu_shell (
Gtk.MenuShell
) – The object which received the signaldirection (
Gtk.MenuDirectionType
) – the direction to move
An keybinding signal which moves the current menu item in the direction specified by direction.
- Gtk.MenuShell.signals.move_selected(menu_shell, distance)¶
- Signal Name:
move-selected
- Flags:
- Parameters:
menu_shell (
Gtk.MenuShell
) – The object which received the signaldistance (
int
) – +1 to move to the next item, -1 to move to the previous
- Returns:
- Return type:
The
::move-selected
signal is emitted to move the selection to another item.New in version 2.12.
- Gtk.MenuShell.signals.selection_done(menu_shell)¶
- Signal Name:
selection-done
- Flags:
- 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:
- Default Value:
- Flags:
A boolean that determines whether the menu and its submenus grab the keyboard focus. See
Gtk.MenuShell.set_take_focus
() andGtk.MenuShell.get_take_focus
().New in version 2.8.