Commit b904f620 authored by Og B. Maciel's avatar Og B. Maciel

New widgets added to support charting and new calendaring.

svn path=/trunk/; revision=643
parent 8196aad5
2008-09-23 Og Maciel <ogmaciel@gnome.org>
* src/gui/widgets/calendarwidget.py: New calendaring widget for the main dialog.
* src/gui/widgets/chartwidget.py: New charting widget.
* src/gui/widgets/charting.py: Charting library based off the hamster-applet.
* src/gui/maindialog.py: Added new calendar and chart widget.
* src/lib/actions.py: Added partial support for new method.
* src/lib/dbus_actions.py: Added partial support for new method.
* po/POTFILES.in: Added calendarwidget.py.
==== BillReminder 0.3.2 ====
2008-09-10 Og Maciel <ogmaciel@gnome.org>
......
......@@ -20,6 +20,7 @@ src/gui/adddialog.py
src/gui/categoriesdialog.py
src/gui/maindialog.py
src/gui/prefdialog.py
src/gui/widgets/calendarwidget.py
src/gui/widgets/datebutton.py
src/gui/widgets/genericlistview.py
src/gui/widgets/statusbar.py
......
......@@ -15,6 +15,8 @@ from gui.widgets.toolbar import Toolbar
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.calendarwidget import CalendarWidget
# Import data model modules
from lib.bill import Bill
......@@ -101,10 +103,6 @@ class MainDialog:
self._populate_menubar()
self.listbox = gtk.VBox(homogeneous=False, spacing=6)
self.listlabel = gtk.Label()
self.listlabel.set_markup_with_mnemonic(_("<b>_Bills:</b>"))
self.listlabel.set_mnemonic_widget(self.list)
self.listlabel.set_alignment(0.00, 0.50)
# ScrolledWindow
self.scrolledwindow = gtk.ScrolledWindow()
self.scrolledwindow.set_shadow_type(gtk.SHADOW_IN)
......@@ -112,8 +110,6 @@ class MainDialog:
gtk.POLICY_AUTOMATIC)
self.scrolledwindow.add(self.list)
## Pack it all up
self.listbox.pack_start(self.listlabel,
expand=False, fill=True, padding=1)
self.listbox.pack_start(self.scrolledwindow,
expand=True, fill=True, padding=2)
......@@ -122,20 +118,15 @@ class MainDialog:
# Calendar
self.calbox = gtk.VBox(homogeneous=False, spacing=1)
self.callabel = gtk.Label()
self.callabel.set_markup_with_mnemonic(_("<b>_Due Date:</b>"))
self.callabel.set_alignment(0.00, 0.50)
self.calendar = gtk.Calendar()
self.callabel.set_mnemonic_widget(self.calendar)
# Format the dueDate field
self.calendar.connect("month_changed", self._on_calendar_month_changed)
self.calendar.connect("day_selected_double_click", self._on_calendar_double_click)
self.calendar = CalendarWidget()
self.calendar.connect("date_changed", self._on_calendar_month_changed)
## Pack it all up
self.calbox.pack_start(self.callabel,
expand=False, fill=True, padding=1)
self.calbox.pack_start(self.calendar,
expand=True, fill=True, padding=2)
self.calendar.mark_day(datetime.datetime.today().day)
#self.calendar.mark_day(datetime.datetime.today().day)
# Chart
self.chart = ChartWidget()
# Pack it all up
self.box.pack_start(self.toolbar,
......@@ -144,6 +135,8 @@ class MainDialog:
expand=False, fill=True, padding=4)
self.box.pack_start(self.listbox,
expand=True, fill=True, padding=4)
self.box.pack_start(self.chart,
expand=True, fill=True, padding=2)
self.box.pack_start(self.statusbar,
expand=False, fill=True, padding=2)
......@@ -225,11 +218,6 @@ class MainDialog:
else:
self.currentrecord = None
def _markCalendar(self, records):
self.calendar.clear_marks()
for rec in records:
self.calendar.mark_day(datetime.datetime.fromtimestamp(rec['dueDate']).day)
def _populateTreeView(self, records):
""" Populates the treeview control with the records passed """
......@@ -247,8 +235,8 @@ class MainDialog:
def reloadTreeView(self, *arg):
# Update list with updated record
status = self.gconf_client.get_int(GCONF_GUI_PATH + 'show_paid_bills')
month = self.calendar.get_date()[1] + 1
year = self.calendar.get_date()[0]
month = self.calendar.currentMonth
year = self.calendar.currentYear
path = self.list.get_cursor()[0]
self.list.listStore.clear()
......@@ -260,9 +248,12 @@ class MainDialog:
# Populate treeview
self._populateTreeView(records)
# Mark days in calendar
self._markCalendar(records)
#self._markCalendar(records)
# Update status bar
self._update_statusbar()
# populate chart
self._populate_chart(status, month, year)
return len(records)
def _formated_row(self, row):
......@@ -305,6 +296,14 @@ class MainDialog:
_("Not Paid"), _("Mark as not paid"), self.on_btnPaid_clicked)
self.btnUnpaid.set_is_important(True)
def _populate_chart(self, status, month, year):
chartdata = []
records = self.actions.get_monthly_totals(status, month, year)
for rec in records:
chartdata.append([field for field in rec])
#if chartdata:
self.chart.plot(chartdata)
def _populate_menubar(self):
# Create a UIManager instance
self.uimanager = gtk.UIManager()
......@@ -371,8 +370,9 @@ class MainDialog:
self.box.pack_start(menubar, expand=False, fill=True, padding=0)
def add_bill(self):
selectedDate = scheduler.time_from_calendar(self.calendar.get_date())
selectedDate = scheduler.datetime_from_timestamp(selectedDate)
#selectedDate = scheduler.time_from_calendar(self.calendar.get_date())
#selectedDate = scheduler.datetime_from_timestamp(selectedDate)
selectedDate = self.calendar.currentDate
records = dialogs.add_dialog(parent=self.window, selectedDate=selectedDate)
# Checks if the user did not cancel the action
......@@ -574,10 +574,7 @@ class MainDialog:
def on_delete_event(self, widget, event, data=None):
self._quit_application()
def _on_calendar_double_click(self, widget):
self.add_bill()
def _on_calendar_month_changed(self, widget):
def _on_calendar_month_changed(self, widget, args):
self.reloadTreeView()
def _on_show_toolbar(self, action):
......
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import gobject
import datetime
from lib import i18n
MINDATE = 1900
MAXDATE = 3000
class CalendarWidget(gtk.HBox):
currentDate = None
# #define a custom signal
__gsignals__ = dict(date_changed=(gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)))
def __init__(self, currentDate=None):
gtk.HBox.__init__(self, False, 4)
if not currentDate:
currentDate = datetime.datetime.today()
self.currentDate = currentDate
self.currentYear = self.currentDate.year
self.currentMonth = self.currentDate.month
self.initialize_interface()
self.initialize_values()
def set_currentDate (self, value):
self.currentDate = value
self.currentYear = self.currentDate.year
self.currentMonth = self.currentDate.month
self.emit_date_changed_signal()
def emit_date_changed_signal(self):
self.emit("date_changed", self.currentDate)
def get_months (self):
year = self.currentYear
months = [datetime.datetime(year, x, 1).strftime("%B") for x in range(1,13)]
return months
def initialize_interface(self):
label1 = gtk.Label()
label1.set_markup_with_mnemonic(_("<b>_Monthly Report:</b>"))
self.monthSelector = gtk.combo_box_new_text()
self.monthSelector.connect("changed", self._on_monthSelector_changed)
self.populate_month_selector()
label2 = gtk.Label()
label2.set_markup_with_mnemonic(_("<b>_Year:</b>"))
placeHolder1 = gtk.Label()
# gtk.Adjustment(value=0, lower=0, upper=0, step_incr=0, page_incr=0, page_size=0)
adj = gtk.Adjustment(self.currentYear, MINDATE, MAXDATE, 1)
self.yearSpinner = gtk.SpinButton(adj, 0, 0)
self.yearSpinner.set_numeric(True)
self.yearSpinner.set_update_policy(gtk.UPDATE_IF_VALID)
self.yearSpinner.set_snap_to_ticks(True)
self.yearSpinner.connect("changed", self._on_yearSpinner_changed)
placeHolder2 = gtk.Label()
self.pack_start(label1, expand=False, fill=False, padding=4)
self.pack_start(self.monthSelector, expand=False, fill=False, padding=4)
self.pack_start(placeHolder1, expand=True, fill=True, padding=0)
self.pack_start(placeHolder2, expand=True, fill=True, padding=0)
self.pack_start(label2, expand=False, fill=False, padding=4)
self.pack_start(self.yearSpinner, expand=False, fill=False, padding=4)
def initialize_values(self):
self.monthSelector.set_active(self.currentMonth - 1)
self.yearSpinner.set_value(self.currentYear)
def populate_month_selector(self):
store = gtk.ListStore(gobject.TYPE_STRING)
self.monthSelector.set_model(store)
for month in self.get_months():
store.append([month])
def _on_yearSpinner_changed(self, spin):
self.update_current_date()
def _on_monthSelector_changed(self, combo):
self.update_current_date()
def update_current_date(self):
index = self.monthSelector.get_active()
month = index + 1
year = int(self.yearSpinner.get_value())
changedDate = datetime.datetime(year, month, 1)
self.set_currentDate(changedDate)
gobject.type_register(CalendarWidget)
class BasicWindow:
# close the window and quit
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
def __init__(self):
# Create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("Basic Window")
#self.window.set_size_request(500, 200)
self.window.connect("delete_event", self.delete_event)
self.calendar = CalendarWidget()
self.calendar.connect("date_changed", self._on_calendar_date_changed)
self.window.add(self.calendar)
self.window.show_all()
def _on_calendar_date_changed(self, widget, args):
print args
def main():
gtk.main()
if __name__ == "__main__":
example = BasicWindow()
main()
This diff is collapsed.
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
from charting import Chart
class ChartWidget(gtk.EventBox):
def __init__(self):
gtk.EventBox.__init__(self)
self.chart = Chart(
max_bar_width = 40,
animate = False,
values_on_bars = True,
stretch_grid = True,
legend_width = 80)
self.add(self.chart)
def plot(self, data):
"""
Populates chart with data passed in.
"""
self.chart.plot(data)
class BasicWindow:
# close the window and quit
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
def __init__(self):
# Create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("Basic Window")
self.window.set_size_request(500, 200)
self.window.connect("delete_event", self.delete_event)
#self.activity_chart = Chart(max_bar_width = 20, collapse_whitespace = True)
self.chart = ChartWidget()
place = gtk.Frame()
place.add(self.chart)
self.window.add(place)
self.window.show_all()
data = [["Rent", 790, '#808080'], ["Gas", 120], ["Food", 280],
["Education", 60], ["Utilities", 140, '#1a3def'], ["Insurance", 0], ["Travel", 0]]
self.chart.plot(data)
def main():
gtk.main()
if __name__ == "__main__":
example = BasicWindow()
main()
......@@ -94,9 +94,9 @@ class Actions(object):
self.edit_bill(bill)
return self.dal.delete(CategoriesTable, key)
"""
if not '--standalone' in sys.argv \
and not sys.argv[0].endswith('billreminderd') \
and verify_dbus_service(common.DBUS_INTERFACE):
from lib.dbus_actions import Actions
"""
......@@ -47,6 +47,27 @@ class Actions(object):
record['caId'] = int(record['caId'])
return record
def get_monthly_totals(self, status, month, year):
# Return a list of categories and totals for the given month
# Delimeters for our search
firstOfMonth = scheduler.first_of_month(month, year)
lastOfMonth = scheduler.last_of_month(month, year)
# Determine status criteria
status = status < 2 and ' = %s' % status or ' in (0,1)'
stmt = 'select categoryName, sum(amountDue) as amount, color' \
' from br_billstable, br_categoriestable where' \
' paid %s' \
' and dueDate >= ? and dueDate <= ?' \
' and br_categoriestable.Id = br_billstable.catId' \
' GROUP BY catId, color' \
' ORDER BY dueDate ASC' % status
params = [firstOfMonth, lastOfMonth]
records = self.executeSql(stmt, params)
return records
def get_monthly_bills(self, status, month, year):
# Delimeters for our search
firstOfMonth = scheduler.first_of_month(month, year)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment