Fix bug #5282 - show advice for best results
[pedometerwidget] / src / usr / lib / hildon-desktop / pedometer_widget_home.py
index 5266c48..5c9412d 100644 (file)
@@ -150,7 +150,6 @@ class PedoValues():
         self.steps = steps
         self.calories = calories
         self.dist = dist
-        self.unit = unit
 
     def __add__(self, other):
         return PedoValues(self.time + other.time,
@@ -175,20 +174,22 @@ class PedoValues():
         return strtime
 
     def get_print_distance(self):
+        global unit
         if self.dist > 1000:
-            if self.unit == 0:
+            if unit == 0:
                 return "%.2f km" % (self.dist / 1000)
             else:
                 return "%.2f mi" % (self.dist / 1609.344)
         else:
-            if self.unit == 0:
+            if unit == 0:
                 return "%d m" % self.dist
             else:
                 return "%d ft" % int(self.dist * 3.2808)
 
     def get_avg_speed(self):
+        global unit
         conv = 0
-        if self.unit:
+        if unit:
             conv = 2.23693629
         else:
             conv = 3.6
@@ -199,9 +200,10 @@ class PedoValues():
         return speed * conv
 
     def get_print_avg_speed(self):
+        global unit
         suffix = ""
         conv = 0
-        if self.unit:
+        if unit:
             suffix = "mi/h"
             conv = 2.23693629
         else:
@@ -219,7 +221,7 @@ class PedoValues():
         return str(self.steps)
 
     def get_print_calories(self):
-        return str(self.calories)
+        return "%.2f" % self.calories
 
 class PedoRepository(Singleton):
     values = {}
@@ -241,7 +243,9 @@ class PedoRepository(Singleton):
     def get_values(self):
         return self.values
 
-    def add_values(self, values, when=date.today()):
+    def add_values(self, values, when=None):
+        if when is None:
+            when = date.today()
         """add PedoValues values to repository """
         try:
             self.values[when] = self.values[when] + values
@@ -458,6 +462,8 @@ class PedoController(Singleton):
 
     def reset_all_values(self):
         self.repository.reset_values()
+        self.v[0] = PedoValues()
+        self.v[1] = PedoValues()
         self.notify()
 
     def stop_pedometer(self):
@@ -516,11 +522,14 @@ class PedoController(Singleton):
     def set_mode(self, mode):
         self.mode = mode
         self.set_height(self.height_interval)
+        self.pedometerInterval.set_mode(self.mode)
         self.notify()
 
     def set_unit(self, new_unit):
         self.unit = new_unit
+        global unit
         unit = new_unit
+        self.notify()
 
     def get_str_weight_unit(self):
         if self.unit == 0:
@@ -697,7 +706,7 @@ class PedoCounter(Singleton):
     COORD_FNAME_SDK = "/home/andrei/pedometer-widget-0.1/date.txt"
     LOGFILE = "/home/user/log_pedometer"
     #time in ms between two accelerometer data reads
-    COORD_GET_INTERVAL = 10
+    COORD_GET_INTERVAL = 25
 
     COUNT_INTERVAL = 5
 
@@ -1564,6 +1573,7 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem):
         else:
             self.controller.start_pedometer()
             self.button.set_icon(ICONSPATH + "stop.png")
+            hildon.hildon_banner_show_information(self, "None", "Keep the N900 in a pocket close to your hip for best results")
 
     def do_expose_event(self, event):
         cr = self.window.cairo_create()