#!/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=("", 25, "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("", 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)