-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpomodoro_popup.py
executable file
·60 lines (43 loc) · 1.39 KB
/
pomodoro_popup.py
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
#!/usr/bin/env python
import time
import pygtk
pygtk.require('2.0')
import gtk
POMODORO_LENGTH = 25 * 60 # seconds
class Base(object):
def __init__(self):
# Main window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_position(gtk.WIN_POS_CENTER)
self.window.set_size_request(300, 150)
self.window.set_title("Pomodoro rest break")
# Button next pomodoro
self.button_next = gtk.Button('Start next pomodoro')
self.button_next.set_size_request(150, 40)
self.button_next.connect('clicked', self.wait)
# Put buttons
fixed = gtk.Fixed()
fixed.put(self.button_next, 75, 55)
self.window.add(fixed)
self.window.show_all()
self.window.connect('destroy', self.destroy)
def wait(self, widget, **kwargs):
time_lapse = kwargs.get('time_lapse', POMODORO_LENGTH)
self.window.hide()
time_start = time.time()
time_end = (time_start + time_lapse)
while time_end > time.time():
time.sleep(1)
while gtk.events_pending():
gtk.main_iteration(False)
self.window.show()
def destroy(self, widget):
"""Close main window."""
gtk.main_quit()
def main(self):
gtk.main()
if __name__ == '__main__':
try:
Base().main()
except KeyboardInterrupt:
exit(1)