Shortcuts
A searchable, grouped list of key bindings for a Keyboard shortcuts dialog. groups are (title, [(action, keys), ...]) pairs.
ui.shortcuts · Category: Code and tools · Full reference →


pz.container(ui.shortcuts([ ("File", [("Save", "ctrl-s"), ("Open file", "ctrl-p")]), ("View", [("Command palette", "ctrl-shift-p"), ("Toggle left dock", "ctrl-b")]),], on_query=on_query, height=240), width=420)When to use
Section titled “When to use”- Inside a
ui.modalopened from a Help menu or with Ctrl+K Ctrl+S.
import pyzed as pzfrom pyzed import ui
pz.container(ui.shortcuts([ ("File", [("Save", "ctrl-s"), ("Open file", "ctrl-p")]), ("View", [("Command palette", "ctrl-shift-p"), ("Toggle left dock", "ctrl-b")]),], on_query=on_query, height=240), width=420)Variants
Section titled “Variants”Options
Section titled “Options”

Code
pz.container(ui.shortcuts([("File", [("Save", "ctrl-s"), ("Open", "ctrl-o")])], on_query=on_query, height=130), width=360)

query="pal"Code
pz.container(ui.shortcuts([("View", [("Command palette", "ctrl-shift-p"), ("Zoom in", "ctrl-=")])], query="pal", on_query=on_query, height=110), width=360)Events
Section titled “Events”Shortcuts has 1 event of its own, listed below. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.
| Event | Handler gets | When |
|---|---|---|
on_query |
(text) |
Adds a search box. |
Handler gets is what Pyzed passes to your callable: () means nothing. Any handler can also be a message (a value that is not callable), which goes to update().
Handling the events
Section titled “Handling the events”The same events written three ways. Imperative: methods of the app change self. Declarative: the handlers produce messages and one update() decides. Functional: a pure function draws an immutable state and asks for changes with set_state(...). See Imperative, declarative and functional.
class Help(pz.App): def __init__(self): self.query = ""
def view(self): return ui.shortcuts([("File", [("Save", "ctrl-s"), ("Open file", "ctrl-p")])], query=self.query, on_query=lambda q: setattr(self, "query", q)) # adds searchfrom dataclasses import dataclass
@dataclassclass Search: query: str
class Help(pz.App): query = ""
def update(self, message): match message: case Search(query): self.query = query
def view(self): return ui.shortcuts([("File", [("Save", "ctrl-s")])], query=self.query, on_query=Search)from dataclasses import dataclass
@dataclass(frozen=True)class State: query: str = ""
def view(state, set_state): return ui.shortcuts([("File", [("Save", "ctrl-s"), ("Open file", "ctrl-p")])], query=state.query, on_query=lambda q: set_state(query=q))Properties and API
Section titled “Properties and API”ui.shortcuts
Section titled “ui.shortcuts”shortcuts(groups, *, query='', on_query=None, height=380, theme=None)A searchable list of key bindings, grouped (for a Keyboard shortcuts dialog).
| Property | Default | Description |
|---|---|---|
groups |
required | [(title, [(label, keys), ...]), ...], keys like "ctrl-s". |
query |
"" |
Filter text. |
height |
380 |
Height of the list. |
theme |
None |
Theme to use instead of the current one (pyzed.theme.current()). |
Events: on_query (events).