ContextMenu#
Superclasses: Object
Represents the context menu in a WebView.
ContextMenu represents a context menu containing
ContextMenuItem<!– –>s in a WebView.
When a WebView is about to display the context menu, it
emits the WebView::context-menu signal, which has the
ContextMenu as an argument. You can modify it, adding new
submenus that you can create with new(), adding
new ContextMenuItem<!– –>s with
prepend(), append() or
insert(), maybe after having removed the
existing ones with remove_all().
Constructors#
- class ContextMenu
- classmethod new() → ContextMenu#
Creates a new
ContextMenuobject.Creates a new
ContextMenuobject to be used as a submenu of an existingContextMenu. The context menu of aWebViewis created by the view and passed as an argument ofWebView::context-menu signal. To add items to the menu useprepend(),append()orinsert(). See alsonew_with_items()to create aContextMenuwith a list of initial items.
- classmethod new_with_items(items: list[ContextMenuItem]) → ContextMenu#
Creates a new
ContextMenuobject with the given items.Creates a new
ContextMenuobject to be used as a submenu of an existingContextMenuwith the given initial items. See alsonew()- Parameters:
items – a
ListofContextMenuItem
Methods#
- class ContextMenu
- append(item: ContextMenuItem) → None#
Adds
itemat the end of themenu.- Parameters:
item – the
ContextMenuItemto add
- first() → ContextMenuItem#
Gets the first item in the
menu.
- get_event() → Event#
Gets the
Eventthat triggered the context menu. This function only returns a validEventwhen called for aContextMenupassed toWebView::context-menu signal; in all other cases,Noneis returned.The returned
Eventis expected to be one of the following types: <itemizedlist> <listitem><para> aGdkEventButtonof type %GDK_BUTTON_PRESS when the context menu was triggered with mouse. </para></listitem> <listitem><para> aGdkEventKeyof type %GDK_KEY_PRESS if the keyboard was used to show the menu. </para></listitem> <listitem><para> a genericEventof type %GDK_NOTHING when theWidget::popup-menu signal was used to show the context menu. </para></listitem> </itemizedlist>Added in version 2.40.
- get_item_at_position(position: int) → ContextMenuItem#
Gets the item at the given position in the
menu.- Parameters:
position – the position of the item, counting from 0
- get_items() → list[ContextMenuItem]#
Returns the item list of
menu.
- get_user_data() → Variant#
Gets the user data of
menu.This function can be used from the UI Process to get user data previously set from the Web Process with
set_user_data().Added in version 2.8.
- insert(item: ContextMenuItem, position: int) → None#
Inserts
iteminto themenuat the given position.If
positionis negative, or is larger than the number of items in theContextMenu, the item is added on to the end of themenu. The first position is 0.- Parameters:
item – the
ContextMenuItemto addposition – the position to insert the item
- last() → ContextMenuItem#
Gets the last item in the
menu.
- move_item(item: ContextMenuItem, position: int) → None#
Moves
itemto the given position in themenu.If
positionis negative, or is larger than the number of items in theContextMenu, the item is added on to the end of themenu. The first position is 0.- Parameters:
item – the
ContextMenuItemto addposition – the new position to move the item
- prepend(item: ContextMenuItem) → None#
Adds
itemat the beginning of themenu.- Parameters:
item – the
ContextMenuItemto add
- remove(item: ContextMenuItem) → None#
Removes
itemfrom themenu.See also
remove_all()to remove all items.- Parameters:
item – the
ContextMenuItemto remove
- set_user_data(user_data: Variant) → None#
Sets user data to
menu.This function can be used from a Web Process extension to set user data that can be retrieved from the UI Process using
get_user_data(). If theuser_dataVariantis floating, it is consumed.Added in version 2.8.
- Parameters:
user_data – a
Variant