From 598af3eab7e4d698be26b1523ef135292dca6e49 Mon Sep 17 00:00:00 2001 From: Christian Dietrich Date: Thu, 20 Feb 2014 12:37:33 +0100 Subject: [PATCH] keybindings for next and previous file [ and ] are now keybindings for the next and the previous open file. --- xdot.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/xdot.py b/xdot.py index 710950a..0c870c6 100755 --- a/xdot.py +++ b/xdot.py @@ -2015,6 +2015,8 @@ def __init__(self, command_line_files, widget=None): # to display a file menu self.widget.connect("button-press-event", self.on_file_menu) + self.connect('key-press-event', self.on_key_press_event) + self.last_open_dir = "." self.set_focus(self.dotwidget) @@ -2145,16 +2147,35 @@ def on_close_file(self, action): self.open_file_idx = min(len(self.open_files)-1, self.open_file_idx) self.open_file(self.open_files[self.open_file_idx]) - def on_go_forward(self, action): + def on_go_forward(self, action = None): """Display the next file""" self.open_file_idx = min(self.open_file_idx + 1, len(self.open_files) - 1) self.open_file(self.open_files[self.open_file_idx]) - def on_go_back(self, action): + def on_go_back(self, action = None): """Display the previous file""" self.open_file_idx = max(0, self.open_file_idx - 1) self.open_file(self.open_files[self.open_file_idx]) + def on_file_menu(self, widget, event): + if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: + menu = gtk.Menu() + for filename in self.open_files: + label = os.path.basename(filename) + item = gtk.MenuItem(label) + menu.append(item) + item.connect("activate", lambda _, f: self.open_file(f), filename) + item.show() + menu.popup(None, None, None, 3, event.time) + + def on_key_press_event(self, widget, event): + if event.keyval == gtk.keysyms.bracketleft: + self.on_go_back() + return True + if event.keyval == gtk.keysyms.bracketright: + self.on_go_forward() + return True + class OptionParser(optparse.OptionParser): @@ -2173,6 +2194,8 @@ def main(): Up, Down, Left, Right scroll PageUp, +, = zoom in PageDown, - zoom out + [ previous open file + ] next open file R reload dot file F find Q quit