Skip to content

Conversation

@jnsebgosselin
Copy link
Member

@jnsebgosselin jnsebgosselin commented Dec 3, 2025

Add Centralized Shortcut Manager

This PR introduces a ShortcutManager for centralized keyboard shortcut handling in Qt applications.

Features

  • Two-phase shortcut management: Declare shortcuts at startup (before UI exists), then bind them when lazy-loaded UI is created
  • UserConfig integration: Automatically loads/saves user-customized shortcuts
  • Conflict detection: Prevents duplicate key bindings within the same context, with support for global (_) context
  • UI synchronization: Auto-updates tooltips, titles, and menu text when shortcuts change via sync translators (ActionMenuSyncTranslator, TitleSyncTranslator, ToolTipSyncTranslator)

Usage

manager = ShortcutManager(userconfig=config)

# Declare shortcuts (even before UI exists)
manager.declare_shortcut(context="file", name="save", default_key_sequence="Ctrl+S")

# Bind when UI is ready
manager.bind_shortcut(
    context="file", name="save",
    callback=self.save_file,
    parent=widget,
    synced_ui_data=[(button.setText, TitleSyncTranslator("Save"))]
)

Changes

  • Added qtapputils/managers/shortcuts.py
  • Added comprehensive tests in qtapputils/managers/tests/test_shortcut_manager.py
  • Updated managers/__init__.py with lazy imports
  • Minor updates to qthelpers.format_tooltip() to support {sc_str} placeholder

@jnsebgosselin jnsebgosselin self-assigned this Dec 3, 2025
@jnsebgosselin jnsebgosselin added this to the 0.10.0 milestone Dec 3, 2025
@jnsebgosselin jnsebgosselin merged commit fd01424 into main Dec 18, 2025
1 check passed
@jnsebgosselin jnsebgosselin deleted the add_shortcut_manager branch December 18, 2025 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants