Repository navigation
Toolbar
A row of buttons, toggles, one-of-several groups, text, separators and spacers. When it runs out of room, buttons drop to icons.
from wapyt import ToolbarButton, ToolbarConfig, ToolbarSeparator, ToolbarSpacer, ToolbarText
toolbar = self.add_toolbar("mainwindow_header", ToolbarConfig(items=[
ToolbarButton("new", "New connection", "mdi-plus"),
ToolbarButton("delete", "Delete", "mdi-delete", variant="danger"),
ToolbarSeparator(),
ToolbarButton("tabbed", "Tabs", "mdi-table-row", group="layout", active=True, show_label=False),
ToolbarButton("tiled", "Tiles", "mdi-view-grid", group="layout", show_label=False),
ToolbarSpacer(),
ToolbarButton("update", "Update", "mdi-arrow-up-circle", variant="accent", hidden=True),
ToolbarText("user"),
ToolbarButton("logout", "Logout", "mdi-logout"),
]))
toolbar.on_click(lambda p: self.on_toolbar(p["id"]))
toolbar.set_text("user", me["username"])Layout.add_toolbar(id, toolbar_config) mounts it; id defaults to
MainWindow's mainwindow_header cell. Elsewhere, use
Toolbar(cfg, container=...).
| Item | |
|---|---|
ToolbarButton(id, label, icon, ...) |
A button (options below) |
ToolbarText(id, text, hidden) |
Plain text, such as the signed-in user's name |
ToolbarSeparator() |
A thin divider |
ToolbarSpacer() |
Takes the free space, pushing what follows to the right |
Ids must be unique within a toolbar.
ToolbarButton |
|
|---|---|
label, icon, tooltip
|
Text, MDI class, hover text (defaults to the label); shown as a styled tooltip, also on keyboard focus |
variant |
"default", "primary", "accent" (a highlighted call to action, such as an update notice) or "danger"
|
toggle=True |
Stays pressed until clicked again |
group="..." |
One of several: pressing one releases the rest of its group |
active |
Initial pressed state for toggles and groups |
badge |
A small count or tag; 0 is shown |
disabled, hidden
|
Initial state |
show_label=False |
Icon-only; the label becomes the tooltip and accessible name |
keep_label=True |
Keep the label in compact mode |
Added in #50.
from wapyt import MenuItem
ToolbarButton("export", "Export", "mdi-export", items=[
MenuItem("csv", "CSV"),
MenuItem("json", "JSON"),
MenuItem("more", "More formats", items=[MenuItem("xml", "XML")]),
])
ToolbarButton("run", "Run", "mdi-play", split=True, items=[
MenuItem("run_debug", "Run with debugger", "mdi-bug", shortcut="F5"),
MenuItem("run_profile", "Profile"),
])-
itemsmakes a dropdown: the button opens a menu under it instead of firingon_click. Menu entries are ContextMenuMenuItems, so submenus, separators, shortcut hints,danger,checkableand radiogroupitems all work. -
split=Truekeeps the button a normal command and adds a joined arrow beside it that opens the menu. - A pick fires
on_selectwith{id, menu}, wheremenuis the button's id, pluscheckedfor checkable and group items.on_openfires with{id}as a menu opens, in time to update it. - Ids are unique across the whole toolbar, buttons and menu items together,
so
set_disabled,set_hidden,is_disabledandis_hiddenwork on menu items too.set_checked(id)/is_checked(id)for checkable and group items;set_menu_items(id, items)replaces a menu (recent files, say; an empty menu doesn't open);open_menu(id),close_menu(),is_menu_open(id=None). - A dropdown can't also be a toggle or group button; a split one can, since its main part is still an ordinary button.
on_click → {id, group, active}. active is the new pressed state for
toggle and group buttons, otherwise None; group is None outside a group.
| Method | |
|---|---|
set_hidden(id, hidden=True) |
Show or hide, e.g. a "Reconnect all" button that only matters sometimes |
set_text(id, text) |
Relabel a button ("Reconnect 3") or change a text item |
set_badge(id, badge) |
None or "" removes it |
set_disabled, set_icon, set_tooltip
|
|
set_active(id, active=True), is_active(id), get_active(group)
|
Pressed state |
set_items(items) |
Replace everything |
All text is set as text, never markup.
ToolbarConfig(compact="auto") (the default) watches the toolbar's width.
Once the labelled toolbar no longer fits, buttons with an icon drop their
labels. They come back when there's room for the labelled width again. Labels
remain the tooltip and accessible name. compact="always" or "never" force
it.
Following the WAI-ARIA toolbar pattern, the toolbar is one Tab stop. ←/→ move
between buttons and wrap, Home and End jump to the ends, and Enter or Space
press. Toggles and group buttons expose aria-pressed.
On a dropdown (or a split button's arrow), Enter, Space or ↓ open the menu on its first item and ↑ on its last. In the menu, Escape closes it and returns to the button, and ←/→ close it and move along the toolbar, opening the next dropdown if that is one.
wapyt is MIT-licensed · Repository · pyTincture · Issues
Getting started
Widgets
- Layout and MainWindow
- Tree
- DataTable
- Form
- ModalWindow
- Window
- TabWidget
- Toolbar
- Sidebar
- Chat
- Terminal
- CardPanel
- ResourceBoard
- File Transfer
- Message
- ContextMenu
- MenuBar
- Listbox
- Kanban
- ProgressBar
- Pagination
- Popup and tooltips
- Chart
- Scheduler
- MediaPlayer
Guides
Planning
Contributing