Skip to content

Commit 569cb62

Browse files
authored
Merge pull request slgobinath#737 from SebastianDorobantu/master
Add option to postpone breaks by seconds rather than minutes
2 parents c760f8d + b18589a commit 569cb62

File tree

5 files changed

+57
-12
lines changed

5 files changed

+57
-12
lines changed

safeeyes/config/locale/safeeyes.pot

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,3 +558,12 @@ msgstr ""
558558

559559
msgid "A required plugin is missing dependencies!"
560560
msgstr ""
561+
562+
msgid "Postponement duration in"
563+
msgstr ""
564+
565+
msgid "minutes"
566+
msgstr ""
567+
568+
msgid "seconds"
569+
msgstr ""

safeeyes/config/safeeyes.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"short_break_duration": 15,
1212
"persist_state": false,
1313
"postpone_duration": 5,
14+
"postpone_unit": "minutes",
1415
"shortcut_disable_time": 2,
1516
"shortcut_skip": 9,
1617
"shortcut_postpone": 65,

safeeyes/core.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ def initialize(self, config: Config):
7373
logging.info("Initialize the core")
7474
self.pre_break_warning_time = config.get("pre_break_warning_time")
7575
self._break_queue = BreakQueue.create(config, self.context)
76-
self.default_postpone_duration = (
77-
config.get("postpone_duration") * 60
78-
) # Convert to seconds
76+
self.default_postpone_duration = int(config.get("postpone_duration"))
77+
self.postpone_unit = config.get("postpone_unit")
78+
if self.postpone_unit != "seconds":
79+
self.default_postpone_duration *= 60
80+
7981
self.postpone_duration = self.default_postpone_duration
8082

8183
def start(self, next_break_time=-1, reset_breaks=False) -> None:
@@ -236,7 +238,11 @@ def __scheduler_job(self) -> None:
236238
)
237239

238240
# Wait for the pre break warning period
239-
logging.info("Waiting for %d minutes until next break", (time_to_wait / 60))
241+
if self.postpone_unit == "seconds":
242+
logging.info("Waiting for %d seconds until next break", time_to_wait)
243+
else:
244+
logging.info("Waiting for %d minutes until next break", (time_to_wait / 60))
245+
240246
self.__wait_for(time_to_wait)
241247

242248
logging.info("Pre-break waiting is over")

safeeyes/glade/settings_dialog.glade

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,28 +412,46 @@
412412
</child>
413413
<child>
414414
<object class="GtkBox" id="box10">
415-
<property name="visible">1</property>
416415
<property name="spacing">5</property>
417-
<property name="homogeneous">1</property>
416+
<property name="visible">1</property>
418417
<child>
419418
<object class="GtkLabel" id="lbl_postpone_duration">
419+
<property name="halign">start</property>
420+
<property name="label" translatable="yes">Postponement duration in</property>
420421
<property name="visible">1</property>
422+
</object>
423+
</child>
424+
<child>
425+
<object class="GtkDropDown" id="dropdown_postpone_unit">
421426
<property name="halign">start</property>
422-
<property name="label" translatable="yes">Postponement duration (in minutes)</property>
427+
<property name="valign">center</property>
428+
<property name="hexpand">true</property>
429+
<property name="vexpand">false</property>
430+
<property name="selected">0</property>
431+
<property name="model">
432+
<object class="GtkStringList">
433+
<items>
434+
<item translatable="yes">minutes</item>
435+
<item translatable="yes">seconds</item>
436+
</items>
437+
</object>
438+
</property>
423439
</object>
424440
</child>
425441
<child>
426442
<object class="GtkSpinButton" id="spin_postpone_duration">
427-
<property name="visible">1</property>
428-
<property name="can-focus">1</property>
429-
<property name="halign">end</property>
430-
<property name="valign">center</property>
431-
<property name="text">1</property>
432443
<property name="adjustment">adjust_postpone_duration</property>
444+
<property name="can-focus">1</property>
433445
<property name="climb-rate">1</property>
446+
<property name="halign">end</property>
447+
<property name="hexpand">True</property>
448+
<property name="hexpand-set">True</property>
434449
<property name="numeric">1</property>
450+
<property name="text">1</property>
435451
<property name="update-policy">if-valid</property>
452+
<property name="valign">center</property>
436453
<property name="value">1</property>
454+
<property name="visible">1</property>
437455
</object>
438456
</child>
439457
</object>

safeeyes/ui/settings_dialog.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def __init__(self, application, config, on_save_settings):
8080
self.spin_long_break_interval = builder.get_object("spin_long_break_interval")
8181
self.spin_time_to_prepare = builder.get_object("spin_time_to_prepare")
8282
self.spin_postpone_duration = builder.get_object("spin_postpone_duration")
83+
self.dropdown_postpone_unit = builder.get_object("dropdown_postpone_unit")
8384
self.spin_disable_keyboard_shortcut = builder.get_object(
8485
"spin_disable_keyboard_shortcut"
8586
)
@@ -130,6 +131,11 @@ def __initialize(self, config):
130131
self.spin_long_break_interval.set_value(config.get("long_break_interval"))
131132
self.spin_time_to_prepare.set_value(config.get("pre_break_warning_time"))
132133
self.spin_postpone_duration.set_value(config.get("postpone_duration"))
134+
# Set the active item in the dropdown based on the postpone unit
135+
if config.get("postpone_unit") == "seconds":
136+
self.dropdown_postpone_unit.set_selected(1)
137+
else:
138+
self.dropdown_postpone_unit.set_selected(0)
133139
self.spin_disable_keyboard_shortcut.set_value(
134140
config.get("shortcut_disable_time")
135141
)
@@ -317,6 +323,7 @@ def on_switch_postpone_activate(self, switch, state):
317323
state of the postpone switch.
318324
"""
319325
self.spin_postpone_duration.set_sensitive(self.switch_postpone.get_active())
326+
self.dropdown_postpone_unit.set_sensitive(self.switch_postpone.get_active())
320327

321328
def on_spin_short_break_interval_change(self, spin_button, *value):
322329
"""Event handler for value change of short break interval."""
@@ -376,6 +383,10 @@ def on_window_delete(self, *args):
376383
self.config.set(
377384
"postpone_duration", self.spin_postpone_duration.get_value_as_int()
378385
)
386+
self.config.set(
387+
"postpone_unit",
388+
self.dropdown_postpone_unit.get_selected_item().get_string(),
389+
)
379390
self.config.set(
380391
"shortcut_disable_time",
381392
self.spin_disable_keyboard_shortcut.get_value_as_int(),

0 commit comments

Comments
 (0)