From: Christian Heller Date: Tue, 27 Aug 2024 09:42:21 +0000 (+0200) Subject: Browser: replace movement buttons with vi keybindings. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bprefix%7D%7D/bar%20baz.html?a=commitdiff_plain;h=583f7bed3e893d9dc9eeb81a1f0e4208325e3de0;p=stable_plom Browser: replace movement buttons with vi keybindings. --- diff --git a/browser.py b/browser.py index 9768443..0818297 100755 --- a/browser.py +++ b/browser.py @@ -75,14 +75,10 @@ class Window(Gtk.ApplicationWindow): btn.connect('clicked', on_click) parent_box.append(btn) - def add_nav_button(label_, inc_, pos_): - add_button(label_, lambda _: self.move_selection(inc_, pos_), - box_nav_buttons) - - box_nav_buttons = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) - for label, inc, pos in (('first', None, 0), ('prev', -1, None), - ('next', 1, None), ('last', None, -1)): - add_nav_button(label, inc, pos) + keyboard_control = Gtk.EventControllerKey() + keyboard_control.connect('key-pressed', self.handle_keypress, self) + self.prev_key = [''] + self.add_controller(keyboard_control) self.metadata = Gtk.Label(xalign=0) self.label_nothing_to_show = Gtk.Label(label='nothing to show') @@ -94,7 +90,6 @@ class Window(Gtk.ApplicationWindow): box_files_selection.append(self.box_sort_order) self.viewer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.viewer.append(box_files_selection) - self.viewer.append(box_nav_buttons) self.viewer.append(self.metadata) self.viewer.append(self.label_nothing_to_show) @@ -274,6 +269,18 @@ class Window(Gtk.ApplicationWindow): with open(CACHE_PATH, 'w', encoding='utf8') as f: json_dump(cache, f) + def handle_keypress(self, _keyval, keycode, _state, _user_data, _win): + if ord('G') == keycode: + self.move_selection(None, -1) + elif ord('j') == keycode: + self.move_selection(1, None) + elif ord('k') == keycode: + self.move_selection(-1, None) + elif ord('g') == keycode and 'g' == self.prev_key[0]: + self.move_selection(None, 0) + else: + self.prev_key[0] = chr(keycode) + def on_activate(app_): win = Window(application=app_)