[hamster-applet/gnome-2-28] show year controls depening on what's in DB not what's being selected. fixes bug 605947



commit d453d21bc4f3afda03744d3b40b65117c5727bd9
Author: Toms Bauģis <toms baugis gmail com>
Date:   Mon Jan 4 12:26:25 2010 +0000

    show year controls depening on what's in DB not what's being selected. fixes bug 605947

 hamster/stats.py |   55 ++++++++++++++++++++++++++++-------------------------
 1 files changed, 29 insertions(+), 26 deletions(-)
---
diff --git a/hamster/stats.py b/hamster/stats.py
index 55b84be..caa6621 100644
--- a/hamster/stats.py
+++ b/hamster/stats.py
@@ -432,30 +432,35 @@ class StatsViewer(object):
     def init_stats(self):
         self.stat_facts = runtime.storage.get_facts(dt.date(1970, 1, 1), dt.date.today())
         
-        by_year = stuff.totals(self.stat_facts,
-                               lambda fact: fact["start_time"].year,
-                               lambda fact: 1)
-        
-        year_box = self.get_widget("year_box")
-        class YearButton(gtk.ToggleButton):
-            def __init__(self, label, year, on_clicked):
-                gtk.ToggleButton.__init__(self, label)
-                self.year = year
-                self.connect("clicked", on_clicked)
-        
-        all_button = YearButton(C_("years", "All").encode("utf-8"),
-                                None,
-                                self.on_year_changed)
-        year_box.pack_start(all_button)
-        self.bubbling = True # TODO figure out how to properly work with togglebuttons as radiobuttons
-        all_button.set_active(True)
-        self.bubbling = False # TODO figure out how to properly work with togglebuttons as radiobuttons
-
-        years = sorted(by_year.keys())
-        for year in years:
-            year_box.pack_start(YearButton(str(year), year, self.on_year_changed))
-
-        year_box.show_all()
+        
+        if not self.stat_facts or self.stat_facts[-1]["start_time"].year == self.stat_facts[0]["start_time"].year:
+            self.get_widget("explore_controls").hide()
+        else:
+            by_year = stuff.totals(self.stat_facts,
+                                   lambda fact: fact["start_time"].year,
+                                   lambda fact: 1)
+            
+            year_box = self.get_widget("year_box")
+            class YearButton(gtk.ToggleButton):
+                def __init__(self, label, year, on_clicked):
+                    gtk.ToggleButton.__init__(self, label)
+                    self.year = year
+                    self.connect("clicked", on_clicked)
+            
+            all_button = YearButton(C_("years", "All").encode("utf-8"),
+                                    None,
+                                    self.on_year_changed)
+            year_box.pack_start(all_button)
+            self.bubbling = True # TODO figure out how to properly work with togglebuttons as radiobuttons
+            all_button.set_active(True)
+            self.bubbling = False # TODO figure out how to properly work with togglebuttons as radiobuttons
+    
+            years = sorted(by_year.keys())
+            for year in years:
+                year_box.pack_start(YearButton(str(year), year, self.on_year_changed))
+    
+            year_box.show_all()
+
 
         self.chart_category_totals = charting.HorizontalBarChart(value_format = "%.1f",
                                                             bars_beveled = False,
@@ -528,7 +533,6 @@ class StatsViewer(object):
 
         if not facts or (facts[-1]["start_time"] - facts[0]["start_time"]) < dt.timedelta(days=6):
             self.get_widget("statistics_box").hide()
-            self.get_widget("explore_controls").hide()
             label = self.get_widget("not_enough_records_label")
 
             if not facts:
@@ -541,7 +545,6 @@ A week of usage would be nice!"""))
             return
         else:
             self.get_widget("statistics_box").show()
-            self.get_widget("explore_controls").show()
             self.get_widget("not_enough_records_label").hide()
 
         # All dates in the scope



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]