pywry.menu_proxy¶
IPC-backed native menu management.
MenuProxy sends commands to the pytauri subprocess to create, mutate, and
attach native OS menus. See the Native Menus guide for
usage patterns and examples.
pywry.menu_proxy.MenuProxy
¶
Proxy for a native menu living in the pytauri subprocess.
Stores the {item_id: handler} map extracted from items at creation
time. Call :meth:register_handlers with a window label to wire
everything up before the window is shown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
menu_id
|
str
|
The menu identifier (matches the subprocess-side |
required |
handlers
|
dict[str, Callable]
|
Mapping of |
None
|
Attributes¶
Functions¶
create
classmethod
¶
create(menu_id: str, items: list[MenuItemKindConfig] | None = None) -> MenuProxy
Create a native menu in the subprocess.
Handlers are automatically extracted from every item that has one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
menu_id
|
str
|
Unique menu identifier. |
required |
items
|
list of MenuItemKindConfig
|
Initial menu items. Each item must implement |
None
|
Returns:
| Type | Description |
|---|---|
MenuProxy
|
Proxy connected to the created menu. |
from_config
classmethod
¶
from_config(config: MenuConfig) -> MenuProxy
Create a native menu from a :class:MenuConfig.
Handlers are extracted from the config's item tree automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
MenuConfig
|
Complete menu configuration. |
required |
Returns:
| Type | Description |
|---|---|
MenuProxy
|
|
register_handlers
¶
Register all item handlers for a window label.
Installs a single menu:click callback on label that dispatches
to the correct item handler based on data["item_id"].
Safe to call multiple times — duplicate registrations are ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The window label to register handlers on. |
required |
insert
¶
Insert an item at a specific position.
set_checked
¶
Set the checked state of a check menu item.
set_accelerator
¶
Set or clear the keyboard accelerator for a menu item.
set_icon
¶
Set the icon for an icon menu item.
set_as_window_menu
¶
Attach this menu to a specific window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window_label
|
str
|
The target window's label. |
required |
popup
¶
Show this menu as a context menu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window_label
|
str
|
The window to show the popup on. |
required |
x
|
float or None
|
X coordinate (logical pixels). |
None
|
y
|
float or None
|
Y coordinate (logical pixels). |
None
|