Fanchart Feature, allow gradient. Must be changed to HSV values, and white text if needed
svn: r20329
This commit is contained in:
parent
d95af110e8
commit
4379726f75
@ -92,6 +92,7 @@ class FanChartWidget(Gtk.DrawingArea):
|
||||
BACKGROUND_SCHEME2 = 1
|
||||
BACKGROUND_GENDER = 2
|
||||
BACKGROUND_WHITE = 3
|
||||
BACKGROUND_GRAD_GEN = 4
|
||||
GENCOLOR = {
|
||||
BACKGROUND_SCHEME1: ((255, 63, 0),
|
||||
(255,175, 15),
|
||||
@ -169,10 +170,12 @@ class FanChartWidget(Gtk.DrawingArea):
|
||||
self.center_xy = [0, 0] # distance from center (x, y)
|
||||
self.center = 50 # pixel radius of center
|
||||
#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)
|
||||
|
||||
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.
|
||||
"""
|
||||
@ -180,11 +183,12 @@ class FanChartWidget(Gtk.DrawingArea):
|
||||
self.childring = childring
|
||||
self.background = background
|
||||
self.fontdescr = fontdescr
|
||||
if self.background == self.BACKGROUND_GENDER:
|
||||
self.colors = None
|
||||
else:
|
||||
self.colors = self.GENCOLOR[self.background]
|
||||
self.grad_start = grad_start
|
||||
self.grad_end = grad_end
|
||||
|
||||
self.set_generations(maxgen)
|
||||
# prepare the colors for the boxes
|
||||
self.prepare_background_box()
|
||||
|
||||
def set_generations(self, generations):
|
||||
"""
|
||||
@ -310,6 +314,49 @@ class FanChartWidget(Gtk.DrawingArea):
|
||||
if child and self.childring:
|
||||
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,
|
||||
state, parents, child, person):
|
||||
"""
|
||||
@ -320,19 +367,7 @@ class FanChartWidget(Gtk.DrawingArea):
|
||||
cr.save()
|
||||
start_rad = start * math.pi/180
|
||||
stop_rad = stop * math.pi/180
|
||||
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
|
||||
r, g, b = self.background_box(person, gender, generation)
|
||||
radius = generation * self.PIXELS_PER_GENERATION + self.center
|
||||
# If max generation, and they have parents:
|
||||
if generation == self.generations - 1 and parents:
|
||||
@ -876,6 +911,8 @@ class FanChartGrampsGUI(object):
|
||||
self.childring = childring
|
||||
self.radialtext = radialtext
|
||||
self.fonttype = font
|
||||
self.grad_start = '#0000FF'
|
||||
self.grad_end = '#FF0000'
|
||||
|
||||
def have_parents(self, person):
|
||||
"""on_childmenu_changed
|
||||
@ -930,7 +967,8 @@ class FanChartGrampsGUI(object):
|
||||
data.
|
||||
"""
|
||||
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'))
|
||||
if not person:
|
||||
name = None
|
||||
|
@ -64,6 +64,8 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
|
||||
('interface.fanview-childrenring', True),
|
||||
('interface.fanview-radialtext', True),
|
||||
('interface.fanview-font', 'Sans'),
|
||||
('interface.color-start-grad', '#0000FF'),
|
||||
('interface.color-end-grad', '#FF0000'),
|
||||
)
|
||||
def __init__(self, pdata, dbstate, uistate, nav_group=0):
|
||||
self.dbstate = dbstate
|
||||
@ -80,6 +82,9 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
|
||||
self._config.get('interface.fanview-radialtext'),
|
||||
self._config.get('interface.fanview-font'),
|
||||
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('database-changed', self.change_db)
|
||||
@ -245,7 +250,8 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
|
||||
"""
|
||||
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_col_spacings(6)
|
||||
table.set_row_spacings(6)
|
||||
@ -253,24 +259,34 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
|
||||
configdialog.add_spinner(table, _("Max generations"), 0,
|
||||
'interface.fanview-maxgen', (1, 11),
|
||||
callback=self.cb_update_maxgen)
|
||||
configdialog.add_checkbox(table,
|
||||
_('Show children ring'),
|
||||
1, 'interface.fanview-childrenring')
|
||||
configdialog.add_combo(table,
|
||||
_('Text Font'),
|
||||
1, 'interface.fanview-font',
|
||||
self.allfonts, callback=self.cb_update_font, valueactive=True)
|
||||
configdialog.add_combo(table,
|
||||
_('Background'),
|
||||
2, 'interface.fanview-background',
|
||||
((0, _('Color Scheme 1')),
|
||||
(1, _('Color Scheme 2')),
|
||||
(2, _('Gender Colors')),
|
||||
(3, _('White'))),
|
||||
(
|
||||
(0, _('Color scheme 1')),
|
||||
(1, _('Color scheme 2')),
|
||||
(2, _('Gender colors')),
|
||||
(3, _('White')),
|
||||
(4, _('Generation based gradient')),
|
||||
),
|
||||
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,
|
||||
_('Allow radial text at generation 6'),
|
||||
3, 'interface.fanview-radialtext')
|
||||
configdialog.add_combo(table,
|
||||
_('Text Font'),
|
||||
4, 'interface.fanview-font',
|
||||
self.allfonts, callback=self.cb_update_font, valueactive=True)
|
||||
nrentry-1, 'interface.fanview-radialtext')
|
||||
|
||||
return _('Layout'), table
|
||||
|
||||
@ -284,6 +300,10 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
|
||||
self.cb_update_childrenring)
|
||||
self._config.connect('interface.fanview-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):
|
||||
self.maxgen = spinbtn.get_value_as_int()
|
||||
@ -316,6 +336,14 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
|
||||
self.radialtext = False
|
||||
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):
|
||||
entry = obj.get_active()
|
||||
self._config.set(constant, self.allfonts[entry][1])
|
||||
|
Loading…
Reference in New Issue
Block a user