def test_shortcuts(): shortcuts = Shortcuts() assert shortcuts["new"] == shortcuts[0] assert shortcuts["new"] == QKeySequence.fromString("Ctrl+N") shortcuts["new"] = QKeySequence.fromString("Ctrl+Shift+N") assert shortcuts["new"] == QKeySequence.fromString("Ctrl+Shift+N") assert list(shortcuts[0:2].keys()) == ["new", "open"]
def load(cls, settings: QSettings): return cls(close_to_systray=settings.value("close_to_systray", True, bool), use_global_hotkey=settings.value("use_global_hotkey", False, bool), global_hotkey=QKeySequence.fromString( settings.value("global_hotkey", "", str)), external_editor=settings.value("external_editor", ""))
def _process_shortcut_dict(self, shortcuts: dict) -> dict: for action in shortcuts.keys(): # Ignore shortcuts which aren't in currently supported list if action not in self._names: continue # Use "" if there's no shortcut set key_string = shortcuts.get(action, None) key_string = "" if key_string is None else key_string if not key_string.strip(): shortcuts[action] = "" continue try: shortcuts[action] = eval(key_string) except: shortcuts[action] = QKeySequence.fromString(key_string) return shortcuts
def get_keycode(keycomb: str): keyseq = QKeySequence.fromString(keycomb) return keyseq[0]