[hamster-applet] Used a dictionary instead of four constants to represent the different overview range options (matte
- From: Mjumbe Wawatu Ukweli <mjumbewu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hamster-applet] Used a dictionary instead of four constants to represent the different overview range options (matte
- Date: Sun, 23 May 2010 20:17:56 +0000 (UTC)
commit a7ba0ed029fae128bc7894dd3dd5401afe96dbcd
Author: Mjumbe Wawatu Ukweli <mjumbewu gmail com>
Date: Sun May 23 16:17:41 2010 -0400
Used a dictionary instead of four constants to represent the different overview range options (matter of taste).
src/hamster/overview.py | 48 ++++++++++++++++++++++++++--------------------
1 files changed, 27 insertions(+), 21 deletions(-)
---
diff --git a/src/hamster/overview.py b/src/hamster/overview.py
index eca05e5..3e69736 100644
--- a/src/hamster/overview.py
+++ b/src/hamster/overview.py
@@ -76,17 +76,23 @@ class Overview(object):
self.get_widget("reports_tab").add(self.reports)
self.range_combo = gtk.combo_box_new_text()
- def add_range_option(label):
- """Insert a new item in the range combo and return its index"""
+ self.ranges = {}
+
+ def add_range_option(key, label):
+ """
+ Insert a new item in the range combo and map its index into the
+ ranges dictionary.
+ """
self.range_combo.append_text(label)
- return self.range_combo.get_model().iter_n_children(None)-1
+ index = self.range_combo.get_model().iter_n_children(None)-1
+ self.ranges[key] = index
- self.SHOW_DAY = add_range_option(_("Day"))
- self.SHOW_WEEK = add_range_option(_("Week"))
- self.SHOW_MONTH = add_range_option(_("Month"))
- self.SHOW_DATE_RANGE = add_range_option(_("Date Range"))
+ add_range_option("day", _("Day"))
+ add_range_option("week", _("Week"))
+ add_range_option("month", _("Month"))
+ add_range_option("custom", _("Date Range"))
- self.range_combo.set_active(self.SHOW_WEEK)
+ self.range_combo.set_active(self.ranges["week"])
self.range_combo.connect("changed", self.on_range_combo_changed)
@@ -251,21 +257,21 @@ class Overview(object):
self.get_widget("preset_range").hide()
self.get_widget("range_box").hide()
- if idx == self.SHOW_DATE_RANGE:
+ if idx == self.ranges["custom"]:
self.get_widget("range_box").show()
else:
- if idx == self.SHOW_DAY:
+ if idx == self.ranges["day"]:
self.start_date = self.view_date
self.end_date = self.start_date + dt.timedelta(0)
self.get_widget("preset_range").show()
- elif idx == self.SHOW_WEEK:
+ elif idx == self.ranges["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 == self.SHOW_MONTH:
+ elif idx == self.ranges["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)
@@ -292,13 +298,13 @@ class Overview(object):
return self.range_combo.get_active()
def on_prev_clicked(self, button):
- if self._chosen_range() == self.SHOW_DAY:
+ if self._chosen_range() == self.ranges["day"]:
self.start_date -= dt.timedelta(1)
self.end_date -= dt.timedelta(1)
- elif self._chosen_range() == self.SHOW_WEEK:
+ elif self._chosen_range() == self.ranges["week"]:
self.start_date -= dt.timedelta(7)
self.end_date -= dt.timedelta(7)
- elif self._chosen_range() == self.SHOW_MONTH:
+ elif self._chosen_range() == self.ranges["month"]:
self.end_date = self.start_date - dt.timedelta(1)
first_weekday, days_in_month = calendar.monthrange(self.end_date.year, self.end_date.month)
self.start_date = self.end_date - dt.timedelta(days_in_month - 1)
@@ -307,13 +313,13 @@ class Overview(object):
self.search()
def on_next_clicked(self, button):
- if self._chosen_range() == self.SHOW_DAY:
+ if self._chosen_range() == self.ranges["day"]:
self.start_date += dt.timedelta(1)
self.end_date += dt.timedelta(1)
- elif self._chosen_range() == self.SHOW_WEEK:
+ elif self._chosen_range() == self.ranges["week"]:
self.start_date += dt.timedelta(7)
self.end_date += dt.timedelta(7)
- elif self._chosen_range() == self.SHOW_MONTH:
+ elif self._chosen_range() == self.ranges["month"]:
self.start_date = self.end_date + dt.timedelta(1)
first_weekday, days_in_month = calendar.monthrange(self.start_date.year, self.start_date.month)
self.end_date = self.start_date + dt.timedelta(days_in_month - 1)
@@ -325,16 +331,16 @@ class Overview(object):
def on_home_clicked(self, button):
self.view_date = (dt.datetime.today() - dt.timedelta(hours = self.day_start.hour,
minutes = self.day_start.minute)).date()
- if self._chosen_range() == self.SHOW_DAY:
+ if self._chosen_range() == self.ranges["day"]:
self.start_date = self.view_date
self.end_date = self.start_date + dt.timedelta(0)
- elif self._chosen_range() == self.SHOW_WEEK:
+ elif self._chosen_range() == self.ranges["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)
- elif self._chosen_range() == self.SHOW_MONTH:
+ elif self._chosen_range() == self.ranges["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)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]