Source

gcalcli / extra / reminderpopup

Full commit
#!/usr/bin/env python
# 2010-03-10, Mark Edgington

# gxmessage based popup reminder dialog box, with option to snooze for
# different periods of time.  Simply closing the dialog will dismiss the alarm.

# call this script just like you would call gxmessage, except make sure that there
# are no -buttons or -default arguments.

import subprocess
import sys
import time
import datetime

args = ['gxmessage', '-buttons', "_15min:15,30min:30,45min:45,1hr:60,3hr:180,_dismiss:0", '-default', "_15min"] + sys.argv[1:]

sleep_secs = None

while (sleep_secs != 0) and (sleep_secs != 60):
    if sleep_secs is not None:
        start_time = datetime.datetime.now()
        time_diff = datetime.timedelta(seconds=sleep_secs)
        while True:
            now = datetime.datetime.now()
            if now - start_time >= time_diff:
                break
            time.sleep(1)
            
    # try also to pop up a short libnotify notification - useful if you're
    # using another application in fullscreen mode and might miss seeing a
    # gxmessage popup.
    try:
        import pynotify
        if pynotify.init("Reminder Popup Script"):
            # hard-coded assuming that we are called with "reminderpopup -center -title 'titletext' ..."
            title = sys.argv[3] 
            n = pynotify.Notification("Calendar Reminder", title)
            n.set_timeout(1500) # milliseconds
            n.show()
        # else: there was an error initializing pynotify (app name conflict?)
    except ImportError:
        pass
    
    # sound alarm tone
    try:
        subprocess.Popen(['beep']) # non-blocking call
    except:
        pass # ignore if it's not there

    # pop up gxmessage window
    minutes = subprocess.call(args)
    sleep_secs = minutes*60