From 781cdcb6f4b001a14168101c29d1b476e119b0ae Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Tue, 4 Sep 2012 20:44:24 +0000 Subject: [PATCH] Fanchart: nice gradient when used based on hsv svn: r20330 --- src/gui/widgets/fanchart.py | 16 ++++++++++++---- src/plugins/view/fanchartview.py | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gui/widgets/fanchart.py b/src/gui/widgets/fanchart.py index 71617bacf..9d0d05cc6 100644 --- a/src/gui/widgets/fanchart.py +++ b/src/gui/widgets/fanchart.py @@ -43,6 +43,7 @@ from gi.repository import Gdk from gi.repository import Gtk from gi.repository import PangoCairo import math +import colorsys import cPickle as pickle from cgi import escape @@ -328,11 +329,18 @@ class FanChartWidget(Gtk.DrawingArea): #compute the colors, -1, 0, ..., maxgen cstart = gui.utils.hex_to_rgb(self.grad_start) cend = gui.utils.hex_to_rgb(self.grad_end) - divs = [x/(maxgen+1) for x in range(maxgen+2)] - self.colors = [(int((1-x) * cstart[0] + x * cend[0]), - int((1-x) * cstart[1] + x * cend[1]), - int((1-x) * cstart[2] + x * cend[2]), + cstart_hsv = colorsys.rgb_to_hsv(cstart[0]/255, cstart[1]/255, + cstart[2]/255) + cend_hsv = colorsys.rgb_to_hsv(cend[0]/255, cend[1]/255, + cend[2]/255) + divs = [x/(maxgen-1) for x in range(maxgen)] + rgb_colors = [colorsys.hsv_to_rgb( + (1-x) * cstart_hsv[0] + x * cend_hsv[0], + (1-x) * cstart_hsv[1] + x * cend_hsv[1], + (1-x) * cstart_hsv[2] + x * cend_hsv[2], ) for x in divs] + self.colors = [(int(255*r), int(255*g), int(255*b)) + for r, g, b in rgb_colors] else: # known colors per generation, set or compute them self.colors = self.GENCOLOR[self.background] diff --git a/src/plugins/view/fanchartview.py b/src/plugins/view/fanchartview.py index d4da995e3..cdee4a236 100644 --- a/src/plugins/view/fanchartview.py +++ b/src/plugins/view/fanchartview.py @@ -276,9 +276,9 @@ class FanChartView(FanChartGrampsGUI, NavigationView): callback=self.cb_update_background) #colors, stored as hex values configdialog.add_color(table, _('Start gradient/Main color'), 3, - 'interface.color-start-grad') + 'interface.color-start-grad', col=1) configdialog.add_color(table, _('End gradient/2nd color'), 4, - 'interface.color-end-grad') + 'interface.color-end-grad', col=1) # options users should not change: configdialog.add_checkbox(table,