From e535fcefa5e508c871d33bc8dc38f88bae6ca344 Mon Sep 17 00:00:00 2001 From: SNoiraud Date: Mon, 17 Apr 2023 17:33:31 +0200 Subject: [PATCH] Tags with color names don't work in pedigree views Color tags work correctly in all views except in pedigree views. These views modify colors: ... context.set_source_rgba(*(self.bordercolor[:3] + (0.4,))) ... and context.set_source_rgb(*self.bgcolor[:3]) As it works everywhere except in these views, I think it is a bug even if we cannot enter color names in tags Fixes #012866 --- gramps/gui/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gramps/gui/utils.py b/gramps/gui/utils.py index 187814c49..75d0c8e53 100644 --- a/gramps/gui/utils.py +++ b/gramps/gui/utils.py @@ -549,11 +549,26 @@ def color_graph_box(alive=False, gender=Person.MALE): # color functions. For hsv and hls values, use import colorsys ! +def name_to_hex(value): + """ + Convert a named color to a 6 digit hexadecimal value to rgb. + """ + if value[:1] != "#": + # We have color names like "green", "orange", "yellow",... + # We need to convert them to hex format + Color = Gdk.RGBA() + Color.parse(value) + value = "#%02x%02x%02x" % (int(Color.red * 255), + int(Color.green * 255), + int(Color.blue * 255)) + return value + def hex_to_rgb_float(value): """ Convert a 6 or 12 digit hexademical value to rgb. Returns tuple of floats between 0 and 1. """ + value = name_to_hex(value) value = value.lstrip('#') lenv = len(value) return tuple(int(value[i:i+lenv//3], 16)/16.0**(lenv//3) @@ -563,6 +578,7 @@ def hex_to_rgb(value): """ Convert a 6 or 12 digit hexadecimal value to rgb. Returns tuple of integers. """ + value = name_to_hex(value) value = value.lstrip('#') lenv = len(value) return tuple(int(value[i:i+lenv//3], 16) for i in range(0, lenv, lenv//3))