diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2014-07-04 14:13:48 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2014-07-04 14:42:22 (GMT) |
commit | c342dc0522e0e9cf8408eb646b4911efbf6b2616 (patch) | |
tree | e888156ffe2ba1c1b55dec4b7bd043c41cfeedbb | |
parent | 96cdc76aef688a37b208805d9836ff869d5d55a9 (diff) |
Move color constnts and methods to a new package
Defined constants for credit and debit colors,
and changed credit color fromo blue to green.
-rw-r--r-- | budgetscreen.py | 5 | ||||
-rw-r--r-- | chartscreen.py | 6 | ||||
-rw-r--r-- | colors.py | 43 | ||||
-rw-r--r-- | finance.py | 59 | ||||
-rw-r--r-- | registerscreen.py | 8 |
5 files changed, 61 insertions, 60 deletions
diff --git a/budgetscreen.py b/budgetscreen.py index d1863a7..baaec00 100644 --- a/budgetscreen.py +++ b/budgetscreen.py @@ -27,8 +27,7 @@ from gi.repository import GObject # Set up localization. locale.setlocale(locale.LC_ALL, '') -# Import activity module -import finance +import colors BUDGET_HELP = _( 'The Budget view allows you to set a monthly budget for each expense ' @@ -106,7 +105,7 @@ class BudgetScreen(Gtk.VBox): catbox = Gtk.Label(label=description) catbox.set_padding(10, 0) - color = finance.get_category_color_str(c) + color = colors.get_category_color_str(c) ebox = Gtk.EventBox() parse, color = Gdk.Color.parse(color) diff --git a/chartscreen.py b/chartscreen.py index a6fc9a5..a20e702 100644 --- a/chartscreen.py +++ b/chartscreen.py @@ -19,7 +19,7 @@ import math import locale # Import activity module -import finance +import colors from gettext import gettext as _ @@ -102,7 +102,7 @@ class ChartScreen(Gtk.HBox): catlabel = Gtk.Label(label=description) catgroup.add_widget(catlabel) - color = finance.get_category_color_str(c) + color = colors.get_category_color_str(c) amountlabel = Gtk.Label() amountlabel.set_markup(locale.currency(self.category_total[c])) @@ -138,7 +138,7 @@ class ChartScreen(Gtk.HBox): for c in self.sorted_categories: slice = 2 * math.pi * self.category_total[c] / total - color = finance.get_category_color(c) + color = colors.get_category_color(c) context.move_to(x, y) context.arc(x, y, r, angle, angle + slice) diff --git a/colors.py b/colors.py new file mode 100644 index 0000000..af75e1a --- /dev/null +++ b/colors.py @@ -0,0 +1,43 @@ +CREDIT_COLOR = '#009900' + +DEBIT_COLOR = '#ff4040' + +CATEGORY_COLORS = [ + (1.0, 1.0, 1.0), + (1.0, 1.0, 0.6), + (1.0, 1.0, 0.8), + (1.0, 0.6, 1.0), + (1.0, 0.6, 0.6), + (1.0, 0.6, 0.8), + (1.0, 0.8, 1.0), + (1.0, 0.8, 0.6), + (1.0, 0.8, 0.8), + (0.6, 1.0, 1.0), + (0.6, 1.0, 0.6), + (0.6, 1.0, 0.8), + (0.6, 0.6, 1.0), + (0.6, 0.6, 0.6), + (0.6, 0.6, 0.8), + (0.6, 0.8, 1.0), + (0.6, 0.8, 0.6), + (0.6, 0.8, 0.8), + (0.8, 1.0, 1.0), + (0.8, 1.0, 0.6), + (0.8, 1.0, 0.8), + (0.8, 0.6, 1.0), + (0.8, 0.6, 0.6), + (0.8, 0.6, 0.8), + (0.8, 0.8, 1.0), + (0.8, 0.8, 0.6), + (0.8, 0.8, 0.8), +] + + +def get_category_color(catname): + return CATEGORY_COLORS[catname.__hash__() % len(CATEGORY_COLORS)] + + +def get_category_color_str(catname): + color = get_category_color(catname) + return "#%02x%02x%02x" % \ + (int(color[0] * 255), int(color[1] * 255), int(color[2] * 255)) @@ -21,13 +21,6 @@ import logging import datetime import locale - -# Import screen classes. -import registerscreen -import chartscreen -import budgetscreen -from helpbutton import HelpButton - from gettext import gettext as _ import json @@ -45,6 +38,13 @@ from sugar3.activity.widgets import StopButton from sugar3.activity.widgets import ActivityToolbarButton from sugar3.activity.activity import Activity +# Import screen classes. +import registerscreen +import chartscreen +import budgetscreen +from helpbutton import HelpButton +import colors + # Set up localization. locale.setlocale(locale.LC_ALL, '') @@ -54,47 +54,6 @@ log.setLevel(logging.DEBUG) logging.basicConfig() -CATEGORY_COLORS = [ - (1.0, 1.0, 1.0), - (1.0, 1.0, 0.6), - (1.0, 1.0, 0.8), - (1.0, 0.6, 1.0), - (1.0, 0.6, 0.6), - (1.0, 0.6, 0.8), - (1.0, 0.8, 1.0), - (1.0, 0.8, 0.6), - (1.0, 0.8, 0.8), - (0.6, 1.0, 1.0), - (0.6, 1.0, 0.6), - (0.6, 1.0, 0.8), - (0.6, 0.6, 1.0), - (0.6, 0.6, 0.6), - (0.6, 0.6, 0.8), - (0.6, 0.8, 1.0), - (0.6, 0.8, 0.6), - (0.6, 0.8, 0.8), - (0.8, 1.0, 1.0), - (0.8, 1.0, 0.6), - (0.8, 1.0, 0.8), - (0.8, 0.6, 1.0), - (0.8, 0.6, 0.6), - (0.8, 0.6, 0.8), - (0.8, 0.8, 1.0), - (0.8, 0.8, 0.6), - (0.8, 0.8, 0.8), -] - - -def get_category_color(catname): - return CATEGORY_COLORS[catname.__hash__() % len(CATEGORY_COLORS)] - - -def get_category_color_str(catname): - color = get_category_color(catname) - return "#%02x%02x%02x" % \ - (int(color[0] * 255), int(color[1] * 255), int(color[2] * 255)) - - # This is the main Finance activity class. # # It owns the main application window, and all the various toolbars @@ -418,9 +377,9 @@ class Finance(Activity): # Update Balance. if total >= 0.0: - balancecolor = '#4040ff' + balancecolor = colors.CREDIT_COLOR else: - balancecolor = '#ff4040' + balancecolor = colors.DEBIT_COLOR balance = "<span size='xx-large' foreground='%s'><b>" % balancecolor balance += _('Balance: ') + locale.currency(total) balance += "</b></span>" diff --git a/registerscreen.py b/registerscreen.py index 7db19af..a11d19b 100644 --- a/registerscreen.py +++ b/registerscreen.py @@ -30,7 +30,7 @@ from sugar3.graphics import style locale.setlocale(locale.LC_ALL, '') # Import activity module -import finance +import colors REGISTER_HELP = _( 'Welcome to Finance! This activity keeps track of income ' @@ -147,11 +147,11 @@ class RegisterScreen(Gtk.VBox): t = self.activity.transaction_map[id] cell_renderer.set_property('xalign', 1.0) if t['type'] == 'credit': - cell_renderer.set_property('foreground', '#4040ff') + cell_renderer.set_property('foreground', colors.CREDIT_COLOR) cell_renderer.set_property('text', locale.currency(t['amount'], False)) else: - cell_renderer.set_property('foreground', '#ff4040') + cell_renderer.set_property('foreground', colors.DEBIT_COLOR) cell_renderer.set_property('text', locale.currency(-t['amount'], False)) @@ -183,7 +183,7 @@ class RegisterScreen(Gtk.VBox): cell_renderer.set_property('text', category) if category: cell_renderer.set_property( - 'background', finance.get_category_color_str(category)) + 'background', colors.get_category_color_str(category)) else: cell_renderer.set_property('background', None) |