[billreminder/fresh] simplified



commit e255f320483944e4b7e7c1da626f112020926672
Author: Toms Bauģis <toms baugis gmail com>
Date:   Wed Jan 20 01:26:57 2010 +0000

    simplified

 data/new.ui    |  422 +++++++-------------------------------------------------
 src/gui/new.py |  114 +++++++++++++---
 2 files changed, 144 insertions(+), 392 deletions(-)
---
diff --git a/data/new.ui b/data/new.ui
index 05e5cb5..6d80e0e 100644
--- a/data/new.ui
+++ b/data/new.ui
@@ -3,6 +3,7 @@
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy project-wide -->
   <object class="GtkWindow" id="main_window">
+    <property name="border_width">12</property>
     <property name="default_width">600</property>
     <property name="default_height">400</property>
     <signal name="delete_event" handler="on_delete_event"/>
@@ -10,186 +11,16 @@
       <object class="GtkVBox" id="vbox1">
         <property name="visible">True</property>
         <property name="orientation">vertical</property>
+        <property name="spacing">10</property>
         <child>
-          <object class="GtkAlignment" id="menu_box">
+          <object class="GtkLabel" id="range_title">
             <property name="visible">True</property>
-            <child>
-              <object class="GtkMenuBar" id="menubar1">
-                <property name="visible">True</property>
-                <child>
-                  <object class="GtkMenuItem" id="menuitem1">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">_Bill</property>
-                    <property name="use_underline">True</property>
-                    <child type="submenu">
-                      <object class="GtkMenu" id="menu1">
-                        <property name="visible">True</property>
-                        <child>
-                          <object class="GtkImageMenuItem" id="imagemenuitem1">
-                            <property name="label">gtk-new</property>
-                            <property name="visible">True</property>
-                            <property name="related_action">newBill</property>
-                            <property name="use_underline">True</property>
-                            <property name="use_stock">True</property>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkImageMenuItem" id="imagemenuitem2">
-                            <property name="label">gtk-open</property>
-                            <property name="visible">True</property>
-                            <property name="related_action">editBill</property>
-                            <property name="use_underline">True</property>
-                            <property name="use_stock">True</property>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkImageMenuItem" id="imagemenuitem3">
-                            <property name="label">gtk-save</property>
-                            <property name="visible">True</property>
-                            <property name="related_action">removeBill</property>
-                            <property name="use_underline">True</property>
-                            <property name="use_stock">True</property>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
-                            <property name="visible">True</property>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkImageMenuItem" id="btnQuit">
-                            <property name="label">gtk-quit</property>
-                            <property name="visible">True</property>
-                            <property name="use_underline">True</property>
-                            <property name="use_stock">True</property>
-                            <signal name="activate" handler="on_btnQuit_activate"/>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkMenuItem" id="menuitem2">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">_Edit</property>
-                    <property name="use_underline">True</property>
-                    <child type="submenu">
-                      <object class="GtkMenu" id="menu2">
-                        <property name="visible">True</property>
-                        <child>
-                          <object class="GtkImageMenuItem" id="imagemenuitem6">
-                            <property name="label">gtk-cut</property>
-                            <property name="visible">True</property>
-                            <property name="related_action">markPaid</property>
-                            <property name="use_underline">True</property>
-                            <property name="use_stock">True</property>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkImageMenuItem" id="imagemenuitem7">
-                            <property name="label">gtk-copy</property>
-                            <property name="visible">True</property>
-                            <property name="related_action">markNotPaid</property>
-                            <property name="use_underline">True</property>
-                            <property name="use_stock">True</property>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkSeparatorMenuItem" id="menuitem5">
-                            <property name="visible">True</property>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkImageMenuItem" id="btnPrefs">
-                            <property name="label">gtk-preferences</property>
-                            <property name="visible">True</property>
-                            <property name="use_underline">True</property>
-                            <property name="use_stock">True</property>
-                            <signal name="activate" handler="on_btnPrefs_activate"/>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkMenuItem" id="menuitem3">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">_View</property>
-                    <property name="use_underline">True</property>
-                    <child type="submenu">
-                      <object class="GtkMenu" id="menu4">
-                        <property name="visible">True</property>
-                        <child>
-                          <object class="GtkCheckMenuItem" id="menuitem6">
-                            <property name="visible">True</property>
-                            <property name="related_action">showToolbar</property>
-                            <property name="label" translatable="yes">Show Toolbar</property>
-                            <property name="use_underline">True</property>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkSeparatorMenuItem" id="menuitem7">
-                            <property name="visible">True</property>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkRadioMenuItem" id="showPaid">
-                            <property name="visible">True</property>
-                            <property name="label" translatable="yes">Paid Only</property>
-                            <property name="use_underline">True</property>
-                            <property name="draw_as_radio">True</property>
-                            <signal name="toggled" handler="on_showPaid_toggled"/>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkRadioMenuItem" id="showNotPaid">
-                            <property name="visible">True</property>
-                            <property name="label" translatable="yes">Not Paid Only</property>
-                            <property name="use_underline">True</property>
-                            <property name="draw_as_radio">True</property>
-                            <property name="group">showPaid</property>
-                            <signal name="toggled" handler="on_showNotPaid_toggled"/>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkRadioMenuItem" id="showAll">
-                            <property name="visible">True</property>
-                            <property name="label" translatable="yes">All Bills</property>
-                            <property name="use_underline">True</property>
-                            <property name="draw_as_radio">True</property>
-                            <property name="group">showPaid</property>
-                            <signal name="toggled" handler="on_showAll_toggled"/>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkMenuItem" id="menuitem4">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">_Help</property>
-                    <property name="use_underline">True</property>
-                    <child type="submenu">
-                      <object class="GtkMenu" id="menu3">
-                        <property name="visible">True</property>
-                        <child>
-                          <object class="GtkImageMenuItem" id="btnAbout">
-                            <property name="label">gtk-about</property>
-                            <property name="visible">True</property>
-                            <property name="use_underline">True</property>
-                            <property name="use_stock">True</property>
-                            <signal name="activate" handler="on_btnAbout_activate"/>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
+            <property name="xalign">0</property>
+            <property name="label">January 1-31, 2010</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+              <attribute name="size" value="15000"/>
+            </attributes>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -197,72 +28,11 @@
           </packing>
         </child>
         <child>
-          <object class="GtkToolbar" id="toolbar">
+          <object class="GtkAlignment" id="time_box">
+            <property name="height_request">100</property>
             <property name="visible">True</property>
             <child>
-              <object class="GtkToolButton" id="toolbutton1">
-                <property name="visible">True</property>
-                <property name="tooltip_text" translatable="yes">Add a new bill</property>
-                <property name="related_action">newBill</property>
-                <property name="use_underline">True</property>
-                <property name="stock_id">gtk-new</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="homogeneous">True</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkToolButton" id="btnEdit">
-                <property name="visible">True</property>
-                <property name="tooltip_text" translatable="yes">Edit a bill</property>
-                <property name="related_action">editBill</property>
-                <property name="use_underline">True</property>
-                <property name="stock_id">gtk-edit</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="homogeneous">True</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkToolButton" id="btnRemove">
-                <property name="visible">True</property>
-                <property name="tooltip_text" translatable="yes">Delete selected bill</property>
-                <property name="related_action">removeBill</property>
-                <property name="use_underline">True</property>
-                <property name="stock_id">gtk-delete</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="homogeneous">True</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkToolButton" id="btnPaid">
-                <property name="visible">True</property>
-                <property name="tooltip_text" translatable="yes">Mark as paid</property>
-                <property name="related_action">markPaid</property>
-                <property name="use_underline">True</property>
-                <property name="stock_id">gtk-apply</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="homogeneous">True</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkToolButton" id="btnNotPaid">
-                <property name="visible">True</property>
-                <property name="tooltip_text" translatable="yes">Mark as not paid</property>
-                <property name="related_action">markNotPaid</property>
-                <property name="use_underline">True</property>
-                <property name="stock_id">gtk-undo</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="homogeneous">True</property>
-              </packing>
+              <placeholder/>
             </child>
           </object>
           <packing>
@@ -271,64 +41,47 @@
           </packing>
         </child>
         <child>
-          <object class="GtkAlignment" id="alignment1">
+          <object class="GtkHBox" id="hbox1">
             <property name="visible">True</property>
-            <property name="top_padding">10</property>
-            <property name="bottom_padding">10</property>
-            <property name="left_padding">10</property>
-            <property name="right_padding">10</property>
+            <property name="spacing">10</property>
+            <child>
+              <object class="GtkScrolledWindow" id="scrollbox99">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hscrollbar_policy">automatic</property>
+                <property name="vscrollbar_policy">automatic</property>
+                <child>
+                  <object class="GtkViewport" id="upcoming_box">
+                    <property name="visible">True</property>
+                    <property name="resize_mode">queue</property>
+                    <child>
+                      <object class="GtkAlignment" id="bill_box">
+                        <property name="visible">True</property>
+                        <child>
+                          <placeholder/>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="position">0</property>
+              </packing>
+            </child>
             <child>
-              <object class="GtkHBox" id="hbox1">
+              <object class="GtkAlignment" id="totals">
+                <property name="width_request">250</property>
                 <property name="visible">True</property>
-                <property name="spacing">10</property>
                 <child>
                   <object class="GtkVBox" id="vbox2">
                     <property name="visible">True</property>
                     <property name="orientation">vertical</property>
-                    <property name="spacing">10</property>
                     <child>
-                      <object class="GtkFrame" id="frame1">
+                      <object class="GtkAlignment" id="by_type">
                         <property name="visible">True</property>
-                        <property name="label_xalign">0</property>
-                        <property name="shadow_type">none</property>
                         <child>
-                          <object class="GtkAlignment" id="alignment2">
-                            <property name="visible">True</property>
-                            <property name="left_padding">12</property>
-                            <child>
-                              <object class="GtkScrolledWindow" id="scrollbox99">
-                                <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="hscrollbar_policy">automatic</property>
-                                <property name="vscrollbar_policy">automatic</property>
-                                <child>
-                                  <object class="GtkViewport" id="upcoming_box">
-                                    <property name="visible">True</property>
-                                    <property name="resize_mode">queue</property>
-                                    <child>
-                                      <object class="GtkAlignment" id="bill_box">
-                                        <property name="visible">True</property>
-                                        <child>
-                                          <placeholder/>
-                                        </child>
-                                      </object>
-                                    </child>
-                                  </object>
-                                </child>
-                              </object>
-                            </child>
-                          </object>
-                        </child>
-                        <child type="label">
-                          <object class="GtkLabel" id="label1">
-                            <property name="visible">True</property>
-                            <property name="xalign">0.49000000953674316</property>
-                            <property name="label" translatable="yes">Upcoming bills</property>
-                            <property name="use_markup">True</property>
-                            <attributes>
-                              <attribute name="weight" value="bold"/>
-                            </attributes>
-                          </object>
+                          <placeholder/>
                         </child>
                       </object>
                       <packing>
@@ -336,113 +89,40 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkFrame" id="frame2">
+                      <object class="GtkAlignment" id="by_category">
                         <property name="visible">True</property>
-                        <property name="label_xalign">0</property>
-                        <property name="shadow_type">none</property>
                         <child>
-                          <object class="GtkAlignment" id="alignment3">
-                            <property name="visible">True</property>
-                            <property name="left_padding">12</property>
-                            <child>
-                              <object class="GtkScrolledWindow" id="paidBillsContainer">
-                                <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="hscrollbar_policy">automatic</property>
-                                <property name="vscrollbar_policy">automatic</property>
-                                <child>
-                                  <object class="GtkTreeView" id="paid_tree">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">True</property>
-                                  </object>
-                                </child>
-                              </object>
-                            </child>
-                          </object>
-                        </child>
-                        <child type="label">
-                          <object class="GtkLabel" id="label2">
-                            <property name="visible">True</property>
-                            <property name="label" translatable="yes">&lt;b&gt;Paid bills&lt;/b&gt;</property>
-                            <property name="use_markup">True</property>
-                          </object>
+                          <placeholder/>
                         </child>
                       </object>
                       <packing>
                         <property name="position">1</property>
                       </packing>
                     </child>
-                  </object>
-                  <packing>
-                    <property name="padding">2</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkAlignment" id="graph_box">
-                    <property name="width_request">150</property>
-                    <property name="visible">True</property>
                     <child>
                       <placeholder/>
                     </child>
                   </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="position">1</property>
-                  </packing>
                 </child>
               </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">1</property>
+              </packing>
             </child>
           </object>
           <packing>
             <property name="position">2</property>
           </packing>
         </child>
-        <child>
-          <object class="GtkStatusbar" id="statusbar_box">
-            <property name="visible">True</property>
-            <property name="spacing">2</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="position">3</property>
-          </packing>
-        </child>
       </object>
     </child>
   </object>
-  <object class="GtkAction" id="newBill">
-    <property name="stock_id">gtk-new</property>
-    <signal name="activate" handler="on_newBill_activate"/>
-  </object>
-  <object class="GtkAction" id="editBill">
-    <property name="stock_id">gtk-edit</property>
-    <signal name="activate" handler="on_editBill_activate"/>
-  </object>
-  <object class="GtkAction" id="removeBill">
-    <property name="stock_id">gtk-delete</property>
-    <signal name="activate" handler="on_removeBill_activate"/>
-  </object>
-  <object class="GtkAction" id="markPaid">
-    <property name="stock_id">gtk-apply</property>
-    <property name="is_important">True</property>
-    <signal name="activate" handler="on_markPaid_activate"/>
-  </object>
-  <object class="GtkAction" id="markNotPaid">
-    <property name="stock_id">gtk-undo</property>
-    <property name="is_important">True</property>
-    <signal name="activate" handler="on_markNotPaid_activate"/>
-  </object>
-  <object class="GtkToggleAction" id="showToolbar">
-    <property name="active">True</property>
-    <signal name="toggled" handler="on_showToolbar_toggled"/>
-  </object>
   <object class="GtkMenu" id="context_menu">
     <property name="visible">True</property>
     <child>
       <object class="GtkImageMenuItem" id="menuitem8">
         <property name="visible">True</property>
-        <property name="related_action">newBill</property>
         <property name="use_underline">True</property>
         <property name="use_stock">True</property>
       </object>
@@ -450,7 +130,6 @@
     <child>
       <object class="GtkImageMenuItem" id="menuitem9">
         <property name="visible">True</property>
-        <property name="related_action">removeBill</property>
         <property name="use_underline">True</property>
         <property name="use_stock">True</property>
       </object>
@@ -458,7 +137,6 @@
     <child>
       <object class="GtkImageMenuItem" id="menuitem10">
         <property name="visible">True</property>
-        <property name="related_action">editBill</property>
         <property name="use_underline">True</property>
         <property name="use_stock">True</property>
       </object>
@@ -466,7 +144,6 @@
     <child>
       <object class="GtkImageMenuItem" id="menuitem11">
         <property name="visible">True</property>
-        <property name="related_action">markPaid</property>
         <property name="use_underline">True</property>
         <property name="use_stock">True</property>
       </object>
@@ -474,7 +151,6 @@
     <child>
       <object class="GtkImageMenuItem" id="menuitem12">
         <property name="visible">True</property>
-        <property name="related_action">markNotPaid</property>
         <property name="use_underline">True</property>
         <property name="use_stock">True</property>
       </object>
diff --git a/src/gui/new.py b/src/gui/new.py
index 27beeac..8661909 100755
--- a/src/gui/new.py
+++ b/src/gui/new.py
@@ -6,48 +6,124 @@ from db import entities
 from lib import utils
 import widgets
 
-import datetime as dt
+from lib.actions import Actions # data model
+from widgets import charting
+
+import itertools
 
-TODAY = dt.date.today()
-NEXT_WEEK = TODAY + dt.timedelta(days=7)
-LAST_WEEK = TODAY - dt.timedelta(days=7)
+import datetime as dt
+import calendar
 
 class MainWindow:
     def __init__(self):
         # Create a new window
         self.ui = utils.load_ui_file("new.ui")
         self.window = self.ui.get_object("main_window")
+        self.actions = Actions()
 
         self.upcoming = widgets.BillTree()
         self.ui.get_object("bill_box").add(self.upcoming)
 
-        self.window.show_all()
-        self.ui.connect_signals(self)
+
+        today = dt.date.today()
+        self.start_date = today - dt.timedelta(today.day - 1) # beginning of month
+        first_weekday, days_in_month = calendar.monthrange(today.year, today.month)
+        self.end_date = self.start_date + dt.timedelta(days_in_month - 1)
+
+        self.filtered_types = []
+        self.filtered_categories = []
+
+        self.type_chart = charting.HorizontalBarChart(interactive = True)
+        self.type_chart.max_bar_width = 20
+        self.type_chart.legend_width = 60
+        self.type_chart.connect("bar-clicked", self.on_type_chart_clicked)
+        self.get_widget("by_type").add(self.type_chart)
+
+        self.category_chart = charting.HorizontalBarChart(interactive = True)
+        self.category_chart.max_bar_width = 20
+        self.category_chart.legend_width = 60
+        self.category_chart.connect("bar-clicked", self.on_category_chart_clicked)
+        self.get_widget("by_category").add(self.category_chart)
 
         self.load_bills()
+        self.ui.connect_signals(self)
+        self.window.show_all()
 
     def load_bills(self):
+        self.set_title()
         self.upcoming.clear()
 
-        ht = entities.Bill('Harris Teeter', 123.94, TODAY)
-        food = entities.Category('Groceries', '#ad7fa8')
-        ht.category = food
+        start_date, end_date = self.start_date, self.end_date
 
-        aes = entities.Bill('Alan & Sons', 41.65, NEXT_WEEK)
-        dining = entities.Category('Dining', '#fce94f')
-        aes.category = dining
+        if 1 in self.filtered_types: # upcoming
+            start_date = dt.date.today() + dt.timedelta(days = 1)
 
-        energy = entities.Bill('Duke Energy', 62, LAST_WEEK)
-        utilities = entities.Category('Utilities', '#73d216')
-        energy.category = utilities
 
-        self.upcoming.add_bill(ht)
-        self.upcoming.add_bill(aes)
-        self.upcoming.add_bill(energy)
+        bills = self.actions.get_interval_bills(start_date, end_date)
+        for bill in bills:
+            self.upcoming.add_bill(bill)
+
+        self.update_graphs(bills)
+
+    def on_type_chart_clicked(self, area, idx):
+        if idx in self.filtered_types:
+            self.type_chart.bars_selected.remove(idx)
+            self.filtered_types.remove(idx)
+        else:
+            self.type_chart.bars_selected.append(idx)
+            self.filtered_types.append(idx)
+        self.load_bills()
 
 
+    def on_category_chart_clicked(self, area, idx):
+        if idx in self.filtered_categories:
+            self.category_chart.bars_selected.remove(idx)
+            self.filtered_categories.remove(idx)
+        else:
+            self.category_chart.bars_selected.append(idx)
+            self.filtered_categories.append(idx)
+        self.load_bills()
+
+    def set_title(self):
+        title = "%s - %s" % (self.start_date.strftime("%B %d"),
+                             self.end_date.strftime("%d, %Y"))
+
+        self.get_widget("range_title").set_text(title)
+
+
+    def update_graphs(self, bills):
+        today = dt.date.today()
+        # totals by type - paid, upcoming and overdue
+        bill_types = ("Paid", "Upcoming", "Overdue")
+        type_totals = [0,0,0]
+        for bill in bills:
+            if bill.paid:
+                type_totals[0] += float(bill.amount)
+            elif bill.dueDate > today: # upcoming
+                type_totals[1] += float(bill.amount)
+            else: # overdue
+                type_totals[2] += float(bill.amount)
+        self.type_chart.plot(bill_types, type_totals)
+
+
+
+        # totals by category
+        bills = sorted(bills, key=lambda bill: bill.category.name)
+        category_keys = []
+        category_amount = []
+        for category, totals in itertools.groupby(bills, lambda bill: bill.category):
+            total_amount = sum([float(total.amount) for total in totals])
+            category_keys.append(category.name)
+            category_amount.append(total_amount)
+
+        self.category_chart.plot(category_keys, category_amount)
+
+
+    def get_widget(self, name):
+        """ skip one variable (huh) """
+        return self.ui.get_object(name)
+
     # close the window and quit
     def on_delete_event(self, widget, event, data=None):
         gtk.main_quit()
         return False
-



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