Permalink
Browse files

Switch text color to white when dark background

Thanks for the patch to Antonio Roquentin
Launchpad bug: https://bugs.launchpad.net/gtg/+bug/1002083
  • Loading branch information...
1 parent 21edce3 commit d059a79ba389a5603cc230f0a78d15f6683d4409 @izidormatusov izidormatusov committed Jun 7, 2012
Showing with 18 additions and 3 deletions.
  1. +8 −3 AUTHORS
  2. +10 −0 liblarch_gtk/__init__.py
View
@@ -2,7 +2,12 @@ AUTHORS
========
Liblarch team:
-=============
+--------------
-* Lionel Dricot <ploum@ploum.net>
-* Izidor Matušov <izidor.matusov@gmail.com>
+ * Lionel Dricot <ploum@ploum.net>
+ * Izidor Matušov <izidor.matusov@gmail.com>
+
+Contributors:
+-------------
+
+ * Antonio Roquentin <https://launchpad.net/~antonio-roquentin>
@@ -321,6 +321,16 @@ def _celldatafunction(self, column, cell, model, myiter):
color = model.get_value(myiter, self.bg_color_column)
else:
color = None
+
+ def brightness(color_str):
+ c = gtk.gdk.color_parse(color_str)
+ return (0.2126*c.red + 0.7152*c.green + 0.0722*c.blue)/65535.0
+
+ if color:
+ fg_color = '#FFFFFF' if brightness(color)<0.5 else '#000000'
+ if isinstance(cell, gtk.CellRendererText):
+ cell.set_property("foreground", fg_color)
+
cell.set_property("cell-background", color)
######### DRAG-N-DROP functions #####################################

0 comments on commit d059a79

Please sign in to comment.