KeyCombination
Qt Base Class: QKeyCombination
Signature: QKeyCombination(self, arg__1: Union[PySide6.QtCore.QKeyCombination, PySide6.QtCore.Qt.KeyboardModifier, PySide6.QtCore.Qt.Key]) -> None
QKeyCombination(self, key: PySide6.QtCore.Qt.Key = Instance(Qt.Key_unknown)) -> None
QKeyCombination(self, modifiers: PySide6.QtCore.Qt.KeyboardModifier, key: PySide6.QtCore.Qt.Key = Instance(Qt.Key_unknown)) -> None
QKeyCombination(self, modifiers: PySide6.QtCore.Qt.Modifier, key: PySide6.QtCore.Qt.Key) -> None
Base classes
Name |
Children |
Inherits |
SerializeMixin prettyqt.utils.serializemixin
|
|
|
QKeyCombination PySide6.QtCore QKeyCombination(self, arg__1: Union[PySide6.QtCore.QKeyCombination, PySide6.QtCore.Qt.KeyboardModifier, PySide6.QtCore.Qt.Key]) -> None |
|
|
⋔ Inheritance diagram
graph TD
1473299902864["core.KeyCombination"]
1473299806240["utils.SerializeMixin"]
140713234304496["builtins.object"]
1473243620256["QtCore.QKeyCombination"]
1473291690208["Shiboken.Object"]
1473299806240 --> 1473299902864
140713234304496 --> 1473299806240
1473243620256 --> 1473299902864
1473291690208 --> 1473243620256
140713234304496 --> 1473291690208
🛈 DocStrings
Bases: SerializeMixin
, QKeyCombination
Stores a combination of a key with optional modifiers.
Source code in prettyqt\core\keycombination.py
| class KeyCombination(serializemixin.SerializeMixin, QtCore.QKeyCombination):
"""Stores a combination of a key with optional modifiers."""
def __init__(self, *args, **kwargs):
match args:
case (str(),) if args[0] in MODIFIERS.inverse.values():
mods = args[0].split("+")
qtmod = functools.reduce(or_, [MODIFIERS[m] for m in mods])
super().__init__(qtmod, Keys.No)
return
case (str(),):
*mods, btn = args[0].split("+")
# get modifiler
qtmod = (
functools.reduce(or_, [MODIFIERS[m] for m in mods])
if mods
else Mod.NoModifier
)
# get button
if btn in _SYMBOLS:
btn = _SYMBOLS[btn]
if btn.isalnum():
btn = btn.upper()
qtkey = getattr(Key, f"Key_{btn}") if btn != "{}" else Keys.Any
super().__init__(qtmod, qtkey)
case (QtCore.QEvent(),):
modifier = args[0].modifiers()
modifier ^= Mod.KeypadModifier
key = args[0].key()
if key in MODIFIER_KEYS: # modifier only
key = Keys.No
super().__init__(key, modifier)
case _:
super().__init__(*args, **kwargs)
def __eq__(self, other):
if isinstance(other, str | Key):
other = KeyCombination(other)
return super().__eq__(other)
def __add__(self, other):
from prettyqt import gui
return gui.KeySequence(self, other)
def __repr__(self):
return get_repr(self, self.key(), self.keyboardModifiers())
def is_typing(self) -> bool:
"""True if key is a letter or number."""
mod_ok = self.keyboardModifiers() in (Mod.NoModifier, Mod.ShiftModifier)
key = self.key()
key_ok = (
Key.Key_Exclam <= key <= Key.Key_ydiaeresis
or Keys.ALPHA <= key <= Keys.OMEGA
or Keys.CYR_A <= key <= Keys.CYR_YA
)
return mod_ok and key_ok
def is_moving(self) -> bool:
"""True if arrows are pushed."""
return self.key() in ARROW_KEYS
def is_moving_func(self) -> bool:
"""True if function arrows are pushed."""
return self.key() in FUNC_ARROW_KEYS
def has_modifier(self, modifier: constants.KeyboardModifierStr) -> bool:
"""True if keycombo contains modifier."""
return bool(self.keyboardModifiers() & constants.KEYBOARD_MODIFIERS[modifier])
def has_key(self) -> bool:
"""True if non-modifier key is pressed."""
return self.key() != Keys.No
def get_key(self) -> constants.KeyStr:
return constants.KEY.inverse[self.key()]
def get_modifiers(self) -> list[constants.KeyboardModifierStr]:
return constants.KEYBOARD_MODIFIERS.get_list(self.keyboardModifiers())
|
has_key() -> bool
True if non-modifier key is pressed.
Source code in prettyqt\core\keycombination.py
| def has_key(self) -> bool:
"""True if non-modifier key is pressed."""
return self.key() != Keys.No
|
has_modifier(modifier: constants.KeyboardModifierStr) -> bool
True if keycombo contains modifier.
Source code in prettyqt\core\keycombination.py
| def has_modifier(self, modifier: constants.KeyboardModifierStr) -> bool:
"""True if keycombo contains modifier."""
return bool(self.keyboardModifiers() & constants.KEYBOARD_MODIFIERS[modifier])
|
is_moving() -> bool
True if arrows are pushed.
Source code in prettyqt\core\keycombination.py
| def is_moving(self) -> bool:
"""True if arrows are pushed."""
return self.key() in ARROW_KEYS
|
is_moving_func() -> bool
True if function arrows are pushed.
Source code in prettyqt\core\keycombination.py
| def is_moving_func(self) -> bool:
"""True if function arrows are pushed."""
return self.key() in FUNC_ARROW_KEYS
|
is_typing() -> bool
True if key is a letter or number.
Source code in prettyqt\core\keycombination.py
| def is_typing(self) -> bool:
"""True if key is a letter or number."""
mod_ok = self.keyboardModifiers() in (Mod.NoModifier, Mod.ShiftModifier)
key = self.key()
key_ok = (
Key.Key_Exclam <= key <= Key.Key_ydiaeresis
or Keys.ALPHA <= key <= Keys.OMEGA
or Keys.CYR_A <= key <= Keys.CYR_YA
)
return mod_ok and key_ok
|