bootstack.shortcuts.Shortcuts#
- class bootstack.shortcuts.Shortcuts#
Bases:
objectSingleton service for managing keyboard shortcuts.
Provides cross-platform keyboard shortcut registration and binding. The service automatically translates modifier keys for each platform:
ModbecomesCtrlon Windows/Linux,Commandon MacAltbecomesAlton Windows/Linux,Optionon MacShiftworks the same on all platforms
Examples
shortcuts = get_shortcuts() # Register shortcuts shortcuts.register("save", "Mod+S", save_file) shortcuts.register("undo", "Mod+Z", undo) shortcuts.register("find", "Mod+F", find) # Bind all to window shortcuts.bind_to(app) # Get display string for menu shortcuts.display("save") # "Ctrl+S" on Windows, "⌘S" on Mac
- all()#
Get all registered shortcuts.
- bind_to(window)#
Bind all registered shortcuts to a window.
- Parameters:
window (Any) – The window (App, Toplevel, Tk) to bind shortcuts to.
Note
Shortcuts registered after calling bind_to will also be automatically bound to this window.
- binding(key)#
Get Tkinter binding string for a shortcut key.
- display(key)#
Get display string for a shortcut key.
- get(key)#
Get a shortcut by key.
- register(key, pattern, command)#
Register a keyboard shortcut.
- Parameters:
- Returns:
The created Shortcut object.
- Raises:
ValueError – If key is already registered.
- Return type:
Examples
shortcuts.register("save", "Mod+S", save_file) shortcuts.register("quit", "Mod+Q", app.quit) shortcuts.register("refresh", "F5", refresh)