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')
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)
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_)