Add Ctrl+MouseWheel Zoom in/out and Shift+MouseWheel page scroll up/down

This commit is contained in:
Stephen Boddy 2015-03-02 22:03:08 +01:00
parent df0043427e
commit 9c9a37eb78
1 changed files with 23 additions and 0 deletions

View File

@ -332,6 +332,7 @@ class Terminal(Gtk.VBox):
self.vte.connect('key-press-event', self.on_keypress) self.vte.connect('key-press-event', self.on_keypress)
self.vte.connect('button-press-event', self.on_buttonpress) self.vte.connect('button-press-event', self.on_buttonpress)
self.vte.connect('scroll-event', self.on_mousewheel)
self.vte.connect('popup-menu', self.popup_menu) self.vte.connect('popup-menu', self.popup_menu)
srcvtetargets = [("vte", Gtk.TargetFlags.SAME_APP, self.TARGET_TYPE_VTE)] srcvtetargets = [("vte", Gtk.TargetFlags.SAME_APP, self.TARGET_TYPE_VTE)]
@ -834,6 +835,28 @@ class Terminal(Gtk.VBox):
return(False) return(False)
def on_mousewheel(self, widget, event):
"""Handler for modifier + mouse wheel scroll events"""
SMOOTH_SCROLL_UP = event.direction == Gdk.ScrollDirection.SMOOTH and event.delta_y <= 0.
SMOOTH_SCROLL_DOWN = event.direction == Gdk.ScrollDirection.SMOOTH and event.delta_y > 0.
if event.state & Gdk.ModifierType.CONTROL_MASK == Gdk.ModifierType.CONTROL_MASK:
# Ctrl + mouse wheel up/down
if event.direction == Gdk.ScrollDirection.UP or SMOOTH_SCROLL_UP:
self.zoom_in()
return (True)
elif event.direction == Gdk.ScrollDirection.DOWN or SMOOTH_SCROLL_DOWN:
self.zoom_out()
return (True)
if event.state & Gdk.ModifierType.SHIFT_MASK == Gdk.ModifierType.SHIFT_MASK:
# Shift + mouse wheel up/down
if event.direction == Gdk.ScrollDirection.UP or SMOOTH_SCROLL_UP:
self.scroll_by_page(-1)
return (True)
elif event.direction == Gdk.ScrollDirection.DOWN or SMOOTH_SCROLL_DOWN:
self.scroll_by_page(1)
return (True)
return(False)
def popup_menu(self, widget, event=None): def popup_menu(self, widget, event=None):
"""Display the context menu""" """Display the context menu"""
menu = TerminalPopupMenu(self) menu = TerminalPopupMenu(self)