diff --git a/app/ui/backup.py b/app/ui/backup.py index 3b20fcf5..768ed22a 100644 --- a/app/ui/backup.py +++ b/app/ui/backup.py @@ -2,7 +2,7 @@ # # The MIT License (MIT) # -# Copyright (c) 2018-2024 Dmitriy Yefremov +# Copyright (c) 2018-2026 Dmitriy Yefremov # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -223,11 +223,11 @@ class BackupDialog: self._settings.add("backup_tool_window_size", window.get_size()) def on_key_release(self, view, event): - """ Handling keystrokes """ - key_code = event.hardware_keycode - if not KeyboardKey.value_exist(key_code): + """ Handling keystrokes. """ + key = KeyboardKey(event.hardware_keycode) + if key is KeyboardKey.UNDEFINED: return - key = KeyboardKey(key_code) + ctrl = event.state & MOD_MASK if key is KeyboardKey.DELETE: diff --git a/app/ui/epg/epg.py b/app/ui/epg/epg.py index b17d5633..930fc212 100644 --- a/app/ui/epg/epg.py +++ b/app/ui/epg/epg.py @@ -1217,10 +1217,10 @@ class EpgDialog: def on_key_press(self, view, event): """ Handling keystrokes """ - key_code = event.hardware_keycode - if not KeyboardKey.value_exist(key_code): + key = KeyboardKey(event.hardware_keycode) + if key is KeyboardKey.UNDEFINED: return - key = KeyboardKey(key_code) + ctrl = event.state & Gdk.ModifierType.CONTROL_MASK if ctrl and key is KeyboardKey.C: diff --git a/app/ui/ftp.py b/app/ui/ftp.py index c85618a7..c31b1317 100644 --- a/app/ui/ftp.py +++ b/app/ui/ftp.py @@ -2,7 +2,7 @@ # # The MIT License (MIT) # -# Copyright (c) 2018-2025 Dmitriy Yefremov +# Copyright (c) 2018-2026 Dmitriy Yefremov # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -856,11 +856,10 @@ class FtpClientBox(Gtk.HBox): self._settings.ftp_bookmarks = [r[0] for r in self._bookmark_model] def on_view_key_press(self, view, event): - key_code = event.hardware_keycode - if not KeyboardKey.value_exist(key_code): + key = KeyboardKey(event.hardware_keycode) + if key is KeyboardKey.UNDEFINED: return - key = KeyboardKey(key_code) ctrl = event.state & MOD_MASK if key is KeyboardKey.F7: diff --git a/app/ui/imports.py b/app/ui/imports.py index 86f009b2..7c071e01 100644 --- a/app/ui/imports.py +++ b/app/ui/imports.py @@ -426,10 +426,9 @@ class ImportDialog: def on_key_press(self, view, event): """ Handling keystrokes """ - key_code = event.hardware_keycode - if not KeyboardKey.value_exist(key_code): + key = KeyboardKey(event.hardware_keycode) + if key is KeyboardKey.UNDEFINED: return - key = KeyboardKey(key_code) if key is KeyboardKey.SPACE: model = view.get_model() diff --git a/app/ui/iptv.py b/app/ui/iptv.py index 9564b28f..36896b1f 100644 --- a/app/ui/iptv.py +++ b/app/ui/iptv.py @@ -2,7 +2,7 @@ # # The MIT License (MIT) # -# Copyright (c) 2018-2025 Dmitriy Yefremov +# Copyright (c) 2018-2026 Dmitriy Yefremov # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -1331,10 +1331,9 @@ class YtListImportDialog: view.get_model().foreach(lambda mod, path, itr: mod.set_value(itr, 2, select)) def on_key_press(self, view, event): - key_code = event.hardware_keycode - if not KeyboardKey.value_exist(key_code): + key = KeyboardKey(event.hardware_keycode) + if key is KeyboardKey.UNDEFINED: return - key = KeyboardKey(key_code) if key is KeyboardKey.SPACE: path, column = view.get_cursor() diff --git a/app/ui/main.py b/app/ui/main.py index 86d4c4b9..aebe1d16 100644 --- a/app/ui/main.py +++ b/app/ui/main.py @@ -2975,11 +2975,10 @@ class Application(Gtk.Application): def on_tree_view_key_press(self, view, event): """ Handling keystrokes on press """ - key_code = event.hardware_keycode - if not KeyboardKey.value_exist(key_code): - return + key = KeyboardKey(event.hardware_keycode) + if key is KeyboardKey.UNDEFINED: + return False - key = KeyboardKey(key_code) ctrl = event.state & MOD_MASK if key is KeyboardKey.F: if ctrl: @@ -3028,11 +3027,10 @@ class Application(Gtk.Application): def on_tree_view_key_release(self, view, event): """ Handling keystrokes on release """ - key_code = event.hardware_keycode - if not KeyboardKey.value_exist(key_code): + key = KeyboardKey(event.hardware_keycode) + if key is KeyboardKey.UNDEFINED: return - key = KeyboardKey(key_code) ctrl = event.state & MOD_MASK shift = event.state & Gdk.ModifierType.SHIFT_MASK model_name, model = get_model_data(view) @@ -4539,11 +4537,10 @@ class Application(Gtk.Application): self.emit("fav-changed", srv) def on_alt_view_key_press(self, view, event): - key_code = event.hardware_keycode - if not KeyboardKey.value_exist(key_code): + key = KeyboardKey(event.hardware_keycode) + if key is KeyboardKey.UNDEFINED: return - key = KeyboardKey(key_code) ctrl = event.state & MOD_MASK if ctrl and key == KeyboardKey.V: diff --git a/app/ui/picons.py b/app/ui/picons.py index 9a8c5b55..168d3f69 100644 --- a/app/ui/picons.py +++ b/app/ui/picons.py @@ -2,7 +2,7 @@ # # The MIT License (MIT) # -# Copyright (c) 2018-2024 Dmitriy Yefremov +# Copyright (c) 2018-2026 Dmitriy Yefremov # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -976,11 +976,10 @@ class PiconManager(Gtk.Box): return True def on_tree_view_key_press(self, view, event): - key_code = event.hardware_keycode - if not KeyboardKey.value_exist(key_code): + key = KeyboardKey(event.hardware_keycode) + if key is KeyboardKey.UNDEFINED: return - key = KeyboardKey(key_code) if key is KeyboardKey.DELETE: self.on_local_remove(view) diff --git a/app/ui/recordings.py b/app/ui/recordings.py index 599f398e..50d261be 100644 --- a/app/ui/recordings.py +++ b/app/ui/recordings.py @@ -304,11 +304,10 @@ class RecordingsTool(Gtk.Box): self._filter_entry.grab_focus() if button.get_active() else self._filter_entry.set_text("") def on_recordings_key_press(self, view, event): - key_code = event.hardware_keycode - if not KeyboardKey.value_exist(key_code): + key = KeyboardKey(event.hardware_keycode) + if key is KeyboardKey.UNDEFINED: return - key = KeyboardKey(key_code) if key is KeyboardKey.DELETE: self.on_recording_remove() diff --git a/app/ui/telnet.py b/app/ui/telnet.py index a453c9ee..a94eaacd 100644 --- a/app/ui/telnet.py +++ b/app/ui/telnet.py @@ -2,7 +2,7 @@ # # The MIT License (MIT) # -# Copyright (c) 2018-2025 Dmitriy Yefremov +# Copyright (c) 2018-2026 Dmitriy Yefremov # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -129,11 +129,10 @@ class TelnetClient(Gtk.Box): self.do_command() return True - key_code = event.hardware_keycode - if not KeyboardKey.value_exist(key_code): - return None + key = KeyboardKey(event.hardware_keycode) + if key is KeyboardKey.UNDEFINED: + return False - key = KeyboardKey(key_code) ctrl = event.state & MOD_MASK if ctrl and key is KeyboardKey.C: if self._tn and self._tn.sock: diff --git a/app/ui/timers.py b/app/ui/timers.py index 177c750a..b962ee04 100644 --- a/app/ui/timers.py +++ b/app/ui/timers.py @@ -2,7 +2,7 @@ # # The MIT License (MIT) # -# Copyright (c) 2018-2024 Dmitriy Yefremov +# Copyright (c) 2018-2026 Dmitriy Yefremov # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -460,11 +460,10 @@ class TimerTool(Gtk.Box): on_popup_menu(menu, event) def on_timers_key_release(self, view, event): - key_code = event.hardware_keycode - if not KeyboardKey.value_exist(key_code): + key = KeyboardKey(event.hardware_keycode) + if key is KeyboardKey.UNDEFINED: return - key = KeyboardKey(key_code) ctrl = event.state & MOD_MASK if key is KeyboardKey.DELETE: diff --git a/app/ui/uicommons.py b/app/ui/uicommons.py index 397096ca..802e768e 100644 --- a/app/ui/uicommons.py +++ b/app/ui/uicommons.py @@ -2,7 +2,7 @@ # # The MIT License (MIT) # -# Copyright (c) 2018-2025 Dmitriy Yefremov +# Copyright (c) 2018-2026 Dmitriy Yefremov # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -290,14 +290,8 @@ class Column(IntEnum): # *************** Keyboard keys *************** # -class BaseKeyboardKey(Enum): - @classmethod - def value_exist(cls, value): - return value in (val.value for val in cls.__members__.values()) - - if IS_LINUX: - class KeyboardKey(BaseKeyboardKey): + class KeyboardKey(IntEnum): """ The raw(hardware) codes [Linux] of the keyboard keys. """ E = 26 R = 27 @@ -335,8 +329,14 @@ if IS_LINUX: PAGE_UP_KP = 81 PAGE_DOWN_KP = 89 + UNDEFINED = -1 + + @classmethod + def _missing_(cls, value): + return cls.UNDEFINED + elif IS_DARWIN: - class KeyboardKey(BaseKeyboardKey): + class KeyboardKey(IntEnum): """ The raw(hardware) codes [macOS] of the keyboard keys. """ F = 3 E = 14 @@ -376,8 +376,14 @@ elif IS_DARWIN: PAGE_UP_KP = -1 PAGE_DOWN_KP = -1 + UNDEFINED = -1 + + @classmethod + def _missing_(cls, value): + return cls.UNDEFINED + else: - class KeyboardKey(BaseKeyboardKey): + class KeyboardKey(IntEnum): """ The raw(hardware) codes [Windows] of the keyboard keys. """ E = 69 R = 82 @@ -415,6 +421,12 @@ else: PAGE_UP_KP = -1 PAGE_DOWN_KP = -1 + UNDEFINED = -1 + + @classmethod + def _missing_(cls, value): + return cls.UNDEFINED + # Keys for move in lists. KEY_KP_(NAME) for laptop! MOVE_KEYS = {KeyboardKey.UP, KeyboardKey.PAGE_UP, KeyboardKey.DOWN, KeyboardKey.PAGE_DOWN, diff --git a/app/ui/xml/edit.py b/app/ui/xml/edit.py index d374a1a2..859f5dd6 100644 --- a/app/ui/xml/edit.py +++ b/app/ui/xml/edit.py @@ -2,7 +2,7 @@ # # The MIT License (MIT) # -# Copyright (c) 2018-2025 Dmitriy Yefremov +# Copyright (c) 2018-2026 Dmitriy Yefremov # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -310,11 +310,10 @@ class SatellitesTool(Gtk.Box): def on_key_press(self, view, event): """ Handling keystrokes. """ - key_code = event.hardware_keycode - if not KeyboardKey.value_exist(key_code): + key = KeyboardKey(event.hardware_keycode) + if key is KeyboardKey.UNDEFINED: return - key = KeyboardKey(key_code) ctrl = event.state & MOD_MASK if key is KeyboardKey.DELETE: @@ -329,12 +328,11 @@ class SatellitesTool(Gtk.Box): view.do_unselect_all(view) def on_tr_key_press(self, view, event): - """ Handling transponder view keystrokes. """ - key_code = event.hardware_keycode - if not KeyboardKey.value_exist(key_code): + """ Handling transponder view keystrokes. """ + key = KeyboardKey(event.hardware_keycode) + if key is KeyboardKey.UNDEFINED: return - key = KeyboardKey(key_code) ctrl = event.state & MOD_MASK if key is KeyboardKey.DELETE: