skills/setting-up-shortcuts/SKILL.md
ALWAYS LOAD THIS SKILL WHEN ADDING KEYBOARD SHORTCUTS OR HOTKEYS TO A PYSIDE6/QT APP. Do not implement keyboard shortcuts directly — use this skill first. Set up customizable keyboard shortcuts for PySide6 apps with TOML config and platform-specific defaults.
npx skillsauth add quick-brown-foxxx/coding_rules_python setting-up-shortcutsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Reusable keyboard shortcuts system for PySide6 applications. Provides platform-specific defaults, TOML configuration, and Qt integration.
Copy reusable code from coding_rules_python/reusable/shortcuts/ and tests from coding_rules_python/reusable_tests/.
See also: reusable/shortcuts/README.md for full API reference.
# src/myapp/config.py
from shared.shortcuts import ActionShortcut
DEFAULT_SHORTCUTS = (
ActionShortcut("new_file", "New File", "Ctrl+N", "Ctrl+N", "Cmd+N"),
ActionShortcut("save", "Save", "Ctrl+S", "Ctrl+S", "Cmd+S"),
ActionShortcut("quit", "Quit", "Ctrl+Q", "Ctrl+Q", "Cmd+Q"),
ActionShortcut("search", "Search", "Ctrl+F"), # Same on all platforms
)
from shared.shortcuts import ShortcutManager
from pathlib import Path
import platformdirs
manager = ShortcutManager(
config_dir=Path(platformdirs.user_config_dir("myapp")),
app_name="myapp",
default_shortcuts=DEFAULT_SHORTCUTS,
)
from PySide6.QtGui import QAction, QKeySequence
from PySide6.QtWidgets import QMainWindow
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.shortcut_manager = manager
self.shortcut_manager.load()
self._setup_menu()
def _setup_menu(self):
file_menu = self.menuBar().addMenu("&File")
save_action = QAction("&Save", self)
save_action.setShortcut(QKeySequence(self.shortcut_manager.get_shortcut("save")))
save_action.triggered.connect(self._save)
file_menu.addAction(save_action)
Immutable definition of a keyboard shortcut with platform-specific defaults:
ActionShortcut(
action_id="save", # Unique ID (snake_case)
display_name="Save", # Human-readable name for UI
default_linux="Ctrl+S", # Linux default
default_windows="Ctrl+S", # Windows default (falls back to Linux if empty)
default_macos="Cmd+S", # macOS default (falls back to Linux if empty)
)
Uses Qt's QKeySequence string format:
Ctrl, Shift, Alt, MetaReturn (NOT Enter), Backspace, Delete, Tab, Escape, Space, F1-F35Left, Right, Up, Down, Home, End, PageUp, PageDown+: Ctrl+Shift+S, Alt+LeftImportant: Always use "Return" for the Enter key, NOT "Enter" (which maps to numpad Enter on some platforms).
Auto-created at <config_dir>/<app_name>_shortcuts.toml:
# Edit keyboard shortcuts using Qt QKeySequence string format.
# MODIFIERS: Ctrl, Shift, Alt, Meta (use '+' to combine)
# SPECIAL KEYS: Return (Enter key), Backspace, Delete, Tab, Escape, Space, F1-F35
[shortcuts]
new_file = "Ctrl+N"
save = "Ctrl+S"
quit = "Ctrl+Q"
search = "" # Empty string disables the shortcut
[project]
dependencies = [
"pyside6>=6.10.1",
"rusty-results>=1.1.1",
"tomli>=2.2.1",
"tomli-w>=1.2.0",
]
From coding_rules_python/reusable/:
shortcuts/__init__.py — public API exportsshortcuts/shortcuts.py — ActionShortcut, ShortcutConfig, ShortcutManagershortcuts/README.md — full API referenceFrom coding_rules_python/reusable_tests/ → copy into your tests/:
test_shortcuts_base.py — generic tests for ActionShortcut, ShortcutConfig, validationtest_shortcuts_manager.py — generic tests for ShortcutManagerUpdate import paths after copying (e.g., reusable.shortcuts → shared.shortcuts, reusable.shortcuts.shortcuts → shared.shortcuts.shortcuts in monkeypatch paths).
The reusable tests cover all generic behavior. For app-specific tests:
# tests/test_my_shortcuts.py
from reusable_tests.test_shortcuts_base import (
TestActionShortcut,
TestShortcutConfig,
TestShortcutConfigSave,
TestValidateKeySequence,
)
# Inherit generic tests — they run automatically
class TestMyActionShortcut(TestActionShortcut):
pass
# Add app-specific tests
class TestMyAppShortcuts:
def test_default_shortcuts_are_valid(self):
from myapp.config import DEFAULT_SHORTCUTS
for shortcut in DEFAULT_SHORTCUTS:
assert shortcut.action_id
assert shortcut.display_name
development
ALWAYS LOAD THIS SKILL WHEN A NEW FEATURE, NON-TRIVIAL FIX, REFACTOR, OR PYTHON STRUCTURE CHANGE REQUIRES AN ARCHITECTURE DECISION ABOUT LAYERS, WRAPPERS, COMPOSITION ROOTS, FRAMEWORK CHOICES, REUSABLE CORES, OR WHERE CODE SHOULD LIVE. Do not make Python architecture decisions blindly — use this skill first. Python architecture guide + skill router for boundary placement, reusable core design, composition vs inheritance, framework vs custom choices, backend/service layering, and follow-up docs/skills.
tools
ALWAYS LOAD THIS SKILL WHEN CREATING ANY STANDALONE PYTHON SCRIPT OR SINGLE-FILE AUTOMATION. Do not create Python scripts directly — use this skill first. Single-file Python scripts with PEP 723 inline metadata, uv run, and typer CLI.
development
ALWAYS LOAD THIS SKILL WHEN WRITING OR EDITING PYTHON CODE. Do not write or modify Python files directly — use this skill first. Core Python standards: basedpyright strict typing, Result-based error handling, async patterns, security, code style.
development
ALWAYS LOAD THIS SKILL WHEN WRITING TESTS, ADDING FIXTURES, OR SETTING UP PYTEST. Do not write Python tests directly — use this skill first. Python testing with pytest: philosophy, fixtures, mock servers, containerized testing.