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) + +