Fanchart Feature, allow gradient. Must be changed to HSV values, and white text if needed

svn: r20329
This commit is contained in:
Benny Malengier 2012-09-04 20:10:42 +00:00
parent d95af110e8
commit 4379726f75
2 changed files with 99 additions and 33 deletions

View File

@ -92,6 +92,7 @@ class FanChartWidget(Gtk.DrawingArea):
BACKGROUND_SCHEME2 = 1 BACKGROUND_SCHEME2 = 1
BACKGROUND_GENDER = 2 BACKGROUND_GENDER = 2
BACKGROUND_WHITE = 3 BACKGROUND_WHITE = 3
BACKGROUND_GRAD_GEN = 4
GENCOLOR = { GENCOLOR = {
BACKGROUND_SCHEME1: ((255, 63, 0), BACKGROUND_SCHEME1: ((255, 63, 0),
(255,175, 15), (255,175, 15),
@ -169,10 +170,12 @@ class FanChartWidget(Gtk.DrawingArea):
self.center_xy = [0, 0] # distance from center (x, y) self.center_xy = [0, 0] # distance from center (x, y)
self.center = 50 # pixel radius of center self.center = 50 # pixel radius of center
#default values #default values
self.reset(9, self.BACKGROUND_SCHEME1, True, True, 'Sans') self.reset(9, self.BACKGROUND_SCHEME1, True, True, 'Sans', '#0000FF',
'#FF0000')
self.set_size_request(120, 120) self.set_size_request(120, 120)
def reset(self, maxgen, background, childring, radialtext, fontdescr): def reset(self, maxgen, background, childring, radialtext, fontdescr,
grad_start, grad_end):
""" """
Reset all of the data on where/how slices appear, and if they are expanded. Reset all of the data on where/how slices appear, and if they are expanded.
""" """
@ -180,11 +183,12 @@ class FanChartWidget(Gtk.DrawingArea):
self.childring = childring self.childring = childring
self.background = background self.background = background
self.fontdescr = fontdescr self.fontdescr = fontdescr
if self.background == self.BACKGROUND_GENDER: self.grad_start = grad_start
self.colors = None self.grad_end = grad_end
else:
self.colors = self.GENCOLOR[self.background]
self.set_generations(maxgen) self.set_generations(maxgen)
# prepare the colors for the boxes
self.prepare_background_box()
def set_generations(self, generations): def set_generations(self, generations):
""" """
@ -310,6 +314,49 @@ class FanChartWidget(Gtk.DrawingArea):
if child and self.childring: if child and self.childring:
self.drawchildring(cr) self.drawchildring(cr)
def prepare_background_box(self):
"""
Method that is called every reset of the chart, to precomputed values
needed for the background of the boxes
"""
maxgen = self.generations
if self.background == self.BACKGROUND_GENDER:
# nothing to precompute
self.colors = None
elif self.background == self.BACKGROUND_GRAD_GEN:
#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]),
) for x in divs]
else:
# known colors per generation, set or compute them
self.colors = self.GENCOLOR[self.background]
def background_box(self, person, gender, generation):
"""
determine red, green, blue value of background of the box of person,
which has gender gender, and is in ring generation
"""
if self.background == self.BACKGROUND_GENDER:
try:
alive = probably_alive(person, self.dbstate.db)
except RuntimeError:
alive = False
backgr, border = gui.utils.color_graph_box(alive, person.gender)
r, g, b = gui.utils.hex_to_rgb(backgr)
else:
r, g, b = self.colors[generation % len(self.colors)]
if gender == gen.lib.Person.MALE:
r *= .9
g *= .9
b *= .9
return r, g, b
def draw_person(self, cr, gender, name, start, stop, generation, def draw_person(self, cr, gender, name, start, stop, generation,
state, parents, child, person): state, parents, child, person):
""" """
@ -320,19 +367,7 @@ class FanChartWidget(Gtk.DrawingArea):
cr.save() cr.save()
start_rad = start * math.pi/180 start_rad = start * math.pi/180
stop_rad = stop * math.pi/180 stop_rad = stop * math.pi/180
if self.background == self.BACKGROUND_GENDER: r, g, b = self.background_box(person, gender, generation)
try:
alive = probably_alive(person, self.dbstate.db)
except RuntimeError:
alive = False
backgr, border = gui.utils.color_graph_box(alive, person.gender)
r, g, b = gui.utils.hex_to_rgb(backgr)
else:
r,g,b = self.colors[generation % len(self.colors)]
if gender == gen.lib.Person.MALE:
r *= .9
g *= .9
b *= .9
radius = generation * self.PIXELS_PER_GENERATION + self.center radius = generation * self.PIXELS_PER_GENERATION + self.center
# If max generation, and they have parents: # If max generation, and they have parents:
if generation == self.generations - 1 and parents: if generation == self.generations - 1 and parents:
@ -876,6 +911,8 @@ class FanChartGrampsGUI(object):
self.childring = childring self.childring = childring
self.radialtext = radialtext self.radialtext = radialtext
self.fonttype = font self.fonttype = font
self.grad_start = '#0000FF'
self.grad_end = '#FF0000'
def have_parents(self, person): def have_parents(self, person):
"""on_childmenu_changed """on_childmenu_changed
@ -930,7 +967,8 @@ class FanChartGrampsGUI(object):
data. data.
""" """
self.fan.reset(self.maxgen, self.background, self.childring, self.fan.reset(self.maxgen, self.background, self.childring,
self.radialtext, self.fonttype) self.radialtext, self.fonttype,
self.grad_start, self.grad_end)
person = self.dbstate.db.get_person_from_handle(self.get_active('Person')) person = self.dbstate.db.get_person_from_handle(self.get_active('Person'))
if not person: if not person:
name = None name = None

View File

@ -64,6 +64,8 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
('interface.fanview-childrenring', True), ('interface.fanview-childrenring', True),
('interface.fanview-radialtext', True), ('interface.fanview-radialtext', True),
('interface.fanview-font', 'Sans'), ('interface.fanview-font', 'Sans'),
('interface.color-start-grad', '#0000FF'),
('interface.color-end-grad', '#FF0000'),
) )
def __init__(self, pdata, dbstate, uistate, nav_group=0): def __init__(self, pdata, dbstate, uistate, nav_group=0):
self.dbstate = dbstate self.dbstate = dbstate
@ -80,6 +82,9 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
self._config.get('interface.fanview-radialtext'), self._config.get('interface.fanview-radialtext'),
self._config.get('interface.fanview-font'), self._config.get('interface.fanview-font'),
self.on_childmenu_changed) self.on_childmenu_changed)
self.grad_start = self._config.get('interface.color-start-grad')
self.grad_end = self._config.get('interface.color-end-grad')
dbstate.connect('active-changed', self.active_changed) dbstate.connect('active-changed', self.active_changed)
dbstate.connect('database-changed', self.change_db) dbstate.connect('database-changed', self.change_db)
@ -245,7 +250,8 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
""" """
Function that builds the widget in the configuration dialog Function that builds the widget in the configuration dialog
""" """
table = Gtk.Table(4, 2) nrentry = 7
table = Gtk.Table(6, 3)
table.set_border_width(12) table.set_border_width(12)
table.set_col_spacings(6) table.set_col_spacings(6)
table.set_row_spacings(6) table.set_row_spacings(6)
@ -253,24 +259,34 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
configdialog.add_spinner(table, _("Max generations"), 0, configdialog.add_spinner(table, _("Max generations"), 0,
'interface.fanview-maxgen', (1, 11), 'interface.fanview-maxgen', (1, 11),
callback=self.cb_update_maxgen) callback=self.cb_update_maxgen)
configdialog.add_checkbox(table, configdialog.add_combo(table,
_('Show children ring'), _('Text Font'),
1, 'interface.fanview-childrenring') 1, 'interface.fanview-font',
self.allfonts, callback=self.cb_update_font, valueactive=True)
configdialog.add_combo(table, configdialog.add_combo(table,
_('Background'), _('Background'),
2, 'interface.fanview-background', 2, 'interface.fanview-background',
((0, _('Color Scheme 1')), (
(1, _('Color Scheme 2')), (0, _('Color scheme 1')),
(2, _('Gender Colors')), (1, _('Color scheme 2')),
(3, _('White'))), (2, _('Gender colors')),
(3, _('White')),
(4, _('Generation based gradient')),
),
callback=self.cb_update_background) callback=self.cb_update_background)
#colors, stored as hex values
configdialog.add_color(table, _('Start gradient/Main color'), 3,
'interface.color-start-grad')
configdialog.add_color(table, _('End gradient/2nd color'), 4,
'interface.color-end-grad')
# options users should not change:
configdialog.add_checkbox(table,
_('Show children ring'),
nrentry-2, 'interface.fanview-childrenring')
configdialog.add_checkbox(table, configdialog.add_checkbox(table,
_('Allow radial text at generation 6'), _('Allow radial text at generation 6'),
3, 'interface.fanview-radialtext') nrentry-1, 'interface.fanview-radialtext')
configdialog.add_combo(table,
_('Text Font'),
4, 'interface.fanview-font',
self.allfonts, callback=self.cb_update_font, valueactive=True)
return _('Layout'), table return _('Layout'), table
@ -284,6 +300,10 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
self.cb_update_childrenring) self.cb_update_childrenring)
self._config.connect('interface.fanview-radialtext', self._config.connect('interface.fanview-radialtext',
self.cb_update_radialtext) self.cb_update_radialtext)
self._config.connect('interface.color-start-grad',
self.cb_update_color)
self._config.connect('interface.color-end-grad',
self.cb_update_color)
def cb_update_maxgen(self, spinbtn, constant): def cb_update_maxgen(self, spinbtn, constant):
self.maxgen = spinbtn.get_value_as_int() self.maxgen = spinbtn.get_value_as_int()
@ -316,6 +336,14 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
self.radialtext = False self.radialtext = False
self.update() self.update()
def cb_update_color(self, client, cnxn_id, entry, data):
"""
Called when the configuration menu changes the childrenring setting.
"""
self.grad_start = self._config.get('interface.color-start-grad')
self.grad_end = self._config.get('interface.color-end-grad')
self.update()
def cb_update_font(self, obj, constant): def cb_update_font(self, obj, constant):
entry = obj.get_active() entry = obj.get_active()
self._config.set(constant, self.allfonts[entry][1]) self._config.set(constant, self.allfonts[entry][1])