Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions safeeyes/config/locale/safeeyes.pot
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,12 @@ msgstr ""

msgid "A required plugin is missing dependencies!"
msgstr ""

msgid "Postponement duration in"
msgstr ""

msgid "minutes"
msgstr ""

msgid "seconds"
msgstr ""
1 change: 1 addition & 0 deletions safeeyes/config/safeeyes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 10 additions & 4 deletions safeeyes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down
34 changes: 26 additions & 8 deletions safeeyes/glade/settings_dialog.glade
Original file line number Diff line number Diff line change
Expand Up @@ -412,28 +412,46 @@
</child>
<child>
<object class="GtkBox" id="box10">
<property name="visible">1</property>
<property name="spacing">5</property>
<property name="homogeneous">1</property>
<property name="visible">1</property>
<child>
<object class="GtkLabel" id="lbl_postpone_duration">
<property name="halign">start</property>
<property name="label" translatable="yes">Postponement duration in</property>
<property name="visible">1</property>
</object>
</child>
<child>
<object class="GtkDropDown" id="dropdown_postpone_unit">
<property name="halign">start</property>
<property name="label" translatable="yes">Postponement duration (in minutes)</property>
<property name="valign">center</property>
<property name="hexpand">true</property>
<property name="vexpand">false</property>
<property name="selected">0</property>
<property name="model">
<object class="GtkStringList">
<items>
<item translatable="yes">minutes</item>
<item translatable="yes">seconds</item>
</items>
</object>
</property>
</object>
</child>
<child>
<object class="GtkSpinButton" id="spin_postpone_duration">
<property name="visible">1</property>
<property name="can-focus">1</property>
<property name="halign">end</property>
<property name="valign">center</property>
<property name="text">1</property>
<property name="adjustment">adjust_postpone_duration</property>
<property name="can-focus">1</property>
<property name="climb-rate">1</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
<property name="hexpand-set">True</property>
<property name="numeric">1</property>
<property name="text">1</property>
<property name="update-policy">if-valid</property>
<property name="valign">center</property>
<property name="value">1</property>
<property name="visible">1</property>
</object>
</child>
</object>
Expand Down
11 changes: 11 additions & 0 deletions safeeyes/ui/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
)
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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(),
Expand Down