From 882ea5ba6e46b413694d9a74a6aa246d2c7153f5 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Fri, 6 Jan 2017 04:36:44 +0100 Subject: Add a ShortcutsWindow and tooltips to display accelerators The GtkShortcutsWindow is shown upon pressing `?`. This is only available in Gtk+ >= 3.20. For earlier versions nothing happens. --- voctogui/lib/shortcuts.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 voctogui/lib/shortcuts.py (limited to 'voctogui/lib/shortcuts.py') diff --git a/voctogui/lib/shortcuts.py b/voctogui/lib/shortcuts.py new file mode 100644 index 0000000..d591a03 --- /dev/null +++ b/voctogui/lib/shortcuts.py @@ -0,0 +1,59 @@ +from gi.repository import Gtk + +from lib.config import Config + + +class ShortcutsWindow(Gtk.ShortcutsWindow): + def __init__(self, win): + Gtk.ShortcutsWindow.__init__(self) + self.build() + self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) + self.set_transient_for(win) + self.set_modal(True) + + def build(self): + section = Gtk.ShortcutsSection() + section.show() + + compose_group = Gtk.ShortcutsGroup(title="Composition modes") + compose_group.show() + for accel, desc in [("F1", "Select fullscreen mode"), + ("F2", "Select Picture in Picture mode"), + ("F3", "Select Side-by-Side Equal mode"), + ("F4", "Select Side-by-Side Preview mode")]: + short = Gtk.ShortcutsShortcut(title=desc, accelerator=accel) + short.show() + compose_group.add(short) + section.add(compose_group) + + source_group = Gtk.ShortcutsGroup(title="Source Selection") + source_group.show() + num = len(Config.getlist('mix', 'sources')) + source_items = [ + ("1...{}".format(num), "Select Source as A-Source"), + ("1...{}".format(num), "Select Source as B-Source"), + ("1...{}".format(num), "Select Source as Fullscreen") + ] + for accel, desc in source_items: + short = Gtk.ShortcutsShortcut(title=desc, accelerator=accel) + short.show() + source_group.add(short) + section.add(source_group) + + if Config.getboolean('misc', 'cut'): + other_group = Gtk.ShortcutsGroup(title="Other") + other_group.show() + short = Gtk.ShortcutsShortcut(title="Send Cut message", + accelerator="t") + short.show() + other_group.add(short) + section.add(other_group) + + self.add(section) + + +def show_shortcuts(win): + if not hasattr(Gtk, "ShortcutsWindow"): + return + shortcuts_window = ShortcutsWindow(win) + shortcuts_window.show() -- cgit v1.2.3