[billreminder/fresh] initial cleanup



commit f4167fadae5ce9df277569a4257436fa76b8abb5
Author: Toms Bauģis <toms baugis gmail com>
Date:   Wed Jan 13 22:53:08 2010 +0000

    initial cleanup

 DONE                              |   38 --------
 TODO                              |   27 ------
 src/billreminder.py               |   12 ++-
 src/gui/adddialog.py              |   47 ++++------
 src/gui/maindialog.py             |  174 +++++++++++++----------------------
 src/gui/widgets/SearchEntry.py    |  184 -------------------------------------
 src/gui/widgets/__init__.py       |   14 +++
 src/gui/widgets/calendarwidget.py |  145 -----------------------------
 src/lib/utils.py                  |    8 ++
 9 files changed, 114 insertions(+), 535 deletions(-)
---
diff --git a/src/billreminder.py b/src/billreminder.py
old mode 100644
new mode 100755
index 710f278..63c462a
--- a/src/billreminder.py
+++ b/src/billreminder.py
@@ -1,8 +1,10 @@
+#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
 import sys
 import os
 from optparse import OptionParser
+import datetime as dt
 
 current_path = os.path.realpath(__file__)
 basedir = os.path.dirname(os.path.realpath(__file__))
@@ -13,7 +15,6 @@ sys.path.insert(0, basedir)
 os.chdir(basedir)
 
 
-
 try:
     import pygtk
     pygtk.require("2.0")
@@ -38,8 +39,14 @@ from lib import common
 from lib import i18n
 from gui.maindialog import MainDialog as BillReminder
 
-def main():
+# migrate settings to gconf
+# TODO - move to fixtures / consider for removal
+if os.path.exists(os.path.join(common.USER_CFG_PATH, common.CFG_NAME)):
+    from lib.migrate_to_gconf import migrate
+    migrate(os.path.join(common.USER_CFG_PATH, common.CFG_NAME))
+
 
+def main():
     #args = sys.argv
     parser = OptionParser()
     parser.set_usage(_("Usage:  billreminder [OPTIONS...]"))
@@ -50,6 +57,7 @@ def main():
 
     # Verify arguments
     options, args = parser.parse_args()
+
     if options.app_about:
         dialogs.about_dialog()
     elif options.app_add:
diff --git a/src/gui/adddialog.py b/src/gui/adddialog.py
index 2417c1f..b44a632 100644
--- a/src/gui/adddialog.py
+++ b/src/gui/adddialog.py
@@ -1,10 +1,5 @@
 # -*- coding: utf-8 -*-
 
-__all__ = ['AddDialog']
-
-import os
-import pygtk
-pygtk.require('2.0')
 import gtk
 import datetime
 import locale
@@ -13,14 +8,14 @@ import gobject
 from lib import utils
 from lib import common
 from lib import scheduler
-from db.entities import Bill, Category
 from lib.actions import Actions
-from lib.utils import create_pixbuf
+from db.entities import Bill
 from lib import i18n
-from gui.widgets.datebutton import DateButton
-from gui.widgets.datepicker import DatePicker
+
+from gui import widgets
+
+
 from gui.categoriesdialog import CategoriesDialog
-#from lib.config import Configuration
 from lib.Settings import Settings as Configuration
 
 class AddDialog(object):
@@ -28,10 +23,10 @@ class AddDialog(object):
     Class used to generate dialog to allow user to enter/edit records.
     """
     def __init__(self, title=None, parent=None, record=None, selectedDate=None):
-        self.ui = gtk.Builder()
-        self.ui.add_from_file(os.path.join(common.DEFAULT_CFG_PATH, "add_bill.ui"))
-
+        self.ui = utils.load_ui_file("add_bill.ui")
         self.window = self.ui.get_object("add_bill_dialog")
+        self.actions = Actions()
+
 
         self.window.set_icon_from_file(common.APP_ICON)
 
@@ -72,11 +67,11 @@ class AddDialog(object):
     def _initialize_dialog_widgets(self):
         self.frequency = self.ui.get_object("frequency")
 
-        self.dueDate = DatePicker()
+        self.dueDate = widgets.DatePicker()
         self.ui.get_object("due_date_box").add(self.dueDate)
         self.dueDate.connect('date_changed', self._on_datepicker_date_changed)
 
-        self.endDate = DatePicker()
+        self.endDate = widgets.DatePicker()
         self.ui.get_object("end_date_box").add(self.endDate)
 
         self.payee = self.ui.get_object("payee")
@@ -99,7 +94,7 @@ class AddDialog(object):
         self.notes = self.ui.get_object("notes")
         self.txtbuffer = self.notes.get_buffer()
 
-        self.alarmbutton = DateButton(self.window)
+        self.alarmbutton = widgets.DateButton(self.window)
         self.alarmbutton.set_tooltip_text(_("Select Date and Time"))
         self.ui.get_object("alarm_button_box").add(self.alarmbutton)
         self.ui.get_object("alarm_label").set_mnemonic_widget(self.alarmbutton)
@@ -147,9 +142,8 @@ class AddDialog(object):
         utils.select_combo_text(self.payee, self.currentrecord.payee)
 
         if self.currentrecord.category:
-            actions = Actions()
             cat_name = self.currentrecord.category.name
-            records = actions.get_categories(name=cat_name)
+            records = self.actions.get_categories(name=cat_name)
             if records:
                 categoryname = records[0].name
                 utils.select_combo_text(self.category, categoryname, 1)
@@ -166,11 +160,9 @@ class AddDialog(object):
     def _populate_payee(self):
         """ Populates combobox with existing payees """
         # Connects to the database
-        actions = Actions()
-
         # List of payees from database
         payees = []
-        records = actions.get_bills()
+        records = self.actions.get_bills()
         for rec in records:
             if rec.payee not in payees:
                 payees.append(rec.payee)
@@ -217,20 +209,18 @@ class AddDialog(object):
     def _populate_category(self, categoryname=None):
         """ Populates combobox with existing categories """
         # Connects to the database
-        actions = Actions()
-
         # List of categories from database
         categories = []
-        records = actions.get_categories()
+        records = self.actions.get_categories()
 
         ret = 0
-        empty_color = create_pixbuf()
+        empty_color = utils.create_pixbuf()
         for rec in records:
             #if [rec['categoryname'], rec['id']] not in categories:
             #TODO: Better put color creation in a function
             color = rec.color and rec.color or '#000'
 
-            categories.append([create_pixbuf(color=color), rec.name, int(rec.id)])
+            categories.append([utils.create_pixbuf(color=color), rec.name, int(rec.id)])
             if categoryname and categoryname == rec.name:
                 ret = len(categories) + 1
 
@@ -250,9 +240,6 @@ class AddDialog(object):
 
     def _get_category(self):
         """ Extracts information typed into comboboxentry """
-
-        actions = Actions()
-
         if self.category.get_active_iter() is not None:
             model = self.category.get_model()
             iteration = self.category.get_active_iter()
@@ -264,7 +251,7 @@ class AddDialog(object):
         if not name or name == _("None"):
             return None
 
-        records = actions.get_categories(name=name)
+        records = self.actions.get_categories(name=name)
         if records:
             return records[0]
         else:
diff --git a/src/gui/maindialog.py b/src/gui/maindialog.py
index 1d71aa9..bc2c893 100644
--- a/src/gui/maindialog.py
+++ b/src/gui/maindialog.py
@@ -1,68 +1,39 @@
+#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
-__all__ = ['MainDialog']
-
-import os
-
-import pygtk
-pygtk.require('2.0')
 import gtk
-import time
-import datetime
+import datetime as dt
 from gobject import timeout_add
 
-# Import widgets modules
-from gui.widgets.statusbar import Statusbar
-from gui.widgets.viewbill import ViewBill as ViewBill
-from gui.widgets.trayicon import NotifyIcon
-from gui.widgets.chartwidget import ChartWidget
-from gui.widgets.timeline import Timeline, Bullet
-
-# Import data model modules
-from lib.bill import Bill
-from lib.actions import Actions
+from gui import widgets
+from lib.actions import Actions # data model
 
 # Import common utilities
 from lib import common
 from lib import dialogs
-from lib import scheduler
-#from lib.config import Configuration
+
 from lib.Settings import Settings as Configuration
-from lib.utils import Message
-from lib.utils import get_dbus_interface
-from lib.utils import force_string
-from lib.utils import create_pixbuf
+from lib import utils
 from lib import i18n
 
-from lib.common import GCONF_PATH, GCONF_GUI_PATH, GCONF_ALARM_PATH
-from lib.common import CFG_NAME
-from lib.common import USER_CFG_PATH, DEFAULT_CFG_PATH
-from os.path import exists, join
-
 class MainDialog:
     search_text = ""
     _bullet_cache = {}
 
     def __init__(self):
-        if exists(join(USER_CFG_PATH, CFG_NAME)):
-            from lib.migrate_to_gconf import migrate
-            migrate(join(USER_CFG_PATH, CFG_NAME))
-
         self.gconf_client = Configuration()
-        self.message = Message()
+        self.message = utils.Message()
         # Connects to the database
         self.actions = Actions()
 
-
-        self.ui = gtk.Builder()
-        self.ui.add_from_file(os.path.join(DEFAULT_CFG_PATH, "main.ui"))
+        self.ui = utils.load_ui_file("main.ui")
 
         self.window = self.ui.get_object("main_window")
         self.window.set_title("%s" % common.APPNAME)
         self.window.set_icon_from_file(common.APP_ICON)
 
         # ViewBill
-        self.list = ViewBill()
+        self.list = widgets.ViewBill()
         self.list.connect('cursor_changed', self._on_list_cursor_changed)
         self.list.connect('row_activated', self._on_list_row_activated)
         self.list.connect('button_press_event', self._on_list_button_press_event)
@@ -76,16 +47,16 @@ class MainDialog:
         self._populate_menubar()
 
         # Statusbar
-        self.statusbar = Statusbar()
+        self.statusbar = widgets.Statusbar()
         self.ui.get_object("statusbar_box").add(self.statusbar)
 
         # Timeline
-        self.timeline = Timeline(callback=self.on_timeline_cb)
+        self.timeline = widgets.Timeline(callback=self.on_timeline_cb)
         self.timeline.connect("value-changed", self._on_timeline_changed)
         self.ui.get_object("timeline_box").add(self.timeline)
 
         # Chart
-        self.chart = ChartWidget()
+        self.chart = widgets.ChartWidget()
         self.ui.get_object("chart_box").add(self.chart)
 
         # Restore position and size of window
@@ -111,11 +82,11 @@ class MainDialog:
 
         # populate treeview
         self.reloadTreeView()
-        self.notify = NotifyIcon(self)
+        self.notify = widgets.NotifyIcon(self)
 
         # Connects to the Daemon
         self.iface = None
-        iface = get_dbus_interface(common.DBUS_INTERFACE, common.DBUS_PATH)
+        iface = utils.get_dbus_interface(common.DBUS_INTERFACE, common.DBUS_PATH)
         if iface:
             iface.connect_to_signal("bill_edited", self.reloadTreeView)
             iface.connect_to_signal("bill_edited", self.reloadTimeline)
@@ -149,17 +120,9 @@ class MainDialog:
 
     # Methods:  UI
     def _send_tray_hints(self):
-        self.iface.set_tray_hints(force_string(self.notify.get_hints()))
+        self.iface.set_tray_hints(utils.force_string(self.notify.get_hints()))
         timeout_add(60000, self._send_tray_hints)
 
-    def get_window_visibility(self):
-        return self.window.get_property("visible")
-
-    def show_hide_window(self):
-        if self.window.get_property("visible"):
-            self.window.hide()
-        else:
-            self.window.show()
 
     def get_selected_record(self):
         """ Returns a bill object from the current selected record """
@@ -233,7 +196,7 @@ class MainDialog:
         categoryColor = row.category.color if row.category else '#d3d7cf'
         formatted = [
             row.id,
-            create_pixbuf(color=categoryColor),
+            utils.create_pixbuf(color=categoryColor),
             categoryName,
             row.payee,
             row.dueDate.strftime(_('%m/%d').encode('ASCII')),
@@ -282,42 +245,6 @@ class MainDialog:
         self.ui.get_object("showToolbar").set_active(self.gconf_client.get('show_toolbar'))
 
 
-    def add_bill(self):
-        selectedDate = self.timeline.value
-        records = dialogs.add_dialog(parent=self.window, selectedDate=selectedDate)
-
-        # Checks if the user did not cancel the action
-        if records:
-            # Add new bill to database
-            for rec in records:
-                bill = self.actions.add(rec)
-                if bill:
-                    self.list.add(self.format_row(bill))
-            self.update_statusbar()
-            # Reload records tree (something changed)
-            self.reloadTreeView()
-            self.reloadTimeline()
-
-    def edit_bill(self):
-        records = dialogs.edit_dialog(parent=self.window, record=self.currentrecord)
-
-        # Checks if the user did not cancel the action
-        if records:
-            for rec in records:
-                # Edit bill to database
-                rec = self.actions.edit(rec)
-
-            # Reload records tree (something changed)
-            self.reloadTreeView()
-            self.reloadTimeline()
-
-    def remove_bill(self):
-        self.actions.delete(self.currentrecord)
-        self.list.remove()
-        self.update_statusbar()
-        self.reloadTreeView()
-        self.reloadTimeline()
-
     def toggle_bill_paid(self):
         # Fetch record from database
         record = self.actions.get_bills(id=self.currentrecord.id)[0]
@@ -337,12 +264,6 @@ class MainDialog:
         self.reloadTreeView()
         self.reloadTimeline()
 
-    def about(self):
-        dialogs.about_dialog(parent=self.window)
-
-    def preferences(self):
-        dialogs.preferences_dialog(parent=self.window)
-
     # Methods
     def _quit_application(self):
         self.save_position()
@@ -412,20 +333,55 @@ class MainDialog:
         self.update_statusbar()
 
     def on_newBill_activate(self, toolbutton):
-        self.add_bill()
+        selectedDate = self.timeline.value
+        records = dialogs.add_dialog(parent=self.window, selectedDate=selectedDate)
+
+        # Checks if the user did not cancel the action
+        if records:
+            # Add new bill to database
+            for rec in records:
+                bill = self.actions.add(rec)
+                if bill:
+                    self.list.add(self.format_row(bill))
+            self.update_statusbar()
+            # Reload records tree (something changed)
+            self.reloadTreeView()
+            self.reloadTimeline()
 
     def on_editBill_activate(self, toolbutton):
-        if self.currentrecord:
-            self.edit_bill()
+        if not self.currentrecord:
+            return
+        
+        records = dialogs.edit_dialog(parent=self.window, record=self.currentrecord)
+
+        # Checks if the user did not cancel the action
+        if records:
+            for rec in records:
+                # Edit bill to database
+                rec = self.actions.edit(rec)
+
+            # Reload records tree (something changed)
+            self.reloadTreeView()
+            self.reloadTimeline()
+
 
     def on_removeBill_activate(self, toolbutton):
-        if self.currentrecord:
-            resp = self.message.ShowQuestionYesNo(
-                _("Do you really want to delete \"%s\"?") % \
-                self.currentrecord.payee,
-                self.window, _("Confirmation"))
-            if resp:
-                self.remove_bill()
+        if not self.currentrecord:
+            return
+
+        resp = self.message.ShowQuestionYesNo(
+            _("Do you really want to delete \"%s\"?") % \
+            self.currentrecord.payee,
+            self.window, _("Confirmation"))
+        if not resp:
+            return
+
+        self.actions.delete(self.currentrecord)
+        self.list.remove()
+        self.update_statusbar()
+        self.reloadTreeView()
+        self.reloadTimeline()
+
 
     def on_markNotPaid_activate(self, toolbutton):
         self.on_markPaid_activate(toolbutton) # forward
@@ -435,10 +391,10 @@ class MainDialog:
             self.toggle_bill_paid()
 
     def on_btnAbout_activate(self, toolbutton):
-        self.about()
+        dialogs.about_dialog(parent=self.window)
 
     def on_btnPrefs_activate(self, toolbutton):
-        self.preferences()
+        dialogs.preferences_dialog(parent=self.window)
 
     def on_btnQuit_activate(self, toolbutton):
         self._quit_application()
@@ -491,7 +447,7 @@ class MainDialog:
             status = self.gconf_client.get('show_paid_bills')
             amount = 0
             tooltip = ''
-            bullet = Bullet()
+            bullet = widgets.Bullet()
             bullet.date = date
 
             for bill in self._bullet_cache[date]:
@@ -505,7 +461,7 @@ class MainDialog:
                 if bill.paid:
                     if status == 0: return False
                     bullet.status = bullet.status | bullet.PAID
-                elif date <= datetime.date.today():
+                elif date <= dt.date.today():
                     if status == 1: return False
                     bullet.status = bullet.status | bullet.OVERDUE
                 else:
diff --git a/src/gui/widgets/__init__.py b/src/gui/widgets/__init__.py
index 40a96af..3e382da 100644
--- a/src/gui/widgets/__init__.py
+++ b/src/gui/widgets/__init__.py
@@ -1 +1,15 @@
 # -*- coding: utf-8 -*-
+
+# all the available widgets
+# TODO - revise the list and remove orphaned widgets
+
+from chartwidget import ChartWidget
+from datebutton import DateButton
+from datepicker import DatePicker
+from genericlistview import GenericListView
+from statusbar import Statusbar
+from timeline import Timeline, Bullet
+from toolbar import Toolbar
+from trayicon import NotifyIcon
+from viewbill import ViewBill
+from viewcategory import ViewCategory
\ No newline at end of file
diff --git a/src/lib/utils.py b/src/lib/utils.py
index 02ed45e..1df79f9 100644
--- a/src/lib/utils.py
+++ b/src/lib/utils.py
@@ -25,6 +25,14 @@ except ImportError, e:
 
 from lib import i18n
 
+
+def load_ui_file(name):
+    import common
+    ui = gtk.Builder()
+    ui.add_from_file(os.path.join(common.DEFAULT_CFG_PATH, name))
+    return ui
+
+
 class ContextMenu(gtk.Menu):
     """ Creates context menus accessed by mouse right click. """
     def __init__(self, *args):



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