Class PopupMenu

class ooodev.gui.menu.PopupMenu(component, lo_inst=None)[source]

Bases: LoInstPropsPartial, PopupMenuComp

Popup Menu Class.

Parameters:
  • component (XPopupMenu) –

  • lo_inst (LoInst | None) –

__init__(component, lo_inst=None)[source]

Initializes the instance.

Parameters:
  • component (XPopupMenu) – The popup menu component.

  • lo_inst (LoInst, optional) – LoInst, Defaults to Lo.current_lo.

Return type:

None

add_event_item_activated(cb)

Adds a callback for the item activated event for all menu items in the current instance.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

add_event_item_deactivated(cb)

Adds a callback for the item deactivated event for all menu items in the current instance.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

add_event_item_highlighted(cb)

Adds a callback for the item highlighted event for all menu items in the current instance.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

add_event_item_selected(cb)

Adds a callback for the item selected event for all menu items in the current instance.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

add_event_menu_events_disposing(cb)

Adds a callback for the menu events disposing event for all menu items in the current instance.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

add_menu_listener(listener)

adds the specified menu listener to receive events from this menu.

Return type:

None

Parameters:

listener (com.sun.star.awt.XMenuListener) –

check_item(menu_id, check=True)

Sets the state of the item to be checked or unchecked.

Parameters:
  • menu_id (int) – The item identifier.

  • check (bool, optional) – The state of the item. Defaults to True.

Return type:

None

clear()[source]

Removes all items from the menu.

Return type:

None

enable_auto_mnemonics(enable)

Specifies whether mnemonics are automatically assigned to menu items, or not.

Return type:

None

Parameters:

enable (bool) –

enable_item(menu_id, enable=False)

Enables or disables the menu item.

Parameters:
  • menu_id (int) – The ID of the menu item.

  • enable (bool, optional) – The state of the menu item. Defaults to False.

Return type:

None

end_execute()

Ends the execution of the PopupMenu.

XPopupMenu.execute() will then return 0.

Return type:

None

execute(parent, position, direction=0)

Executes the popup menu and returns the selected item or 0, if cancelled.

Parameters:
  • parent (XWindowPeer) – The parent window.

  • position (Rectangle) – The position of the popup menu.

  • direction (int | PopupMenuDirectionEnum, optional) – The direction of the popup menu. Defaults to 0.

Returns:

The selected item or 0 if cancelled.

Return type:

int

Hint

  • PopupMenuDirectionEnum is an enum that can be imported from ooo.dyn.awt.popup_menu_direction.

Note

direction values:

  • EXECUTE_DEFAULT = 0

  • EXECUTE_DOWN = 1

  • EXECUTE_UP = 2

  • EXECUTE_LEFT = 4

  • EXECUTE_RIGHT = 8

execute_cmd(cmd, in_thread=False)[source]

Executes a command.

Parameters:
  • cmd (str, int) – Command or the Menu id to get the command from that is to be executed.

  • in_thread (bool) –

Return type:

bool

find_item_menu_id(cmd, search_sub_menu=False)[source]

Find item menu id by command.

Parameters:
  • cmd (str) – A menu command such as .uno:Copy.

  • search_sub_menu (bool, optional) – Search in sub menus. Defaults to False.

Returns:

The id of the menu item. If not found, return -1.

Return type:

int

See also

find_item_pos(cmd, search_sub_menu=False)[source]

Find item position by command.

Parameters:
  • cmd (str) – A menu command such as .uno:Copy.

  • search_sub_menu (bool, optional) – Search in sub menus. Defaults to False.

Returns:

The position of the menu item and the Popup Menu that command was found in. If not found, return (-1, None).

Return type:

Tuple[int, PopupMenu | None]

classmethod from_lo(lo_inst=None)

Creates the instance from the Lo.

Parameters:

lo_inst (LoInst, optional) – LoInst, Defaults to Lo.current_lo.

Returns:

The instance.

Return type:

PopupMenuComp

get_accelerator_key_event(menu_id)

Gets the KeyEvent for the menu item.

The KeyEvent is only used as a container to transport the shortcut information, so that in this case com.sun.star.lang.EventObject.Source is None.

Return type:

KeyEvent

Parameters:

menu_id (int) –

get_command(menu_id)

Gets the command string for the menu item.

Return type:

str

Parameters:

menu_id (int) –

get_default_item()

Gets the menu default item.

Return type:

int

get_help_command(menu_id)

Gets the help command string for the menu item.

Return type:

str

Parameters:

menu_id (int) –

get_help_text(menu_id)

Gets the help text for the menu item.

Return type:

str

Parameters:

menu_id (int) –

get_item_count()

Gets the number of items in the menu.

Return type:

int

get_item_id(item_pos)

Gets the ID of the item at the specified position.

Return type:

int

Parameters:

item_pos (int) –

get_item_image(menu_id)

Gets the image for the menu item.

Return type:

XGraphic

Parameters:

menu_id (int) –

get_item_pos(menu_id)

Gets the position of the item with the specified ID.

Return type:

int

Parameters:

menu_id (int) –

get_item_text(menu_id)

returns the string for the given item id.

Return type:

str

Parameters:

menu_id (int) –

get_item_type(item_pos)

Gets the type of the menu item.

Parameters:

item_pos (int) – The position of the menu item.

Returns:

The type of the menu item.

Return type:

MenuItemType

Hint

  • MenuItemType is an enum and can be imported from ooo.dyn.awt.menu_item_type.

get_max_menu_id()[source]

Gets the maximum menu id.

Returns:

The maximum menu id.

Return type:

int

get_popup_menu(menu_id)[source]

Gets the popup menu from the menu item.

Parameters:

menu_id (int) – Menu item id.

Returns:

PopupMenu instance if found, otherwise None.

Return type:

PopupMenu

get_tip_help_text(item_id)

retrieves the tip help text for the menu item.

Return type:

str

Parameters:

item_id (int) –

hide_disabled_entries(hide=True)

Specifies whether disabled menu entries should be hidden, or not.

Parameters:

hide (bool, optional) – True to hide disabled entries, False to show them. Defaults to True.

Return type:

None

insert_item(menu_id, text, item_style=0, item_pos=-1)[source]

Insert an item into the menu.

Parameters:
  • menu_id (int) – Menu item id. If set to -1, it will be set to the maximum menu id + 1.

  • text (str) – Text of the menu item.

  • item_style (int | MenuItemStyleKind) – Style Kind. Defaults to 0 (none).

  • item_pos (int) – Index position of the new item. Can be a negative value to index from the end of the list. Defaults to -1.

Returns:

Menu item id.

Return type:

int

insert_item_after(menu_id, text, item_style=0, after=-1)[source]

Insert an item into the menu.

Parameters:
  • menu_id (int) – Menu item id. If set to -1, it will be set to the maximum menu id + 1.

  • text (str) – Text of the menu item.

  • item_style (int | MenuItemStyleKind) – Style Kind. Defaults to 0 (none).

  • after (str | int) – Index of existing item or command to insert after. Can be a negative value to index from the end of the list. Defaults to -1.

Raises:

ValueError – ValueError if after Item not found.

Returns:

Menu item id.

Return type:

int

insert_separator(item_pos)

Inserts a separator at the specified position.

Return type:

None

Parameters:

item_pos (int) –

is_dispatch_cmd(cmd)[source]

Check if a command is a dispatch command.

Parameters:

cmd (str, int) – Command or the Menu id to get the command from that is to be checked.

Returns:

True if it is a dispatch command; Otherwise, False.

Return type:

bool

is_in_execute()

Queries if the PopupMenu is being.

Returns True only if the PopupMenu is being executed as a result of invoking`` XPopupMenu.execute()``; that is, for a PopupMenu activated by a MenuBar item, this methods returns False.

Return type:

bool

is_item_checked(menu_id)

Gets whether the item is checked or unchecked.

Return type:

bool

Parameters:

menu_id (int) –

is_item_enabled(menu_id)

Gets the state of the menu item.

Return type:

bool

Parameters:

menu_id (int) –

is_popup_menu()

Checks whether an XMenu is an XPopupMenu.

Return type:

bool

remove_event_item_activated(cb)

Removes a callback for the item activated event for all menu items in the current instance.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

remove_event_item_deactivated(cb)

Removes a callback for the item deactivated event for all menu items in the current instance.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

remove_event_item_highlighted(cb)

Removes a callback for the item highlighted event for all menu items in the current instance.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

remove_event_item_selected(cb)

Removes a callback for the item selected event for all menu items in the current instance.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

remove_event_menu_events_disposing(cb)

Removes a callback for the menu events disposing event for all menu items in the current instance.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

remove_item(item_pos, count)[source]

Removes one or more items from the menu.

Return type:

None

Parameters:
  • item_pos (int) –

  • count (int) –

remove_menu_listener(listener)

Removes the specified menu listener so that it no longer receives events from this menu.

Return type:

None

Parameters:

listener (com.sun.star.awt.XMenuListener) –

set_accelerator_key_event(menu_id, key_event)

Sets the KeyEvent for the menu item.

The KeyEvent is only used as a container to transport the shortcut information, this methods only draws the text corresponding to this keyboard shortcut. The client code is responsible for listening to keyboard events (typically done via XUserInputInterception), and dispatch the respective command.

Return type:

None

Parameters:
  • menu_id (int) –

  • key_event (com.sun.star.awt.KeyEvent) –

set_command(menu_id, command)

Sets the command string for the menu item.

Return type:

None

Parameters:
  • menu_id (int) –

  • command (str) –

set_default_item(menu_id)

Sets the menu default item.

Return type:

None

Parameters:

menu_id (int) –

set_help_command(menu_id, command)

Sets the help command string for the menu item.

Return type:

None

Parameters:
  • menu_id (int) –

  • command (str) –

set_help_text(menu_id, text)

Sets the help text for the menu item.

Return type:

None

Parameters:
  • menu_id (int) –

  • text (str) –

set_item_image(menu_id, graphic, scale)

Sets the image for the menu item.

Return type:

None

Parameters:
  • menu_id (int) –

  • graphic (com.sun.star.graphic.XGraphic) –

  • scale (bool) –

set_item_text(menu_id, text)

Sets the text for the menu item.

Return type:

None

Parameters:
  • menu_id (int) –

  • text (str) –

set_popup_menu(menu_id, popup_menu)[source]

Sets the popup menu for a specified menu item.

Parameters:
  • menu_id (int) – Menu item id.

  • popup_menu (XPopupMenu | ComponentProp) – Popup menu.

Return type:

None

set_tip_help_text(menu_id, text)

Sets the tip help text for the menu item.

Return type:

None

Parameters:
  • menu_id (int) –

  • text (str) –

subscribe_all_item_activated(cb)

Adds a callbacks for the item activated event for all menu and submenus items.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

subscribe_all_item_deactivated(cb)

Adds a callbacks for the item deactivated event for all menu and submenus items.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

subscribe_all_item_highlighted(cb)

Adds a callbacks for the item highlighted event for all menu and submenus items.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

subscribe_all_item_selected(cb)

Adds a callbacks for the item selected event for all menu and submenus items.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

unsubscribe_all_item_activated(cb)

Remove callbacks for the item selected event for all menu and submenus items.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

unsubscribe_all_item_deactivated(cb)

Remove callbacks for the item deactivated event for all menu and submenus items.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

unsubscribe_all_item_highlighted(cb)

Remove callbacks for the item highlighted event for all menu and submenus items.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

unsubscribe_all_item_selected(cb)

Remove callbacks for the item selected event for all menu and submenus items.

Parameters:

cb (Callable[[Any, EventArgs, PopupMenuComp], None]) – Callback function.

Return type:

None

property cache: LRUCache

Gets the cache.

Returns:

Cache.

Return type:

LRUCache

property component: com.sun.star.awt.PopupMenu

PopupMenu Component

Return type:

PopupMenu

property events_listener_menu: MenuListener

Returns listener

Return type:

MenuListener

property lo_inst: LoInst

Lo Instance

Return type:

LoInst