Skip to content

Commit

Permalink
Keyboard shortcuts added: -Open settings, -Open locations, -Refresh w… (
Browse files Browse the repository at this point in the history
#113)

* Keyboard shortcuts added: -Open settings, -Open locations, -Refresh weather, using keyboard library

* Refactor shortcuts using GTK

---------

Co-authored-by: Franco Battista <franco@FRANCO-DEBIAN.francobattista.com.ar>
  • Loading branch information
francobattista and Franco Battista committed May 8, 2024
1 parent 31c6ed4 commit 63e6b07
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/mousam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)


0 comments on commit 63e6b07

Please sign in to comment.