-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeline.py
executable file
·104 lines (82 loc) · 2.44 KB
/
timeline.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
import time
import signal
import sys
import os
from subprocess import run
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk, GLib
# TODO Accept arguments to customize times and only enable break if argument is given
# TODO Clean up messy code
def abort(signal, frame):
run(["notify-send", "-i", "edit-delete", "Timer aborted"])
cleanExit()
def cleanExit():
try:
os.remove(lockFile)
except:
pass
sys.exit(0)
class Timer:
def __init__(self, progressbar, timeUp, timeDown):
self.bar = progressbar
self.timeUp = timeUp
self.timeDown = timeDown
self.stepUp = 1/timeUp
self.stepDown = -1/timeDown
self.counter = 0
self.goingUp = True
def __call__(self, *args):
if self.counter == self.timeUp:
self.goingUp = False
self.counter = self.timeDown
run(["notify-send", "-i", "starred",
"Time over!", "You can now take a break"])
if self.goingUp:
step = self.stepUp
self.counter += 1
else:
step = self.stepDown
self.counter -= 1
bar.set_fraction(bar.get_fraction() + step)
if not self.goingUp and self.counter == 0:
run(["notify-send", "Break is over"])
cleanExit()
return True
signal.signal(signal.SIGINT, abort)
signal.signal(signal.SIGTERM, abort)
lockFile = '/tmp/atmoz-timeline.lock'
existing_pid = 0
try:
with open(lockFile, 'r') as f:
existing_pid = f.read()
f.closed
except:
pass
if existing_pid == 0:
with open(lockFile, 'w') as f:
f.write(str(os.getpid()))
f.closed
else:
print("killing '" + existing_pid + "'")
run(["kill", existing_pid])
cleanExit()
#settings = Gtk.Settings.get_default()
#settings.set_property("gtk-theme-name", "Numix")
#settings.set_property("gtk-application-prefer-dark-theme", True)
window = Gtk.Window(title="timeline")
#window.connect("destroy", Gtk.main_quit)
window.set_type_hint(Gdk.WindowTypeHint.DOCK)
window.set_default_size(1000,4)
window.set_gravity(Gdk.Gravity.SOUTH)
window.move(0, window.get_screen().height() - window.get_size()[1])
bar = Gtk.ProgressBar()
bar.set_fraction(0.0)
window.add(bar)
window.show_all()
run(["notify-send", "-i", "appointment-new", "Timer started"])
timer = Timer(bar, 25*60, 5*60)
GLib.timeout_add(1000, timer)
GLib.MainLoop().run()
#Gtk.main()