From 63e6b07020f432ecdbcc02e206c7ff9281074f6c Mon Sep 17 00:00:00 2001 From: Franco Battista <89143582+francobattista@users.noreply.github.com> Date: Tue, 7 May 2024 23:23:41 -0300 Subject: [PATCH] =?UTF-8?q?Keyboard=20shortcuts=20added:=20-Open=20setting?= =?UTF-8?q?s,=20-Open=20locations,=20-Refresh=20w=E2=80=A6=20(#113)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Keyboard shortcuts added: -Open settings, -Open locations, -Refresh weather, using keyboard library * Refactor shortcuts using GTK --------- Co-authored-by: Franco Battista --- src/mousam.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/mousam.py b/src/mousam.py index 26d51c2..d80a0ad 100644 --- a/src/mousam.py +++ b/src/mousam.py @@ -5,7 +5,7 @@ gi.require_version("Gtk", "4.0") gi.require_version("Adw", "1") -from gi.repository import Gtk, Adw, Gio +from gi.repository import Gtk, Adw, Gio, GLib, Gdk from gettext import gettext as _, pgettext as C_ @@ -114,6 +114,12 @@ def __init__(self, *args, **kwargs): thread = threading.Thread(target=self._load_weather_data, name="load_data") thread.start() + #Set key listeners + keycont = Gtk.EventControllerKey() + keycont.connect('key-pressed', self.on_key_press) + self.add_controller(keycont) + + # =========== Create Loader ============= def show_loader(self): # Loader container @@ -358,3 +364,16 @@ def _on_preferences_clicked(self, *args, **kwargs): def _on_locations_clicked(self, *args, **kwargs): adw_preferences_window = WeatherLocations(self.main_window) adw_preferences_window.show() + + + #Def shortcuts key listeners + def on_key_press(self, key_controller, keyval, keycode, state,*args): + if state & Gdk.ModifierType.CONTROL_MASK: + if keyval == Gdk.KEY_r: + self._refresh_weather(None) + if keyval == Gdk.KEY_l: + GLib.idle_add(self._on_locations_clicked) + if keyval == Gdk.KEY_comma: + GLib.idle_add(self._on_preferences_clicked) + +