From a6656085b49d2506b01e5ebef82dc70088b7231e Mon Sep 17 00:00:00 2001 From: Hanjin Liu Date: Tue, 10 Jan 2023 20:26:20 +0900 Subject: [PATCH 1/3] support Greek characters --- tabulous/_keymap/_keymap.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tabulous/_keymap/_keymap.py b/tabulous/_keymap/_keymap.py index fc94b375..71d6e49e 100644 --- a/tabulous/_keymap/_keymap.py +++ b/tabulous/_keymap/_keymap.py @@ -141,6 +141,8 @@ class ExtKey: FUNC_ARROW_KEYS = frozenset( {Qt.Key.Key_Home, Qt.Key.Key_End, Qt.Key.Key_PageUp, Qt.Key.Key_PageDown} ) +ALPHA = QtGui.QKeySequence("α")[0] +OMEGA = QtGui.QKeySequence("ω")[0] class QtKeys: @@ -170,7 +172,8 @@ def __hash__(self) -> int: def _reduce_key(self) -> Self: if self.key == ExtKey.No: - # this case is needed to avoid triggering parametric key binding with modifiers. + # this case is needed to avoid triggering parametric key binding + # with modifiers. return self new = QtKeys(self) new.key = ExtKey.Any @@ -199,10 +202,15 @@ def __eq__(self, other): def is_typing(self) -> bool: """True if key is a letter or number.""" - return self.modifier in ( + _modifier_ok = self.modifier in ( Qt.KeyboardModifier.NoModifier, Qt.KeyboardModifier.ShiftModifier, - ) and (Qt.Key.Key_Exclam <= self.key <= Qt.Key.Key_ydiaeresis) + ) + _key_ok = ( + Qt.Key.Key_Exclam <= self.key <= Qt.Key.Key_ydiaeresis + or ALPHA <= self.key <= OMEGA + ) + return _modifier_ok and _key_ok def is_moving(self) -> bool: """True if arrows are pushed.""" @@ -453,7 +461,8 @@ def wrapper(func): if not isinstance(current, QtKeyMap): seq = _key[:i] raise ValueError( - f"Non keymap object {type(current)} encountered at {', '.join(seq)}." + f"Non keymap object {type(current)} encountered at " + f"{', '.join(seq)}." ) k = QtKeys(k) try: @@ -479,7 +488,8 @@ def wrapper(func): if not isinstance(current, QtKeyMap): seq = _key[:i] raise ValueError( - f"Non keymap object {type(current)} encountered at {', '.join(seq)}." + f"Non keymap object {type(current)} encountered " + f"at {', '.join(seq)}." ) k = QtKeys(k) try: From c6eb3abc77cf6dc15214683bc52ec63d9ccd9f2e Mon Sep 17 00:00:00 2001 From: Hanjin Liu Date: Sat, 14 Jan 2023 17:24:37 +0900 Subject: [PATCH 2/3] just avoid crash --- tabulous/_qt/_table/_base/_enhanced_table.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tabulous/_qt/_table/_base/_enhanced_table.py b/tabulous/_qt/_table/_base/_enhanced_table.py index 3198d26f..f6115a5f 100644 --- a/tabulous/_qt/_table/_base/_enhanced_table.py +++ b/tabulous/_qt/_table/_base/_enhanced_table.py @@ -476,6 +476,14 @@ def keyReleaseEvent(self, a0: QtGui.QKeyEvent) -> None: ) return super().keyReleaseEvent(a0) + def inputMethodEvent(self, event: QtGui.QInputMethodEvent) -> None: + """Catch Japanese/Chinese edit event.""" + # NOTE: super().inputMethodEvent(event) is buggy!! + if event.preeditString(): + self._edit_current() + # FIXME: Cannot send the pre-edit text to the editor. + # editor.inputMethodQuery(Qt.InputMethodQuery.ImSurroundingText) + def zoom(self) -> float: """Get current zoom factor.""" return self._zoom From 846f6a947386e5011c675ecbf30f3d90a16d1b14 Mon Sep 17 00:00:00 2001 From: Hanjin Liu Date: Sun, 15 Jan 2023 11:04:34 +0900 Subject: [PATCH 3/3] add cyrillic characters --- tabulous/_keymap/_keymap.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tabulous/_keymap/_keymap.py b/tabulous/_keymap/_keymap.py index 40411714..90cb1dfb 100644 --- a/tabulous/_keymap/_keymap.py +++ b/tabulous/_keymap/_keymap.py @@ -144,6 +144,9 @@ class ExtKey: ALPHA = QtGui.QKeySequence("α")[0] OMEGA = QtGui.QKeySequence("ω")[0] +CYR_A = QtGui.QKeySequence("а")[0] +CYR_YA = QtGui.QKeySequence("я")[0] + class QtKeys: """A custom class for handling key events.""" @@ -209,6 +212,7 @@ def is_typing(self) -> bool: _key_ok = ( Qt.Key.Key_Exclam <= self.key <= Qt.Key.Key_ydiaeresis or ALPHA <= self.key <= OMEGA + or CYR_A <= self.key <= CYR_YA ) return _modifier_ok and _key_ok