~mfisch/+junk/fitbit-indicator-fixes

« back to all changes in this revision

Viewing changes to usr/share/fitbit-steps-indicator/fitbit-steps-indicator

  • Committer: Chris Wayne
  • Date: 2013-07-26 02:24:16 UTC
  • Revision ID: chris.wayne@canonical.com-20130726022416-6gs755xbtq4ywt1a
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
import urllib, os, time, datetime
 
3
 
 
4
from gi.repository import Gtk, GObject
 
5
from gi.repository import AppIndicator3 as appindicator
 
6
from helpers import FitBit
 
7
 
 
8
 
 
9
def openit(*args):
 
10
    os.system("xdg-open http://www.fitbit.com")
 
11
 
 
12
def update(*args):
 
13
    steps = FitBit.fetch(None)
 
14
    print steps.steps
 
15
 
 
16
    ind.set_label("%i steps" % steps.steps, "100 steps")
 
17
    lst.get_child().set_text("Last updated: %s" % time.strftime("%H:%M"))
 
18
    return True
 
19
 
 
20
if __name__ == "__main__":
 
21
    # icon is expected to be in the same directory as the script.
 
22
    iconPath = '/usr/share/icons/hicolor/32x32/apps/fitbit.png'
 
23
 
 
24
    ind = appindicator.Indicator.new("fitbit-steps-indicator", iconPath,
 
25
        appindicator.IndicatorCategory.APPLICATION_STATUS)
 
26
    ind.set_status(appindicator.IndicatorStatus.ACTIVE)
 
27
    ind.set_label("unknown steps", "100 steps")
 
28
 
 
29
    menu = Gtk.Menu()
 
30
    opn = Gtk.MenuItem("Open Fitbit")
 
31
    menu.append(opn)
 
32
    lst = Gtk.MenuItem("Last updated: ?????")
 
33
    menu.append(lst)
 
34
    menu.show_all()
 
35
    opn.connect("activate", openit)
 
36
 
 
37
    ind.set_menu(menu)
 
38
 
 
39
    GObject.timeout_add_seconds(300, update)
 
40
    update()
 
41
    Gtk.main()