Feature Fanchart: allow to set font type used in graph

svn: r20322
This commit is contained in:
Benny Malengier 2012-09-03 22:38:45 +00:00
parent 9321422b48
commit 1b09094916
4 changed files with 36 additions and 9 deletions

View File

@ -362,11 +362,13 @@ class ConfigureDialog(ManagedWindow):
return entry return entry
def add_combo(self, table, label, index, constant, opts, callback=None, def add_combo(self, table, label, index, constant, opts, callback=None,
config=None): config=None, valueactive=False):
""" """
A drop-down list allowing selection from a number of fixed options. A drop-down list allowing selection from a number of fixed options.
:param opts: A list of options. Each option is a tuple containing an :param opts: A list of options. Each option is a tuple containing an
integer code and a textual description. integer code and a textual description.
If valueactive = True, the constant stores the value, not the position
in the list
""" """
if not config: if not config:
config = self.__config config = self.__config
@ -379,8 +381,17 @@ class ConfigureDialog(ManagedWindow):
combo = Gtk.ComboBox(model=store) combo = Gtk.ComboBox(model=store)
cell = Gtk.CellRendererText() cell = Gtk.CellRendererText()
combo.pack_start(cell, True) combo.pack_start(cell, True)
combo.add_attribute(cell, 'text', 1) combo.add_attribute(cell, 'text', 1)
combo.set_active(config.get(constant)) if valueactive:
val = config.get(constant)
pos = 0
for nr, item in enumerate(opts):
if item[-1] == val:
pos = nr
break
combo.set_active(pos)
else:
combo.set_active(config.get(constant))
combo.connect('changed', callback, constant) combo.connect('changed', callback, constant)
table.attach(lwidget, 1, 2, index, index+1, yoptions=0, table.attach(lwidget, 1, 2, index, index+1, yoptions=0,
xoptions=Gtk.AttachOptions.FILL) xoptions=Gtk.AttachOptions.FILL)

View File

@ -128,7 +128,7 @@ class FanChartWidget(Gtk.DrawingArea):
self.goto = None self.goto = None
self.on_popup = callback_popup self.on_popup = callback_popup
self.last_x, self.last_y = None, None self.last_x, self.last_y = None, None
self.fontdescr = "Times New Roman" #"sans" self.fontdescr = "Sans"
self.fontsize = 8 self.fontsize = 8
self.connect("button_release_event", self.on_mouse_up) self.connect("button_release_event", self.on_mouse_up)
self.connect("motion_notify_event", self.on_mouse_move) self.connect("motion_notify_event", self.on_mouse_move)
@ -169,16 +169,17 @@ 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) self.reset(9, self.BACKGROUND_SCHEME1, True, True, 'Sans')
self.set_size_request(120, 120) self.set_size_request(120, 120)
def reset(self, maxgen, background, childring, radialtext): def reset(self, maxgen, background, childring, radialtext, fontdescr):
""" """
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.
""" """
self.radialtext = radialtext self.radialtext = radialtext
self.childring = childring self.childring = childring
self.background = background self.background = background
self.fontdescr = fontdescr
if self.background == self.BACKGROUND_GENDER: if self.background == self.BACKGROUND_GENDER:
self.colors = None self.colors = None
else: else:
@ -859,7 +860,7 @@ class FanChartWidget(Gtk.DrawingArea):
class FanChartGrampsGUI(object): class FanChartGrampsGUI(object):
""" class for functions fanchart GUI elements will need in Gramps """ class for functions fanchart GUI elements will need in Gramps
""" """
def __init__(self, maxgen, background, childring, radialtext, def __init__(self, maxgen, background, childring, radialtext, font,
on_childmenu_changed): on_childmenu_changed):
""" """
Common part of GUI that shows Fan Chart, needs to know what to do if Common part of GUI that shows Fan Chart, needs to know what to do if
@ -874,6 +875,7 @@ class FanChartGrampsGUI(object):
self.background = background self.background = background
self.childring = childring self.childring = childring
self.radialtext = radialtext self.radialtext = radialtext
self.fonttype = font
def have_parents(self, person): def have_parents(self, person):
"""on_childmenu_changed """on_childmenu_changed
@ -928,7 +930,7 @@ 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.radialtext, self.fonttype)
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

@ -63,7 +63,7 @@ class FanChartGramplet(FanChartGrampsGUI, Gramplet):
def __init__(self, gui, nav_group=0): def __init__(self, gui, nav_group=0):
Gramplet.__init__(self, gui, nav_group) Gramplet.__init__(self, gui, nav_group)
FanChartGrampsGUI.__init__(self, 6, 0, True, True, FanChartGrampsGUI.__init__(self, 6, 0, True, True, 'Sans',
self.on_childmenu_changed) self.on_childmenu_changed)
self.set_fan(FanChartWidget(self.dbstate, self.on_popup)) self.set_fan(FanChartWidget(self.dbstate, self.on_popup))
# Replace the standard textview with the fan chart widget: # Replace the standard textview with the fan chart widget:

View File

@ -48,6 +48,7 @@ from gui.views.navigationview import NavigationView
from gen.errors import WindowActiveError from gen.errors import WindowActiveError
from gui.views.bookmarks import PersonBookmarks from gui.views.bookmarks import PersonBookmarks
from gui.editors import EditPerson from gui.editors import EditPerson
from gui.utils import SystemFonts
# the print settings to remember between print sessions # the print settings to remember between print sessions
PRINT_SETTINGS = None PRINT_SETTINGS = None
@ -62,6 +63,7 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
('interface.fanview-background', 0), ('interface.fanview-background', 0),
('interface.fanview-childrenring', True), ('interface.fanview-childrenring', True),
('interface.fanview-radialtext', True), ('interface.fanview-radialtext', True),
('interface.fanview-font', 'Sans'),
) )
def __init__(self, pdata, dbstate, uistate, nav_group=0): def __init__(self, pdata, dbstate, uistate, nav_group=0):
self.dbstate = dbstate self.dbstate = dbstate
@ -76,12 +78,14 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
self._config.get('interface.fanview-background'), self._config.get('interface.fanview-background'),
self._config.get('interface.fanview-childrenring'), self._config.get('interface.fanview-childrenring'),
self._config.get('interface.fanview-radialtext'), self._config.get('interface.fanview-radialtext'),
self._config.get('interface.fanview-font'),
self.on_childmenu_changed) self.on_childmenu_changed)
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)
self.additional_uis.append(self.additional_ui()) self.additional_uis.append(self.additional_ui())
self.allfonts = [x for x in enumerate(SystemFonts().get_system_fonts())]
def navigation_type(self): def navigation_type(self):
return 'Person' return 'Person'
@ -263,6 +267,10 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
configdialog.add_checkbox(table, configdialog.add_checkbox(table,
_('Allow radial text at generation 6'), _('Allow radial text at generation 6'),
3, 'interface.fanview-radialtext') 3, '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
@ -308,6 +316,12 @@ class FanChartView(FanChartGrampsGUI, NavigationView):
self.radialtext = False self.radialtext = False
self.update() self.update()
def cb_update_font(self, obj, constant):
entry = obj.get_active()
self._config.set(constant, self.allfonts[entry][1])
self.fonttype = self.allfonts[entry][1]
self.update()
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# CairoPrintSave class # CairoPrintSave class