Menu Configuration
The deserialize function accepts a dict of action
and menu lists.
Example
import menuet
from menuet.builders.text import Render, TextMenuBuilder
model = menuet.Model()
menuet.deserialize({
"menu": [
{
"label": "Sub-Menu",
"menu": ["My App"],
"group": "Separator",
},
],
"action": [
{
"id": "open-gui",
"label": "Open GUI",
"cb": "import myapp; myapp.open_gui()",
"menu": ["My App", "Sub-Menu"],
},
{
"id": "print-hello",
"label": "Print Hello",
"cb": 'print("Hello")',
},
],
model,
})
builder = TextMenuBuilder(model, root_menu="Example", render=Render.UTF8)
print(builder.build())
Action Options
The [[action]] tables accepts the following options:
[[action]] # `action` is an array of action tables
id = "my-action" # unique identifier [required]
label = "My Action" # display name
menu = ["Menu", "Sub-Menu"] # parent menus hierarchy
group = "My Group" # group related menus and actions
cb = "print('Hello !')" # action callback
desc = "Print Hello" # tooltip
icon = "icons/my-icon.png" # path to an icon
visible = true # display action in menu
enables = true # allow action to be run
Menu Options
The [[menu]] tables accepts the following options:
[[menu]] # `menu` is an array of menu tables
label = "My Menu" # display name [required]
desc = "My App Scripts" # tooltip
menu = ["Parent Menu"] # parent menus hierarchy
group = "My Group" # group related menus and actions
icon = "icons/my-icon.png" # path to an icon
Menus defined in [[action]] tables are created automatically.
The only reason to configure [[menu]] explicitly is to set an icon,
a group, or a desc.
icon Schemes
The icon option accepts a value in the format <path> or <scheme>:<value>.
The following schemes are available:
-
path(default): takes a path to an icon file. -
res: load a resource file. Value is in the formres:importable.module:file.ext.
cb Schemes
The cb option accepts a value in the format <script> or <scheme>:<value>.
The following schemes are available:
-
exec(default): takes a Python script. -
ep: loads an entry point. Value is in the formep:importable.module:callable. -
copy: copy its value to the clipboard.Warning
The
copyscheme requires the copykitten package, available as an extra: -
url: takes a URL and open it in the default browser.