ContextMenuItem

class ContextMenuItem(**properties: Any)

Superclasses: InitiallyUnowned, Object

One item of a ContextMenu.

The ContextMenu is composed of :obj:`~gi.repository.WebKit.ContextMenuItem`<!–

–>s. These items can be created from a GtkAction, from a ContextMenuAction or from a ContextMenuAction and a label. These :obj:`~gi.repository.WebKit.ContextMenuAction`<!– –>s denote stock actions for the items. You can also create separators and submenus.

Constructors

class ContextMenuItem
classmethod new_from_gaction(action: Action, label: str, target: Variant | None = None) ContextMenuItem

Creates a new ContextMenuItem for the given action and label.

On activation target will be passed as parameter to the callback.

Added in version 2.18.

Parameters:
  • action – a Action

  • label – the menu item label text

  • target – a Variant to use as the action target

classmethod new_from_stock_action(action: ContextMenuAction) ContextMenuItem

Creates a new ContextMenuItem for the given stock action.

Stock actions are handled automatically by WebKit so that, for example, when a menu item created with a STOP is activated the action associated will be handled by WebKit and the current load operation will be stopped. You can get the Action of a ContextMenuItem created with a ContextMenuAction with get_gaction() and connect to the SimpleAction::activate signal to be notified when the item is activated, but you can’t prevent the associated action from being performed.

Parameters:

action – a ContextMenuAction stock action

classmethod new_from_stock_action_with_label(action: ContextMenuAction, label: str) ContextMenuItem

Creates a new ContextMenuItem for the given stock action using the given label.

Stock actions have a predefined label, this method can be used to create a ContextMenuItem for a ContextMenuAction but using a custom label.

Parameters:
  • action – a ContextMenuAction stock action

  • label – a custom label text to use instead of the predefined one

classmethod new_separator() ContextMenuItem

Creates a new ContextMenuItem representing a separator.

classmethod new_with_submenu(label: str, submenu: ContextMenu) ContextMenuItem

Creates a new ContextMenuItem using the given label with a submenu.

Parameters:
  • label – the menu item label text

  • submenu – a ContextMenu to set

Methods

class ContextMenuItem
get_gaction() Action

Gets the action associated to item as a Action.

Added in version 2.18.

get_stock_action() ContextMenuAction

Gets the ContextMenuAction of item.

If the ContextMenuItem was not created for a stock action CUSTOM will be returned. If the ContextMenuItem is a separator NO_ACTION will be returned.

get_submenu() ContextMenu

Gets the submenu of item.

is_separator() bool

Checks whether item is a separator.

set_submenu(submenu: ContextMenu | None = None) None

Sets or replaces the item submenu.

If submenu is None the current submenu of item is removed.

Parameters:

submenu – a ContextMenu