Skip to content

Commit bd51aed

Browse files
committed
Added plugin for limiting the number of consecutive skips or postpones
1 parent 684d162 commit bd51aed

File tree

5 files changed

+147
-2
lines changed

5 files changed

+147
-2
lines changed

safeeyes/config/locale/en_US/LC_MESSAGES/safeeyes.po

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,3 +500,19 @@ msgstr "Pause media"
500500
# plugin/healthstats
501501
#~ msgid "Interval to reset statistics (in hours)"
502502
#~ msgstr "Interval to reset statistics (in hours)"
503+
504+
# plugin/limitconsecutiveskipping
505+
msgid "Limit Consecutive Skipping"
506+
msgstr "Limit Consecutive Skipping"
507+
508+
# plugin/limitconsecutiveskipping
509+
msgid "How many skips or postpones are allowed in a row"
510+
msgstr "How many skips or postpones are allowed in a row"
511+
512+
# plugin/limitconsecutiveskipping
513+
msgid "Limit how many breaks can be skipped or postponed in a row"
514+
msgstr "Limit how many breaks can be skipped or postponed in a row"
515+
516+
# plugin/limitconsecutiveskipping
517+
msgid "Skipped or postponed %d/%d breaks in a row"
518+
msgstr "Skipped or postponed %d/%d breaks in a row"

safeeyes/core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def __init__(self, context):
6767
self.context = context
6868
self.context['skipped'] = False
6969
self.context['postponed'] = False
70+
self.context['skip_button_disabled'] = False
71+
self.context['postpone_button_disabled'] = False
7072
self.context['state'] = State.WAITING
7173

7274
def initialize(self, config):
@@ -288,6 +290,8 @@ def __fire_stop_break(self):
288290

289291
# Reset the skipped flag
290292
self.context['skipped'] = False
293+
self.context['skip_button_disabled'] = False
294+
self.context['postpone_button_disabled'] = False
291295
self.__start_next_break()
292296

293297
def __wait_for(self, duration):
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"meta": {
3+
"name": "Limit Consecutive Skipping",
4+
"description": "Limit how many breaks can be skipped or postponed in a row",
5+
"version": "0.0.1"
6+
},
7+
"dependencies": {
8+
"python_modules": [],
9+
"shell_commands": [],
10+
"operating_systems": [],
11+
"desktop_environments": [],
12+
"resources": []
13+
},
14+
"settings": [{
15+
"id": "number_of_allowed_skips_in_a_row",
16+
"label": "How many skips or postpones are allowed in a row",
17+
"type": "INT",
18+
"default": 2,
19+
"min": 1,
20+
"max": 100
21+
}],
22+
"break_override_allowed": true
23+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env python
2+
# Safe Eyes is a utility to remind you to take break frequently
3+
# to protect your eyes from eye strain.
4+
5+
# Copyright (C) 2017 Gobinath
6+
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
"""
20+
Show health statistics on the break screen.
21+
"""
22+
23+
import logging
24+
25+
context = None
26+
no_of_skipped_breaks = 0
27+
session = None
28+
enabled = True
29+
30+
def init(ctx, safeeyes_config, plugin_config):
31+
"""
32+
Initialize the plugin.
33+
"""
34+
global enabled
35+
global context
36+
global session
37+
global no_of_skipped_breaks
38+
global no_allowed_skips
39+
40+
logging.debug('Initialize Limit consecutive skipping plugin')
41+
context = ctx
42+
43+
no_allowed_skips = plugin_config.get('number_of_allowed_skips_in_a_row', 2)
44+
45+
if session is None:
46+
# Read the session
47+
session = context['session']['plugin'].get('limitconsecutiveskipping', None)
48+
if session is None:
49+
session = {'no_of_skipped_breaks': 0}
50+
context['session']['plugin']['limitconsecutiveskipping'] = session
51+
no_of_skipped_breaks = session.get('no_of_skipped_breaks', 0)
52+
53+
54+
def on_stop_break():
55+
"""
56+
After the break, check if it is skipped.
57+
"""
58+
# Check if the plugin is enabled
59+
if not enabled:
60+
return
61+
62+
global no_of_skipped_breaks
63+
if context['skipped'] or context['postponed']:
64+
no_of_skipped_breaks += 1
65+
session['no_of_skipped_breaks'] = no_of_skipped_breaks
66+
else:
67+
no_of_skipped_breaks = 0
68+
session['no_of_skipped_breaks'] = no_of_skipped_breaks
69+
70+
71+
def on_start_break(break_obj):
72+
logging.debug('Skipped / allowed = {} / {}'.format(no_of_skipped_breaks, no_allowed_skips))
73+
74+
if no_of_skipped_breaks >= no_allowed_skips:
75+
context['postpone_button_disabled'] = True
76+
context['skip_button_disabled'] = True
77+
78+
79+
def get_widget_title(break_obj):
80+
"""
81+
Return the widget title.
82+
"""
83+
# Check if the plugin is enabled
84+
if not enabled:
85+
return ""
86+
87+
return _('Limit Consecutive Skipping')
88+
89+
90+
def get_widget_content(break_obj):
91+
"""
92+
Return the statistics.
93+
"""
94+
# Check if the plugin is enabled
95+
if not enabled:
96+
return ""
97+
98+
return _('Skipped or postponed %d/%d breaks in a row') % (no_of_skipped_breaks, no_allowed_skips)
99+

safeeyes/ui/break_screen.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ def __show_break_screen(self, message, image_path, widget, tray_actions):
155155
no_of_monitors = screen.get_n_monitors()
156156
logging.info("Show break screens in %d display(s)", no_of_monitors)
157157

158+
skip_button_disabled = self.context.get('skip_button_disabled', False)
159+
postpone_button_disabled = self.context.get('postpone_button_disabled', False)
160+
158161
for monitor in range(no_of_monitors):
159162
monitor_gemoetry = screen.get_monitor_geometry(monitor)
160163
x = monitor_gemoetry.x
@@ -186,15 +189,15 @@ def __show_break_screen(self, message, image_path, widget, tray_actions):
186189
toolbar_button.show()
187190

188191
# Add the buttons
189-
if self.enable_postpone:
192+
if self.enable_postpone and not postpone_button_disabled:
190193
# Add postpone button
191194
btn_postpone = Gtk.Button(_('Postpone'))
192195
btn_postpone.get_style_context().add_class('btn_postpone')
193196
btn_postpone.connect('clicked', self.on_postpone_clicked)
194197
btn_postpone.set_visible(True)
195198
box_buttons.pack_start(btn_postpone, True, True, 0)
196199

197-
if not self.strict_break:
200+
if not self.strict_break and not skip_button_disabled:
198201
# Add the skip button
199202
btn_skip = Gtk.Button(_('Skip'))
200203
btn_skip.get_style_context().add_class('btn_skip')

0 commit comments

Comments
 (0)