instrumentserver.gui.shortcuts#
Classes
Manages keyboard shortcut mappings for the instrument GUI. |
|
|
Permanent widget for viewing and editing keyboard shortcuts. |
- class instrumentserver.gui.shortcuts.KeyboardShortcutManager[source]#
Bases:
objectManages keyboard shortcut mappings for the instrument GUI.
Holds a registry of named actions with default key sequences and descriptions. The active mapping starts from defaults and can be customized by the user and persisted to a JSON file.
Qt does not poll for key presses — instead, register() hands each mapping entry to Qt’s event system via QShortcut, which fires the associated callback when the key is pressed. register_tooltip() tracks widgets whose tooltips should display the current key hint and be updated live when the user rebinds.
- REGISTRY: dict[str, tuple[str, str]] = {'add_item': ('Ctrl+N', 'Jump cursor to the add parameter bar'), 'clear_add': ('Ctrl+Shift+N', 'Clear regions of add parameter bar'), 'collapse_all': ('Ctrl+Shift+E', 'Collapse all tree nodes'), 'delete_item': ('Ctrl+Backspace', 'Delete the selected parameter'), 'edit_value': ('Right', 'Jump cursor to value field for selected parameter'), 'expand_all': ('Ctrl+E', 'Expand all tree nodes'), 'fit_column': ('Ctrl+Shift+D', 'Fits column width'), 'jump_filter': ('Ctrl+F', 'Jump cursor to the filter search bar'), 'load_items': ('Ctrl+Shift+O', 'Load parameters from JSON file'), 'refresh_all': ('Ctrl+Shift+R', 'Refresh all parameters from instrument'), 'refresh_item': ('Ctrl+R', 'Refresh the selected parameter'), 'run_method': ('Ctrl+Return', 'Runs the selected method'), 'save_items': ('Ctrl+Shift+S', 'Save parameters to JSON file'), 'sort_column': ('Ctrl+D', 'Toggle sorting of selected column'), 'star_item': ('Ctrl+A', 'Star/un-star the selected parameter'), 'toggle_python': ('Ctrl+P', 'Toggle Python eval for selected parameter'), 'toggle_star': ('Ctrl+Shift+A', 'Toggle star filter'), 'toggle_trash': ('Ctrl+Shift+T', 'Toggle trash filter'), 'trash_item': ('Ctrl+T', 'Trash/un-trash the selected parameter')}#
- load_from_dict(config: dict[str, str]) None[source]#
Override the current mapping with entries read from serverConfig file.
- rebind(action_id: str, new_key: str) None[source]#
Update a shortcut immediately. Updates the mapping and the live Qt objects.
- register(action_id: str, callback: Callable, widget: QWidget) None[source]#
Create a QShortcut for action_id on widget and connect it to callback.
The shortcut fires when widget or any of its children has focus. The QShortcut object is retained internally so it is not garbage-collected and can be updated live via rebind().
- class instrumentserver.gui.shortcuts.ShortcutEditorWidget(manager: KeyboardShortcutManager, configPath: str, parent: QWidget | None = None)[source]#
Bases:
QWidgetPermanent widget for viewing and editing keyboard shortcuts.
Intended to be embedded as a tab in the server window. Changes made in the table are applied live to the manager (and therefore all registered shortcuts) when ‘Save to File’ is clicked. Also use ‘Save to file’ to persist across sessions.
- Each row has a small colored indicator dot in the rightmost column:
transparent : saved and unique
orange: unsaved change (widget value differs from manager.mapping)
yellow: applied to the manager but not yet saved to file
red : duplicate key sequence shared with another action (takes priority)
QKeySequenceEdit emits a spurious keySequenceChanged after its finishing timeout resets the internal recording state. _onEditingFinished blocks that widget’s signals for one event-loop tick (swallowing the revert signal at the source), then restores the display if the widget actually changed its stored sequence during the block.