Key filter enancements, new event handler example
This commit is contained in:
parent
b8a058e572
commit
ba94493fb8
|
@ -32,6 +32,7 @@ if __name__ == "__main__":
|
||||||
# Add long and short arguments
|
# Add long and short arguments
|
||||||
parser.add_argument("--debug", "-d", default="false", help="Do extra console messaging.")
|
parser.add_argument("--debug", "-d", default="false", help="Do extra console messaging.")
|
||||||
parser.add_argument("--trace-debug", "-td", default="false", help="Disable saves, ignore IPC lock, do extra console messaging.")
|
parser.add_argument("--trace-debug", "-td", default="false", help="Disable saves, ignore IPC lock, do extra console messaging.")
|
||||||
|
parser.add_argument("--new-tab", "-nt", default="false", help="Opens a 'New Tab' if a handler is set for it.")
|
||||||
parser.add_argument("--file", "-f", default="default", help="JUST SOME FILE ARG.")
|
parser.add_argument("--file", "-f", default="default", help="JUST SOME FILE ARG.")
|
||||||
|
|
||||||
# Read arguments (If any...)
|
# Read arguments (If any...)
|
||||||
|
|
|
@ -38,9 +38,9 @@ class Controller(DummyMixin, SignalsMixins, ControllerData):
|
||||||
self.window.connect("key-press-event", self.on_global_key_press_controller)
|
self.window.connect("key-press-event", self.on_global_key_press_controller)
|
||||||
self.window.connect("key-release-event", self.on_global_key_release_controller)
|
self.window.connect("key-release-event", self.on_global_key_release_controller)
|
||||||
|
|
||||||
|
|
||||||
def _subscribe_to_events(self):
|
def _subscribe_to_events(self):
|
||||||
event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
|
event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
|
||||||
|
event_system.subscribe("tggl_top_main_menubar", self._tggl_top_main_menubar)
|
||||||
|
|
||||||
def load_glade_file(self):
|
def load_glade_file(self):
|
||||||
self.builder = Gtk.Builder()
|
self.builder = Gtk.Builder()
|
||||||
|
@ -54,3 +54,6 @@ class Controller(DummyMixin, SignalsMixins, ControllerData):
|
||||||
|
|
||||||
def get_core_widget(self):
|
def get_core_widget(self):
|
||||||
return self.core_widget
|
return self.core_widget
|
||||||
|
|
||||||
|
def _tggl_top_main_menubar(self):
|
||||||
|
print("_tggl_top_main_menubar > stub...")
|
||||||
|
|
|
@ -17,6 +17,7 @@ class ControllerData:
|
||||||
self.window = settings.get_main_window()
|
self.window = settings.get_main_window()
|
||||||
self.builder = None
|
self.builder = None
|
||||||
self.core_widget = None
|
self.core_widget = None
|
||||||
|
self.was_midified_key = False
|
||||||
self.ctrl_down = False
|
self.ctrl_down = False
|
||||||
self.shift_down = False
|
self.shift_down = False
|
||||||
self.alt_down = False
|
self.alt_down = False
|
||||||
|
|
|
@ -27,6 +27,10 @@ class KeyboardSignalsMixin:
|
||||||
|
|
||||||
def on_global_key_press_controller(self, eve, user_data):
|
def on_global_key_press_controller(self, eve, user_data):
|
||||||
keyname = Gdk.keyval_name(user_data.keyval).lower()
|
keyname = Gdk.keyval_name(user_data.keyval).lower()
|
||||||
|
modifiers = Gdk.ModifierType(user_data.get_state() & ~Gdk.ModifierType.LOCK_MASK)
|
||||||
|
|
||||||
|
self.was_midified_key = True if modifiers != 0 else False
|
||||||
|
|
||||||
if keyname.replace("_l", "").replace("_r", "") in ["control", "alt", "shift"]:
|
if keyname.replace("_l", "").replace("_r", "") in ["control", "alt", "shift"]:
|
||||||
if "control" in keyname:
|
if "control" in keyname:
|
||||||
self.ctrl_down = True
|
self.ctrl_down = True
|
||||||
|
@ -37,8 +41,12 @@ class KeyboardSignalsMixin:
|
||||||
|
|
||||||
def on_global_key_release_controller(self, widget, event):
|
def on_global_key_release_controller(self, widget, event):
|
||||||
""" Handler for keyboard events """
|
""" Handler for keyboard events """
|
||||||
keyname = Gdk.keyval_name(event.keyval).lower()
|
keyname = Gdk.keyval_name(event.keyval).lower()
|
||||||
|
modifiers = Gdk.ModifierType(event.get_state() & ~Gdk.ModifierType.LOCK_MASK)
|
||||||
|
|
||||||
if keyname.replace("_l", "").replace("_r", "") in ["control", "alt", "shift"]:
|
if keyname.replace("_l", "").replace("_r", "") in ["control", "alt", "shift"]:
|
||||||
|
should_return = self.was_midified_key and (self.ctrl_down or self.shift_down or self.alt_down)
|
||||||
|
|
||||||
if "control" in keyname:
|
if "control" in keyname:
|
||||||
self.ctrl_down = False
|
self.ctrl_down = False
|
||||||
if "shift" in keyname:
|
if "shift" in keyname:
|
||||||
|
@ -46,7 +54,16 @@ class KeyboardSignalsMixin:
|
||||||
if "alt" in keyname:
|
if "alt" in keyname:
|
||||||
self.alt_down = False
|
self.alt_down = False
|
||||||
|
|
||||||
|
# NOTE: In effect a filter after releasing a modifier and we have a modifier mapped
|
||||||
|
if should_return:
|
||||||
|
self.was_midified_key = False
|
||||||
|
return
|
||||||
|
|
||||||
mapping = keybindings.lookup(event)
|
mapping = keybindings.lookup(event)
|
||||||
|
logger.debug(f"on_global_key_release_controller > key > {keyname}")
|
||||||
|
logger.debug(f"on_global_key_release_controller > keyval > {event.keyval}")
|
||||||
|
logger.debug(f"on_global_key_release_controller > mapping > {mapping}")
|
||||||
|
|
||||||
if mapping:
|
if mapping:
|
||||||
# See if in controller scope
|
# See if in controller scope
|
||||||
try:
|
try:
|
||||||
|
@ -65,7 +82,9 @@ class KeyboardSignalsMixin:
|
||||||
logger.debug(f"on_global_key_release_controller > key > {keyname}")
|
logger.debug(f"on_global_key_release_controller > key > {keyname}")
|
||||||
|
|
||||||
if self.ctrl_down:
|
if self.ctrl_down:
|
||||||
if keyname in ["1", "kp_1", "2", "kp_2", "3", "kp_3", "4", "kp_4"]:
|
if not keyname in ["1", "kp_1", "2", "kp_2", "3", "kp_3", "4", "kp_4"]:
|
||||||
|
self.handle_key_event_system(None, mapping)
|
||||||
|
else:
|
||||||
...
|
...
|
||||||
|
|
||||||
def handle_key_event_system(self, sender, eve_type):
|
def handle_key_event_system(self, sender, eve_type):
|
||||||
|
|
|
@ -11,7 +11,7 @@ from gi.repository import Gdk
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def err(log = ""):
|
def logger(log = ""):
|
||||||
print(log)
|
print(log)
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class Keybindings:
|
||||||
# Does much the same, but with worse error handling.
|
# Does much the same, but with worse error handling.
|
||||||
# keyval, mask = Gtk.accelerator_parse(binding)
|
# keyval, mask = Gtk.accelerator_parse(binding)
|
||||||
except KeymapError as e:
|
except KeymapError as e:
|
||||||
err(f"Keybinding reload failed to parse binding '{binding}': {e}")
|
logger(f"Keybinding reload failed to parse binding '{binding}': {e}")
|
||||||
else:
|
else:
|
||||||
if mask & Gdk.ModifierType.SHIFT_MASK:
|
if mask & Gdk.ModifierType.SHIFT_MASK:
|
||||||
if keyval == Gdk.KEY_Tab:
|
if keyval == Gdk.KEY_Tab:
|
||||||
|
@ -120,7 +120,7 @@ class Keybindings:
|
||||||
Gdk.ModifierType(event.get_state() & ~Gdk.ModifierType.LOCK_MASK),
|
Gdk.ModifierType(event.get_state() & ~Gdk.ModifierType.LOCK_MASK),
|
||||||
event.group)
|
event.group)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
err(f"Keybinding lookup failed to translate keyboard event: {dir(event)}")
|
logger(f"Keybinding lookup failed to translate keyboard event: {dir(event)}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
mask = (event.get_state() & ~consumed) & self._masks
|
mask = (event.get_state() & ~consumed) & self._masks
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"open_terminal" : "F4",
|
"open_terminal" : "F4",
|
||||||
"refresh_tab" : ["F5", "<Control>r"],
|
"refresh_tab" : ["F5", "<Control>r"],
|
||||||
"delete_files" : "Delete",
|
"delete_files" : "Delete",
|
||||||
"tggl_top_main_menubar" : "Alt",
|
"tggl_top_main_menubar" : "Alt_L",
|
||||||
"trash_files" : "<Shift><Control>t",
|
"trash_files" : "<Shift><Control>t",
|
||||||
"tear_down" : "<Control>q",
|
"tear_down" : "<Control>q",
|
||||||
"go_up" : "<Control>Up",
|
"go_up" : "<Control>Up",
|
||||||
|
|
Loading…
Reference in New Issue