#!/usr/bin/env python # 20-20-20-Rule.py # # 20-20-20-Rule - Helps you practice the 20-20-20 rule as described # in the pop-up # # By Jason Copenhaver # Copyright 2007 Jason Copenhaver # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import pynotify from egg import trayicon import gtk import gobject import sys class Rule: def __init__(self): self.timer = -1 self.tray_icon = trayicon.TrayIcon("trayicon") tray_image = gtk.Image() tray_image.set_from_stock(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_SMALL_TOOLBAR) event_box = gtk.EventBox() event_box.add(tray_image) event_box.connect("button-press-event",self.on_click) self.tray_icon.add(event_box) self.tray_icon.show_all() pynotify.init("20-20-20 Rule") self.notify = pynotify.Notification("20-20-20 Rule", "Go look at something 20 feet away for at least 20 seconds.") self.notify.attach_to_widget(self.tray_icon) self.notify.set_timeout(20000) # 20 minutes, plus the 20 seconds that the notification window is up self.timer = gobject.timeout_add((60000 * 20) + 20000, Rule.action, self) def quit(self, widget): if self.timer != -1: gobject.source_remove(self.timer) self.timer = -1 sys.exit(1) def restart(self, widget): if self.timer != -1: gobject.source_remove(self.timer) self.timer = gobject.timeout_add((60000 * 20) + 20000, Rule.action, self) def on_click(self, widget, event): menu = gtk.Menu() restart = gtk.MenuItem("Restart") restart.connect("activate",self.restart) menu.append(restart) quit = gtk.MenuItem("Quit") quit.connect("activate",self.quit) menu.append(quit) menu.show_all() menu.popup(None, None, None, event.button, event.get_time()) def action(self): self.notify.show() return True if __name__ == "__main__": Rule() gtk.main()