Fix tag colors on PedigreeView (#915)

Fixes #11363

* Handle long and short hex format black color

* Fix hex_to_rgb_float utility function
This commit is contained in:
romjerome 2019-10-17 01:57:36 +02:00 committed by Sam Manzi
parent c54f381737
commit 75b0b66269
2 changed files with 8 additions and 7 deletions

View File

@ -551,16 +551,17 @@ def color_graph_box(alive=False, gender=Person.MALE):
def hex_to_rgb_float(value):
"""
Convert a hexademical value #FF00FF to rgb. Returns tuple of float between
0 and 1
Convert a 6 or 12 digit hexademical value to rgb. Returns tuple of floats
between 0 and 1.
"""
value = value.lstrip('#')
lenv = len(value)
return tuple(int(value[i:i+lenv//3], 16)/256.0 for i in range(0, lenv, lenv//3))
return tuple(int(value[i:i+lenv//3], 16)/16.0**(lenv//3)
for i in range(0, lenv, lenv//3))
def hex_to_rgb(value):
"""
Convert a hexadecimal value #FF00FF to rgb. Returns tuple of integers
Convert a 6 or 12 digit hexadecimal value to rgb. Returns tuple of integers.
"""
value = value.lstrip('#')
lenv = len(value)

View File

@ -196,10 +196,10 @@ class PersonBoxWidgetCairo(_PersonWidgetBase):
if tags and person:
for tag_handle in person.get_tag_list():
# For the complete tag, don't modify the default color
# which is black (#000000000000)
# which is black
tag = dbstate.db.get_tag_from_handle(tag_handle)
if tag.get_color() != "#000000000000": # only if the color
self.bgcolor = tag.get_color() # is not black
if tag.get_color() not in ("#000000", "#000000000000"):
self.bgcolor = tag.get_color()
self.bgcolor = hex_to_rgb_float(self.bgcolor)
self.bordercolor = hex_to_rgb_float(self.bordercolor)