1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
"""
:Requirements: libnotify, python-gobject
"""
from datetime import timedelta
from gi.repository import Notify
from time import time
POMO = 1500 # 60 * 25
SHORT_REST = 300 # 60 * 5
LONG_REST = 1800 # 60 * 30
NB_REST = 4
class Py3status:
"""
Pomodoro method
"""
pomo = POMO
rest = SHORT_REST
nb_rest = NB_REST
def pomodoro(self, json, i3status_config):
"""
This function will update a timer in the i3status bar for 25 minutes,
then print a red "Break time" message for 5 minutes.
"""
if not self.pomo:
self.rest -= 1
timer = self.rest
full_text = 'Break time'
color = 'color_bad'
else:
self.pomo -= 1
timer = self.pomo
full_text = 'Pomodoro'
color = 'color_degraded'
if not timer:
# Pomodoro or Rest is finished, send notification
Notify.init('Pomodoro')
notification = Notify.Notification.new (
'<b>Attention:</b>',
'{} is finished'.format(full_text),
'dialog-information',
)
notification.show()
if not self.rest:
# Rest is finished, reinitialize data
self.nb_rest -= 1
self.pomo = POMO
self.rest = SHORT_REST
if not self.nb_rest:
# Number of small rest reached, go for long rest
self.rest = LONG_REST
self.nb_rest = NB_REST
response = {
'cached_until' : time(),
'color': i3status_config[color],
'full_text': '{}: {}'.format(
full_text, str(timedelta(seconds=timer))[2:]),
'name': 'pomodoro',
}
return (0, response)
|