diff --git a/safeeyes/config/locale/safeeyes.pot b/safeeyes/config/locale/safeeyes.pot index ea0ceee7..13371059 100644 --- a/safeeyes/config/locale/safeeyes.pot +++ b/safeeyes/config/locale/safeeyes.pot @@ -558,3 +558,12 @@ msgstr "" msgid "A required plugin is missing dependencies!" msgstr "" + +msgid "Postponement duration in" +msgstr "" + +msgid "minutes" +msgstr "" + +msgid "seconds" +msgstr "" diff --git a/safeeyes/config/safeeyes.json b/safeeyes/config/safeeyes.json index 06c05cba..47e20fa8 100644 --- a/safeeyes/config/safeeyes.json +++ b/safeeyes/config/safeeyes.json @@ -11,6 +11,7 @@ "short_break_duration": 15, "persist_state": false, "postpone_duration": 5, + "postpone_unit": "minutes", "shortcut_disable_time": 2, "shortcut_skip": 9, "shortcut_postpone": 65, diff --git a/safeeyes/core.py b/safeeyes/core.py index 386ea1ad..deac1ee9 100644 --- a/safeeyes/core.py +++ b/safeeyes/core.py @@ -73,9 +73,11 @@ def initialize(self, config: Config): logging.info("Initialize the core") self.pre_break_warning_time = config.get("pre_break_warning_time") self._break_queue = BreakQueue.create(config, self.context) - self.default_postpone_duration = ( - config.get("postpone_duration") * 60 - ) # Convert to seconds + self.default_postpone_duration = int(config.get("postpone_duration")) + self.postpone_unit = config.get("postpone_unit") + if self.postpone_unit != "seconds": + self.default_postpone_duration *= 60 + self.postpone_duration = self.default_postpone_duration def start(self, next_break_time=-1, reset_breaks=False) -> None: @@ -236,7 +238,11 @@ def __scheduler_job(self) -> None: ) # Wait for the pre break warning period - logging.info("Waiting for %d minutes until next break", (time_to_wait / 60)) + if self.postpone_unit == "seconds": + logging.info("Waiting for %d seconds until next break", time_to_wait) + else: + logging.info("Waiting for %d minutes until next break", (time_to_wait / 60)) + self.__wait_for(time_to_wait) logging.info("Pre-break waiting is over") diff --git a/safeeyes/glade/settings_dialog.glade b/safeeyes/glade/settings_dialog.glade index 93a9735a..03844853 100644 --- a/safeeyes/glade/settings_dialog.glade +++ b/safeeyes/glade/settings_dialog.glade @@ -412,28 +412,46 @@ - 1 5 - 1 + 1 + start + Postponement duration in 1 + + + + start - Postponement duration (in minutes) + center + true + false + 0 + + + + minutes + seconds + + + - 1 - 1 - end - center - 1 adjust_postpone_duration + 1 1 + end + True + True 1 + 1 if-valid + center 1 + 1 diff --git a/safeeyes/ui/settings_dialog.py b/safeeyes/ui/settings_dialog.py index 76daf7e6..9470d43d 100644 --- a/safeeyes/ui/settings_dialog.py +++ b/safeeyes/ui/settings_dialog.py @@ -80,6 +80,7 @@ def __init__(self, application, config, on_save_settings): self.spin_long_break_interval = builder.get_object("spin_long_break_interval") self.spin_time_to_prepare = builder.get_object("spin_time_to_prepare") self.spin_postpone_duration = builder.get_object("spin_postpone_duration") + self.dropdown_postpone_unit = builder.get_object("dropdown_postpone_unit") self.spin_disable_keyboard_shortcut = builder.get_object( "spin_disable_keyboard_shortcut" ) @@ -130,6 +131,11 @@ def __initialize(self, config): self.spin_long_break_interval.set_value(config.get("long_break_interval")) self.spin_time_to_prepare.set_value(config.get("pre_break_warning_time")) self.spin_postpone_duration.set_value(config.get("postpone_duration")) + # Set the active item in the dropdown based on the postpone unit + if config.get("postpone_unit") == "seconds": + self.dropdown_postpone_unit.set_selected(1) + else: + self.dropdown_postpone_unit.set_selected(0) self.spin_disable_keyboard_shortcut.set_value( config.get("shortcut_disable_time") ) @@ -317,6 +323,7 @@ def on_switch_postpone_activate(self, switch, state): state of the postpone switch. """ self.spin_postpone_duration.set_sensitive(self.switch_postpone.get_active()) + self.dropdown_postpone_unit.set_sensitive(self.switch_postpone.get_active()) def on_spin_short_break_interval_change(self, spin_button, *value): """Event handler for value change of short break interval.""" @@ -376,6 +383,10 @@ def on_window_delete(self, *args): self.config.set( "postpone_duration", self.spin_postpone_duration.get_value_as_int() ) + self.config.set( + "postpone_unit", + self.dropdown_postpone_unit.get_selected_item().get_string(), + ) self.config.set( "shortcut_disable_time", self.spin_disable_keyboard_shortcut.get_value_as_int(),