ContextMenu#
Superclasses: Object
Represents the context menu in a WebKitWebView
.
ContextMenu
represents a context menu containing
ContextMenuItem`<!-- -->s in a ``WebKitWebView`
.
When a WebKitWebView
is about to display the context menu, it
emits the WebKitWebView
::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 prepend
, append()
or
insert()
, maybe after having removed the
existing ones with remove_all()
.
Constructors#
- class ContextMenu
- classmethod new() → ContextMenu#
Creates a new
ContextMenu
object.Creates a new
ContextMenu
object to be used as a submenu of an existingContextMenu
. The context menu of aWebKitWebView
is created by the view and passed as an argument ofWebKitWebView
::context-menu signal. To add items to the menu useprepend()
,append()
orinsert()
. See alsonew_with_items()
to create aContextMenu
with a list of initial items.
- classmethod new_with_items(items: list[ContextMenuItem]) → ContextMenu#
Creates a new
ContextMenu
object with the given items.Creates a new
ContextMenu
object to be used as a submenu of an existingContextMenu
with the given initial items. See alsonew()
- Parameters:
items – a
List
ofContextMenuItem
Methods#
- class ContextMenu
- append(item: ContextMenuItem) → None#
Adds
item
at the end of themenu
.- Parameters:
item – the
ContextMenuItem
to add
- first() → ContextMenuItem#
Gets the first item in the
menu
.
- get_event() → Event#
Gets the
Event
that triggered the context menu. This function only returns a validEvent
when called for aContextMenu
passed toWebKitWebView
::context-menu signal; in all other cases,None
is returned.The returned
Event
is expected to be one of the following types: <itemizedlist> <listitem><para> aGdkEventButton
of type%GDK_BUTTON_PRESS
when the context menu was triggered with mouse. </para></listitem> <listitem><para> aGdkEventKey
of type%GDK_KEY_PRESS
if the keyboard was used to show the menu. </para></listitem> <listitem><para> a genericEvent
of 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
item
into themenu
at the given position.If
position
is 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
ContextMenuItem
to addposition – the position to insert the item
- last() → ContextMenuItem#
Gets the last item in the
menu
.
- move_item(item: ContextMenuItem, position: int) → None#
Moves
item
to the given position in themenu
.If
position
is 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
ContextMenuItem
to addposition – the new position to move the item
- prepend(item: ContextMenuItem) → None#
Adds
item
at the beginning of themenu
.- Parameters:
item – the
ContextMenuItem
to add
- remove(item: ContextMenuItem) → None#
Removes
item
from themenu
.See also
remove_all()
to remove all items.- Parameters:
item – the
ContextMenuItem
to 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_data
Variant
is floating, it is consumed.Added in version 2.8.
- Parameters:
user_data – a
Variant