[hamster-applet] brought back toolbar buttons



commit 65f4882442cb519e487150382f7f0b17ed5c8b1a
Author: Toms Bauģis <toms baugis gmail com>
Date:   Mon Dec 21 23:53:15 2009 +0000

    brought back toolbar buttons

 data/stats.ui             |    3 +
 hamster/stats.py          |   98 +++++++++++++++++++++++++++++++++------------
 hamster/stats_overview.py |   53 ------------------------
 3 files changed, 75 insertions(+), 79 deletions(-)
---
diff --git a/data/stats.ui b/data/stats.ui
index 7df4f59..a47aa4c 100644
--- a/data/stats.ui
+++ b/data/stats.ui
@@ -164,6 +164,7 @@
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                 <property name="label" translatable="yes">Add</property>
                 <property name="stock_id">gtk-add</property>
+                <signal name="clicked" handler="on_add_clicked"/>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -177,6 +178,7 @@
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                 <property name="label" translatable="yes">Remove</property>
                 <property name="stock_id">gtk-remove</property>
+                <signal name="clicked" handler="on_remove_clicked"/>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -189,6 +191,7 @@
                 <property name="sensitive">False</property>
                 <property name="label" translatable="yes">Edit</property>
                 <property name="stock_id">gtk-edit</property>
+                <signal name="clicked" handler="on_edit_clicked"/>
               </object>
               <packing>
                 <property name="expand">False</property>
diff --git a/hamster/stats.py b/hamster/stats.py
index aa61932..1496e0b 100644
--- a/hamster/stats.py
+++ b/hamster/stats.py
@@ -39,6 +39,7 @@ import datetime as dt
 import calendar
 
 from hamster.i18n import C_
+from edit_activity import CustomFactController
 
 
 class StatsViewer(object):
@@ -62,6 +63,8 @@ class StatsViewer(object):
         
         self.overview = OverviewBox()
         self.get_widget("overview_tab").add(self.overview)
+        self.fact_tree = self.overview.fact_tree # TODO - this is upside down, should maybe get the overview tab over here
+        self.fact_tree.connect("cursor-changed", self.on_fact_selection_changed)
 
         self.reports = ReportsBox()
         self.get_widget("reports_tab").add(self.reports)
@@ -93,9 +96,29 @@ class StatsViewer(object):
         self.get_widget("by_day_box").add(self.timeline)
 
         self._gui.connect_signals(self)
+        runtime.dispatcher.add_handler('activity_updated', self.after_activity_update)
+        runtime.dispatcher.add_handler('day_updated', self.after_activity_update)
+
+
         self.window.show_all()
+        self.search()
+
+    def on_fact_selection_changed(self, tree):
+        """ enables and disables action buttons depending on selected item """
+        selection = tree.get_selection()
+        (model, iter) = selection.get_selected()
 
+        id = -1
+        if iter:
+            id = model[iter][0]
 
+        self.get_widget('remove').set_sensitive(id != -1)
+        self.get_widget('edit').set_sensitive(id != -1)
+
+        return True
+
+    def after_activity_update(self, widget, renames):
+        print widget, renames
         self.search()
 
     def search(self):
@@ -112,8 +135,6 @@ class StatsViewer(object):
         
         self.overview.search(self.start_date, self.end_date, facts)
         self.reports.search(self.start_date, self.end_date, facts)
-
-                
         
         
     def on_report_button_clicked(self, widget):
@@ -126,22 +147,23 @@ class StatsViewer(object):
         self.get_widget("preset_range").hide()
         self.get_widget("range_box").hide()
         
-        if idx == 0: # week
-            self.start_date = self.view_date - dt.timedelta(self.view_date.weekday() + 1)
-            self.start_date = self.start_date + dt.timedelta(stuff.locale_first_weekday())
-            self.end_date = self.start_date + dt.timedelta(6)
-            self.get_widget("preset_range").show()
-
-        elif idx == 1: #month
-            self.start_date = self.view_date - dt.timedelta(self.view_date.day - 1) #set to beginning of month
-            first_weekday, days_in_month = calendar.monthrange(self.view_date.year, self.view_date.month)
-            self.end_date = self.start_date + dt.timedelta(days_in_month - 1)
-            self.get_widget("preset_range").show()
-
-        elif idx == 2:
+        if idx == 2: # date range
             self.get_widget("range_box").show()
-            
-        self.search()
+        else:
+            if idx == 0: # week
+                self.start_date = self.view_date - dt.timedelta(self.view_date.weekday() + 1)
+                self.start_date = self.start_date + dt.timedelta(stuff.locale_first_weekday())
+                self.end_date = self.start_date + dt.timedelta(6)
+                self.get_widget("preset_range").show()
+    
+            elif idx == 1: #month
+                self.start_date = self.view_date - dt.timedelta(self.view_date.day - 1) #set to beginning of month
+                first_weekday, days_in_month = calendar.monthrange(self.view_date.year, self.view_date.month)
+                self.end_date = self.start_date + dt.timedelta(days_in_month - 1)
+                self.get_widget("preset_range").show()
+    
+                
+            self.search()
         
     def on_start_date_entered(self, input):
         self.start_date = input.get_date().date()
@@ -199,19 +221,43 @@ class StatsViewer(object):
         return self._gui.get_object(name)
 
     def on_window_tabs_switch_page(self, notebook, page, pagenum):
-        if pagenum == 2:
-            year = None
-            for child in self.stats.get_widget("year_box").get_children():
-                if child.get_active():
-                    year = child.year
-            
-            self.stats.stats(year)
+        if pagenum == 0:
+            self.on_fact_selection_changed(self.fact_tree)
         elif pagenum == 1:
+            self.get_widget('remove').set_sensitive(False)
+            self.get_widget('edit').set_sensitive(False)
             self.reports.do_graph()
 
+
+    def on_add_clicked(self, button):
+        selection = self.fact_tree.get_selection()
+        (model, iter) = selection.get_selected()
+
+        selected_date = self.view_date
+        if iter and model[iter][6]: # TODO - here we should check if heading maybe specifies a date
+            selected_date = model[iter][6]["date"]
+
+        custom_fact = CustomFactController(self, selected_date)
+        custom_fact.show()
+
+    def on_remove_clicked(self, button):
+        self.delete_selected()
+
+    def on_edit_clicked(self, button):
+        selection = self.fact_tree.get_selection()
+        (model, iter) = selection.get_selected()
+
+        if model[iter][0] == -1:
+            return #not a fact
+
+        custom_fact = CustomFactController(self, None, model[iter][0])
+        custom_fact.show()
+
+
+
+
     def on_close(self, widget, event):
-        runtime.dispatcher.del_handler('activity_updated',
-                                       self.after_activity_update)
+        runtime.dispatcher.del_handler('activity_updated', self.after_activity_update)
         runtime.dispatcher.del_handler('day_updated', self.after_fact_update)
         self.close_window()        
 
diff --git a/hamster/stats_overview.py b/hamster/stats_overview.py
index 4ecb721..cd72bc1 100644
--- a/hamster/stats_overview.py
+++ b/hamster/stats_overview.py
@@ -66,7 +66,6 @@ class OverviewBox(gtk.VBox):
         self.fact_tree = widgets.FactTree()
         self.get_widget("overview_facts_box").add(self.fact_tree)
         #self.fill_facts_tree()
-        self.fact_tree.connect("cursor-changed", self.on_fact_selection_changed)
         self.fact_tree.connect("row-activated", self.on_facts_row_activated)
         self.fact_tree.connect("key-press-event", self.on_facts_keys)
         self.fact_tree.connect("edit_clicked", lambda tree, fact: self.on_edit_clicked(fact))
@@ -106,41 +105,12 @@ class OverviewBox(gtk.VBox):
     def after_activity_update(self, widget, renames):
         self.fill_facts_tree()
 
-    def on_fact_selection_changed(self, tree):
-        """ enables and disables action buttons depending on selected item """
-        selection = tree.get_selection()
-        (model, iter) = selection.get_selected()
-
-        id = -1
-        if iter:
-            id = model[iter][0]
-
-        #self.get_widget('remove').set_sensitive(id != -1)
-        #self.get_widget('edit').set_sensitive(id != -1)
-
-        return True
-
     def on_facts_row_activated(self, tree, path, column):
         selection = tree.get_selection()
         (model, iter) = selection.get_selected()
         custom_fact = CustomFactController(self, None, model[iter][0])
         custom_fact.show()
         
-
-    def on_add_clicked(self, button):
-        selection = self.fact_tree.get_selection()
-        (model, iter) = selection.get_selected()
-
-        selected_date = self.view_date
-        if iter:
-            selected_date = model[iter][6]["date"]
-
-        custom_fact = CustomFactController(self, selected_date)
-        custom_fact.show()
-
-    def on_remove_clicked(self, button):
-        self.delete_selected()
-
     def on_facts_keys(self, tree, event):
         if (event.keyval == gtk.keysyms.Delete):
             self.delete_selected()
@@ -148,16 +118,6 @@ class OverviewBox(gtk.VBox):
         
         return False
 
-    def on_edit_clicked(self, button):
-        selection = self.fact_tree.get_selection()
-        (model, iter) = selection.get_selected()
-
-        if model[iter][0] == -1:
-            return #not a fact
-
-        custom_fact = CustomFactController(self, None, model[iter][0])
-        custom_fact.show()
-
     def delete_selected(self):
         selection = self.fact_tree.get_selection()
         (model, iter) = selection.get_selected()
@@ -256,16 +216,3 @@ class OverviewBox(gtk.VBox):
         return self._gui.get_object(name)
 
 
-
-
-if __name__ == "__main__":
-    gtk.window_set_default_icon_name("hamster-applet")
-    
-    window = gtk.Window()
-    window.set_title("Hamster - overview")
-    window.set_size_request(800, 600)
-    
-    window.add(OverviewBox())
-
-    window.show_all()    
-    gtk.main()    



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