Menu & Toolbar Widgets¶
MenuBar¶
Horizontal menu bar, typically placed at the top of a window.
Constructor: new Widgets.MenuBar()
Methods:
Method |
Description |
|---|---|
|
Add a Menu with a display name. |
|
Add a menu by name (creates and returns a new Menu). |
|
Return the Menu object for a given name. |
Callbacks: None.
let menubar = new Widgets.MenuBar();
let fileMenu = menubar.add_name("File");
fileMenu.add_name("Open");
fileMenu.add_name("Save");
fileMenu.add_separator();
fileMenu.add_name("Quit");
Menu¶
Dropdown menu with actions, sub-menus, and separators.
Constructor: new Widgets.Menu()
Methods:
Method |
Description |
|---|---|
|
Add a MenuAction or other widget. |
|
Add a named action (returns the MenuAction). |
|
Add a sub-menu. |
|
Add a visual separator. |
|
Show as a context menu at the current pointer position. |
Callbacks: None.
let menu = new Widgets.Menu();
let openAction = menu.add_name("Open");
openAction.add_callback('activated', (w) => openFile());
menu.add_separator();
let checkItem = menu.add_name("Auto-save", true);
MenuAction¶
A single action item inside a Menu.
Constructor: new Widgets.MenuAction({text, icon_url, iconsize, checkable, name})
Options:
text– display texticon_url– icon image URLiconsize– icon size in pixelscheckable– whether the action has a check statename– internal name
Methods:
Method |
Description |
|---|---|
|
Set or get display text. |
|
Set icon. |
|
Set or get check state (if checkable). |
Callbacks:
activated– fired when the action is clicked. Handler signature ishandler(widget)for non-checkable actions andhandler(widget, checked)for checkable ones (the boolean is the new checked state).
ToolBar¶
Toolbar with buttons, toggles, spacers, and separators.
Constructor: new Widgets.ToolBar({orientation})
Options:
orientation–"horizontal"(default) or"vertical"
Methods:
Method |
Description |
|---|---|
|
Add any widget to the toolbar. |
|
Add a visual separator. |
|
Add a flexible spacer. |
|
Add a ToolBarAction (returns the action). |
Callbacks: None.
let toolbar = new Widgets.ToolBar();
let newBtn = toolbar.add_action({text: "New", icon_url: "icons/new.svg"});
toolbar.add_separator();
let boldBtn = toolbar.add_action({text: "B", toggle: true, group: "fmt"});
ToolBarAction¶
A button/toggle inside a ToolBar.
Constructor: new Widgets.ToolBarAction({text, icon_url, iconsize, toggle, group})
Options:
text– display texticon_url– icon image URLiconsize– icon size in pixelstoggle– two-state toggle modegroup– exclusive group name
Methods:
Method |
Description |
|---|---|
|
Set or get display text. |
|
Set icon. |
|
Set or get toggle state. |
Callbacks:
activated– fired when the action is clicked or toggled.