Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/PortfolioActivity.py
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2011-05-11 16:21:38 (GMT)
committer Walter Bender <walter.bender@gmail.com>2011-05-11 16:21:38 (GMT)
commite8fd8630876f1bfa80f6ab64df7e9e99dfc14353 (patch)
treee339c88888c1425e78f640a8abd38e8ad6bad174 /PortfolioActivity.py
parentee51948049e3aa762fe25d00d5cee5fa73bc8ceb (diff)
use lighter of the two XO colors as the background for the text
Diffstat (limited to 'PortfolioActivity.py')
-rw-r--r--PortfolioActivity.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/PortfolioActivity.py b/PortfolioActivity.py
index c4945eb..3687fad 100644
--- a/PortfolioActivity.py
+++ b/PortfolioActivity.py
@@ -67,6 +67,19 @@ SHORTH = 100
SHORTX = 50
SHORTY = 700
+
+def _luminance(color):
+ ''' Calculate luminance value '''
+ return int(color[0:2], 16) * 0.3 + int(color[2:4], 16) * 0.6 + int(color[4:6]) * 0.1
+
+
+def _lighter_color(colors):
+ ''' Which color is lighter? Use that one for the text background '''
+ if _luminance(colors[0][1:6]) > _luminance(colors[1][1:6]):
+ return 0
+ return 1
+
+
def _svg_str_to_pixbuf(svg_string):
''' Load pixbuf from SVG string '''
pl = gtk.gdk.PixbufLoader('svg')
@@ -172,6 +185,12 @@ class PortfolioActivity(activity.Activity):
''' Prepare to render the datastore entries. '''
self._colors = profile.get_color().to_string().split(',')
+ # Use the lighter color for the text background
+ if _lighter_color(self._colors) == 0:
+ tmp = self._colors[0]
+ self._colors[0] = self._colors[1]
+ self._colors[1] = tmp
+
self._width = gtk.gdk.screen_width()
self._height = gtk.gdk.screen_height()
self._scale = gtk.gdk.screen_height() / 900.