From 03fa9c4db73e4353eeae57ca1d386bde189fc0a7 Mon Sep 17 00:00:00 2001 From: coderkun Date: Wed, 26 Apr 2017 11:48:32 +0200 Subject: [PATCH] Add Gtk.ShortcutsWindows to application (resolve #14) --- data/de.coderkun.mcg.gresource.xml | 1 + data/gtk.shortcuts.ui | 123 +++++++++++++++++++++++++++++ data/menu.ui | 5 ++ mcg/application.py | 12 +++ mcg/widgets.py | 23 ++++++ 5 files changed, 164 insertions(+) create mode 100644 data/gtk.shortcuts.ui diff --git a/data/de.coderkun.mcg.gresource.xml b/data/de.coderkun.mcg.gresource.xml index 9c16fb0..8b1aa20 100644 --- a/data/de.coderkun.mcg.gresource.xml +++ b/data/de.coderkun.mcg.gresource.xml @@ -3,6 +3,7 @@ gtk.glade gtk.css + gtk.shortcuts.ui menu.ui mcg.svg noise-texture.png diff --git a/data/gtk.shortcuts.ui b/data/gtk.shortcuts.ui new file mode 100644 index 0000000..20b47fc --- /dev/null +++ b/data/gtk.shortcuts.ui @@ -0,0 +1,123 @@ + + + + + True + + + 1 + shortcuts + Application + 10 + + + 1 + General + + + 1 + <primary>KP_1 + Switch to the Connection panel + + + + + 1 + <primary>KP_2 + Switch to the Cover panel + + + + + 1 + <primary>KP_3 + Switch to the Playlist panel + + + + + 1 + <primary>KP_4 + Switch to the Library panel + + + + + 1 + <primary>k + Show the keyboard shortcuts (this dialog) + + + + + 1 + <primary>i + Open the info dialog + + + + + 1 + <primary>q + Quit the application + + + + + + + 1 + Player + + + 1 + <primary>c + Connect or disconnect + + + + + 1 + <primary>p + Switch between play and pause + + + + + 1 + <primary>r + Clear the playlist + + + + + + + 1 + Cover Panel + + + 1 + <alt>Return F11 + Show the cover in fullscreen mode + + + + + + + 1 + Library Panel + + + 1 + <primary>f + Search the library + + + + + + + + diff --git a/data/menu.ui b/data/menu.ui index ca672e9..d12e586 100644 --- a/data/menu.ui +++ b/data/menu.ui @@ -47,6 +47,11 @@
+ + app.shortcuts + _Keyboard Shortcuts + <Primary>k + app.info Info diff --git a/mcg/application.py b/mcg/application.py index 44b5ff1..233eaf5 100644 --- a/mcg/application.py +++ b/mcg/application.py @@ -32,6 +32,7 @@ class Application(Gtk.Application): def __init__(self): Gtk.Application.__init__(self, application_id=Application.ID, flags=Gio.ApplicationFlags.FLAGS_NONE) self._window = None + self._shortcuts_window = None self._info_dialog = None self._verbosity = logging.WARNING self.add_main_option_entries([ @@ -68,6 +69,14 @@ class Application(Gtk.Application): self._window.present() + def on_menu_shortcuts(self, action, value): + builder = Gtk.Builder() + builder.set_translation_domain(Application.DOMAIN) + builder.add_from_resource(self._get_resource_path('gtk.shortcuts.ui')) + shortcuts_dialog = widgets.ShortcutsDialog(builder, self._window) + shortcuts_dialog.present() + + def on_menu_info(self, action, value): if not self._info_dialog: self._info_dialog = widgets.InfoDialog(self._builder) @@ -119,6 +128,9 @@ class Application(Gtk.Application): def _setup_actions(self): + action = Gio.SimpleAction.new("shortcuts", None) + action.connect('activate', self.on_menu_shortcuts) + self.add_action(action) action = Gio.SimpleAction.new("info", None) action.connect('activate', self.on_menu_info) self.add_action(action) diff --git a/mcg/widgets.py b/mcg/widgets.py index a5ba5e5..c654125 100644 --- a/mcg/widgets.py +++ b/mcg/widgets.py @@ -24,6 +24,25 @@ from mcg.zeroconf import ZeroconfProvider +class ShortcutsDialog(): + + + def __init__(self, builder, window): + # Widgets + self._window = builder.get_object('shortcuts-dialog') + self._window.set_transient_for(window.get()) + + + def get(self): + return self._window + + + def present(self): + self._window.present() + + + + class InfoDialog(): @@ -183,6 +202,10 @@ class Window(): self._appwindow.add_action(self._panel_action) + def get(self): + return self._appwindow + + def present(self): self._appwindow.present() self._appwindow.resize(800, 600)