Created
May 18, 2015 02:37
-
-
Save shark0der/0b2b1b565c433d68a75d to your computer and use it in GitHub Desktop.
Money indicator: Each morning you're given $1440, $1 for every minute of your life. Spend it wisely.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import appindicator, pynotify, gtk, os, sys | |
import threading | |
from datetime import datetime | |
from datetime import timedelta | |
try: | |
import glib | |
except: | |
from gi.repository import GLib as glib | |
def update(): | |
global indicator | |
glib.timeout_add_seconds(1, update) | |
a = datetime.now() | |
b = datetime.now() | |
resetAt = 9 # reset the counter at this hour | |
if (b.hour >= resetAt): | |
b = b + timedelta(days=1) | |
b = b.replace(hour = resetAt, minute = 0, second = 0) | |
left = round((b - a).total_seconds() / 60, 2) | |
indicator.set_label('$' + "{0:.2f}".format(left)) | |
def quit(item): | |
gtk.main_quit() | |
# not used. kept in case is needed | |
def notify(): | |
pynotify.init('money_indicator') | |
n = pynotify.Notification('<b>Title</b>', 'Text', 'notification-message-im') | |
n.show() | |
q = gtk.MenuItem('Quit') | |
q.show() | |
q.connect('activate', quit) | |
menu = gtk.Menu() | |
menu.append(q) | |
indicator = appindicator.Indicator('money', gtk.STOCK_ABOUT, appindicator.CATEGORY_APPLICATION_STATUS) | |
indicator.set_status( appindicator.STATUS_ACTIVE ) | |
indicator.set_label('-') | |
indicator.set_menu(menu) | |
t1 = threading.Thread(target=update) | |
t1.start() | |
t1.join() | |
gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment