forked from akkana/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheggtimer
executable file
·65 lines (49 loc) · 1.65 KB
/
eggtimer
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
#!/usr/bin/env python
import sys, os, time
import Tkinter
# Callback for key events:
def bye(x) :
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 recent kernels:
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>", bye)
root.mainloop()
# main: read the runtime arguments.
try :
sleeptime = int(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
# Now try to fork and give control back to the terminal:
# Unfortunately, tkinter apparently refuses to run from the child process,
# for reasons that don't seem to be documented anywhere.
# try:
# pid = os.fork()
# if pid > 0:
# # exit first parent
# sys.exit(0)
# except OSError, e:
# print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror)
time.sleep(sleeptime)
showAlert(message)