Menu Configuration¶
The load function takes a dict of
{ "action": [], "menu": [] }.
import menuet
from menuet.builders.text import Render, TextMenuBuilder
model = menuet.Model()
load(
{
"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
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.
JSON Schema¶
Menuet provides its own JSON Schema. If your editor supports TOML schema validation, it's recommended to set it up to enable validation diagnostics and auto-complete when editing a menu file:
Both tombi
and taplo supports the #:schema directive to
specify the schema to use for the document.
Add the comment directive at the beginning of the document, followed by a blank line.
Sub Schema¶
Tombi can be configured with sub schema to apply a schema to a specific part of the TOML document.