forked from akkana/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheggtimer
More file actions
executable file
·63 lines (46 loc) · 1.61 KB
/
eggtimer
File metadata and controls
executable file
·63 lines (46 loc) · 1.61 KB
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
#!/usr/bin/env python
import sys, os, time
import Tkinter
# Callback for key events:
def keyEvent(event):
# print(event.char, event.keysym, event.keycode)
if event.char == 'q' or event.keysym == 'Return':
sys.exit(0)
def Usage():
print "Usage:", sys.argv[0], "minutes message"
sys.exit(1)
def showAlert(message):
# This is supposed to show a dialog, but tkMessageBox doesn't exist:
# tkMessageBox.showwarning("hello", message)
# Try to beep a bit, even though that doesn't work on some distros:
print ""
# print message
root = Tkinter.Tk()
button = Tkinter.Button(root, text=message,
bg="red", activebackground="red",
fg="white", activeforeground="white",
font=("Sans", 40, "bold"),
command=quit)
# Make sure the window is at least as big as the screen:
button.pack(ipadx=root.winfo_screenwidth()/2,
ipady=root.winfo_screenheight()/2)
# Apparently we can't bind key events to a button, only to the root:
root.bind("<Key>", keyEvent)
root.mainloop()
# main: read the runtime arguments.
if __name__ == '__main__':
try:
sleeptime = float(sys.argv[1]) * 60
except ValueError, e:
Usage()
if len(sys.argv) > 2:
message = ' '.join(sys.argv[2:])
else:
message = "Wake up!"
print "Sleeping for", sleeptime, "seconds with message:", message
# Return control to the shell before sleeping:
rc = os.fork()
if rc:
sys.exit(0)
time.sleep(sleeptime)
showAlert(message)