[meld] tree: Fix colour handling for rows in folder and VC comparisons



commit 7e2b926f7a56f9d89710b9bb0b50e1a248adf279
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Dec 8 07:46:33 2013 +1000

    tree: Fix colour handling for rows in folder and VC comparisons
    
    Gdk.Color and Gdk.RGBA values in TreeStores seem to get corrupted
    whenever they're inserted, so we get to fall back to using strings
    for now.

 meld/dirdiff.py               |    2 +-
 meld/tree.py                  |   20 ++++++++++++--------
 meld/ui/emblemcellrenderer.py |    5 +++--
 meld/vcview.py                |    2 +-
 4 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index ce92b82..ec1f5fa 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -369,7 +369,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
             column.pack_start(renicon, False)
             column.pack_start(rentext, True)
             column.set_attributes(rentext, markup=col_index(tree.COL_TEXT, i),
-                                  foreground_gdk=col_index(tree.COL_FG, i),
+                                  foreground=col_index(tree.COL_FG, i),
                                   style=col_index(tree.COL_STYLE, i),
                                   weight=col_index(tree.COL_WEIGHT, i),
                                   strikethrough=col_index(tree.COL_STRIKE, i))
diff --git a/meld/tree.py b/meld/tree.py
index bcc7251..8ff8dde 100644
--- a/meld/tree.py
+++ b/meld/tree.py
@@ -17,14 +17,13 @@
 
 import os
 from gi.repository import GObject
-from gi.repository import Gdk
 from gi.repository import Gtk
 from gi.repository import Pango
 
 COL_PATH, COL_STATE, COL_TEXT, COL_ICON, COL_TINT, COL_FG, COL_STYLE, \
     COL_WEIGHT, COL_STRIKE, COL_END = list(range(10))
 
-COL_TYPES = (str, str, str, str, str, Gdk.Color, Pango.Style,
+COL_TYPES = (str, str, str, str, str, str, Pango.Style,
              Pango.Weight, bool)
 
 
@@ -55,10 +54,16 @@ class DiffTreeStore(Gtk.TreeStore):
         roman, italic = Pango.Style.NORMAL, Pango.Style.ITALIC
         normal, bold = Pango.Weight.NORMAL, Pango.Weight.BOLD
 
-        if style:
-            lookup = lambda color_id, default: style.lookup_color(color_id)[1]
-        else:
-            lookup = lambda color_id, default: Gdk.color_parse(default)
+        def lookup(name, default):
+            try:
+                found, colour = style.lookup_color(name)
+                if found:
+                    colour = colour.to_string()
+                else:
+                    colour = default
+            except AttributeError:
+                colour = default
+            return colour
 
         unk_fg = lookup("unknown-text", "#888888")
         new_fg = lookup("insert-text", "#008800")
@@ -146,8 +151,7 @@ class DiffTreeStore(Gtk.TreeStore):
         self.set_value(it, col_idx(COL_ICON,  pane), icon)
         # FIXME: This is horrible, but EmblemCellRenderer crashes
         # if you try to give it a Gdk.Color property
-        tint_str = tint.to_string() if tint else "#fff"
-        self.set_value(it, col_idx(COL_TINT,  pane), tint_str)
+        self.set_value(it, col_idx(COL_TINT,  pane), tint)
 
         fg, style, weight, strike = self.text_attributes[state]
         self.set_value(it, col_idx(COL_FG, pane), fg)
diff --git a/meld/ui/emblemcellrenderer.py b/meld/ui/emblemcellrenderer.py
index 3de2c21..cf9dffe 100644
--- a/meld/ui/emblemcellrenderer.py
+++ b/meld/ui/emblemcellrenderer.py
@@ -59,7 +59,8 @@ class EmblemCellRenderer(Gtk.CellRenderer):
         elif pspec.name == "icon-tint":
             self._icon_tint = value
             if self._icon_tint:
-                self._tint_color = Gdk.color_parse(value)
+                self._tint_color = Gdk.RGBA()
+                self._tint_color.parse(value)
             else:
                 self._tint_color = None
         else:
@@ -101,7 +102,7 @@ class EmblemCellRenderer(Gtk.CellRenderer):
 
             if self._tint_color:
                 c = self._tint_color
-                r, g, b = [x / 65535. for x in (c.red, c.green, c.blue)]
+                r, g, b = c.red, c.green, c.blue
                 # Figure out the difference between our tint colour and an
                 # empirically determined (i.e., guessed) satisfying luma and
                 # adjust the base colours accordingly
diff --git a/meld/vcview.py b/meld/vcview.py
index 48934ec..5b4be8c 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -194,7 +194,7 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
         column.pack_start(rentext, True)
         column.set_attributes(rentext,
                               text=col_index(tree.COL_TEXT, 0),
-                              foreground_gdk=col_index(tree.COL_FG, 0),
+                              foreground=col_index(tree.COL_FG, 0),
                               style=col_index(tree.COL_STYLE, 0),
                               weight=col_index(tree.COL_WEIGHT, 0),
                               strikethrough=col_index(tree.COL_STRIKE, 0))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]