From 99e020b60fbde731b6c416d3c111bd19f10ab356 Mon Sep 17 00:00:00 2001 From: deltragon Date: Fri, 9 May 2025 20:04:47 +0200 Subject: [PATCH 1/6] feature: disable postpone and skip buttons while shortcuts are disabled --- safeeyes/ui/break_screen.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/safeeyes/ui/break_screen.py b/safeeyes/ui/break_screen.py index aeacff15..6ef3fe5b 100644 --- a/safeeyes/ui/break_screen.py +++ b/safeeyes/ui/break_screen.py @@ -59,6 +59,7 @@ def __init__(self, application, context, on_skipped, on_postponed): self.shortcut_disable_time = 2 self.strict_break = False self.windows = [] + self.button_widgets = [] self.show_skip_button = False self.show_postpone_button = False @@ -106,15 +107,20 @@ def on_window_delete(self, *args): def on_skip_clicked(self, button): """Skip button press event handler.""" - self.skip_break() + + if self.enable_shortcut: + self.skip_break() def on_postpone_clicked(self, button): """Postpone button press event handler.""" - self.postpone_break() + + if self.enable_shortcut: + self.postpone_break() def show_count_down(self, countdown, seconds): """Show/update the count down on all screens.""" self.enable_shortcut = self.shortcut_disable_time <= seconds + self.__set_button_widgets_sensitive() mins, secs = divmod(countdown, 60) timeformat = "{:02d}:{:02d}".format(mins, secs) GLib.idle_add(lambda: self.__update_count_down(timeformat)) @@ -139,6 +145,10 @@ def close(self): # Destroy other windows if exists GLib.idle_add(lambda: self.__destroy_all_screens()) + def __set_button_widgets_sensitive(self): + for button in self.button_widgets: + button.set_sensitive(self.enable_shortcut) + def __tray_action(self, button, tray_action): """Tray action handler. @@ -215,7 +225,9 @@ def __show_break_screen(self, message, image_path, widget, tray_actions): btn_postpone.get_style_context().add_class("btn_postpone") btn_postpone.connect("clicked", self.on_postpone_clicked) btn_postpone.set_visible(True) + btn_postpone.set_sensitive(self.enable_shortcut) box_buttons.append(btn_postpone) + self.button_widgets.append(btn_postpone) if self.show_skip_button: # Add the skip button @@ -223,7 +235,9 @@ def __show_break_screen(self, message, image_path, widget, tray_actions): btn_skip.get_style_context().add_class("btn_skip") btn_skip.connect("clicked", self.on_skip_clicked) btn_skip.set_visible(True) + btn_postpone.set_sensitive(self.enable_shortcut) box_buttons.append(btn_skip) + self.button_widgets.append(btn_skip) # Set values if image_path: @@ -354,3 +368,4 @@ def __destroy_all_screens(self): win.destroy() del self.windows[:] del self.count_labels[:] + del self.button_widgets[:] From 0da8c32f8fa39ea74f7ae0cea713cbfa5f356e74 Mon Sep 17 00:00:00 2001 From: deltragon Date: Wed, 25 Jun 2025 21:54:04 +0200 Subject: [PATCH 2/6] break screen: fix thread safety show_count_down is called (by core) from a different thread than the main thread. --- safeeyes/ui/break_screen.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/safeeyes/ui/break_screen.py b/safeeyes/ui/break_screen.py index 6ef3fe5b..5408c946 100644 --- a/safeeyes/ui/break_screen.py +++ b/safeeyes/ui/break_screen.py @@ -120,7 +120,7 @@ def on_postpone_clicked(self, button): def show_count_down(self, countdown, seconds): """Show/update the count down on all screens.""" self.enable_shortcut = self.shortcut_disable_time <= seconds - self.__set_button_widgets_sensitive() + GLib.idle_add(lambda: self.__set_button_widgets_sensitive()) mins, secs = divmod(countdown, 60) timeformat = "{:02d}:{:02d}".format(mins, secs) GLib.idle_add(lambda: self.__update_count_down(timeformat)) @@ -145,9 +145,10 @@ def close(self): # Destroy other windows if exists GLib.idle_add(lambda: self.__destroy_all_screens()) - def __set_button_widgets_sensitive(self): + def __set_button_widgets_sensitive(self) -> None: for button in self.button_widgets: - button.set_sensitive(self.enable_shortcut) + if button.get_sensitive() != self.enable_shortcut: + button.set_sensitive(self.enable_shortcut) def __tray_action(self, button, tray_action): """Tray action handler. From dd46fd3d6d21338c4c2722bcc2a70031a86e3974 Mon Sep 17 00:00:00 2001 From: deltragon Date: Wed, 25 Jun 2025 22:10:24 +0200 Subject: [PATCH 3/6] add styling to disabled skip/postpone buttons --- safeeyes/config/style/safeeyes_style.css | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/safeeyes/config/style/safeeyes_style.css b/safeeyes/config/style/safeeyes_style.css index f2b62555..610c4a0e 100644 --- a/safeeyes/config/style/safeeyes_style.css +++ b/safeeyes/config/style/safeeyes_style.css @@ -43,6 +43,11 @@ color: black; } +.btn_skip:disabled { + color: grey; + border-color: grey; +} + .btn_postpone { color: white; font-size: 10pt; @@ -62,6 +67,11 @@ color: black; } +.btn_postpone:disabled { + color: grey; + border-color: grey; +} + .lbl_message { font-size: 22pt; color: white; From 75d341795bf19ee8b381c22b4e018b19d72f4253 Mon Sep 17 00:00:00 2001 From: deltragon Date: Wed, 25 Jun 2025 22:35:07 +0200 Subject: [PATCH 4/6] add missing translations --- safeeyes/config/locale/safeeyes.pot | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/safeeyes/config/locale/safeeyes.pot b/safeeyes/config/locale/safeeyes.pot index f7e00a69..a560a340 100644 --- a/safeeyes/config/locale/safeeyes.pot +++ b/safeeyes/config/locale/safeeyes.pot @@ -564,3 +564,9 @@ msgstr "" msgid "Customizing the postpone and skip shortcuts does not work on Wayland." msgstr "" + +msgid "Safe Eyes - Error" +msgstr "" + +msgid "A required plugin is missing dependencies!" +msgstr "" From 3bcb47b7b96b6ddff07d16a3a7f3cfe22e70f37f Mon Sep 17 00:00:00 2001 From: deltragon Date: Wed, 25 Jun 2025 22:36:31 +0200 Subject: [PATCH 5/6] fix .editorconfig for glade files --- .editorconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.editorconfig b/.editorconfig index 8b079ee4..9cd88eed 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,3 +11,7 @@ indent_size = 4 [*.{py}] trim_trailing_whitespace = true + +[*.glade] +indent_style = space +indent_size = 2 From 813aba1bc37b480ec18e3e78333f4e6b0beba659 Mon Sep 17 00:00:00 2001 From: deltragon Date: Wed, 25 Jun 2025 22:40:51 +0200 Subject: [PATCH 6/6] rename setting --- safeeyes/config/locale/safeeyes.pot | 7 +++---- safeeyes/glade/settings_dialog.glade | 2 +- safeeyes/ui/break_screen.py | 2 ++ 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/safeeyes/config/locale/safeeyes.pot b/safeeyes/config/locale/safeeyes.pot index a560a340..6f14420a 100644 --- a/safeeyes/config/locale/safeeyes.pot +++ b/safeeyes/config/locale/safeeyes.pot @@ -118,10 +118,6 @@ msgstr "" msgid "Time to prepare for a break (in seconds)" msgstr "" -# Settings dialog -msgid "Keyboard shortcuts disabled period (in seconds)" -msgstr "" - # Settings dialog msgid "Postponement duration (in minutes)" msgstr "" @@ -570,3 +566,6 @@ msgstr "" msgid "A required plugin is missing dependencies!" msgstr "" + +msgid "Skipping/postponing disabled period (in seconds)" +msgstr "" diff --git a/safeeyes/glade/settings_dialog.glade b/safeeyes/glade/settings_dialog.glade index 43ab9a55..1147f908 100644 --- a/safeeyes/glade/settings_dialog.glade +++ b/safeeyes/glade/settings_dialog.glade @@ -447,7 +447,7 @@ 1 start - Keyboard shortcuts disabled period (in seconds) + Skipping/postponing disabled period (in seconds) diff --git a/safeeyes/ui/break_screen.py b/safeeyes/ui/break_screen.py index 5408c946..31fd95c2 100644 --- a/safeeyes/ui/break_screen.py +++ b/safeeyes/ui/break_screen.py @@ -83,6 +83,8 @@ def initialize(self, config): ) ) + # TODO: shortcut_disable_time should be renamed + # it used to be just about keyboard shortcuts - now it also controls whether the buttons are locked self.shortcut_disable_time = config.get("shortcut_disable_time", 2) self.strict_break = config.get("strict_break", False)