Skip to content

Commit f42064d

Browse files
SNoiraudNick-Hall
authored andcommitted
Geps 039 genealogical symbols
Symbols for GraphView, QuiltView and TimelinePedigreeView
1 parent c8a1d35 commit f42064d

File tree

3 files changed

+107
-23
lines changed

3 files changed

+107
-23
lines changed

GraphView/graphview.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
from gramps.gui.views.bookmarks import PersonBookmarks
7474
from gramps.gui.widgets import progressdialog as progressdlg
7575
from gramps.gui.widgets.menuitem import add_menuitem
76+
from gramps.gen.utils.symbols import Symbols
7677

7778
from gramps.gen.const import GRAMPS_LOCALE as glocale
7879
try:
@@ -104,7 +105,6 @@
104105

105106
WIKI_PAGE = 'https://gramps-project.org/wiki/index.php?title=Graph_View'
106107

107-
108108
#-------------------------------------------------------------------------
109109
#
110110
# GraphView
@@ -158,6 +158,11 @@ def __init__(self, pdata, dbstate, uistate, nav_group=0):
158158

159159
self.additional_uis.append(self.additional_ui)
160160
self.define_print_actions()
161+
self.uistate.connect('font-changed', self.font_changed)
162+
163+
def font_changed(self):
164+
self.graph_widget.font_changed(self.get_active())
165+
#self.goto_handle(None)
161166

162167
# for disable animation options in config dialog
163168
self.ani_widgets = []
@@ -597,7 +602,6 @@ def printview(self, *obj):
597602
ErrorDialog(msg2, str(msg), parent=dot)
598603
dot.destroy()
599604

600-
601605
#-------------------------------------------------------------------------
602606
#
603607
# GraphWidget
@@ -619,6 +623,7 @@ def __init__(self, view, dbstate, uistate):
619623
self.view = view
620624
self.dbstate = dbstate
621625
self.uistate = uistate
626+
self.parser = None
622627
self.active_person_handle = None
623628

624629
self.dot_data = None
@@ -733,6 +738,12 @@ def __init__(self, view, dbstate, uistate):
733738
# Gtk style context for scrollwindow to operate with theme colors
734739
self.sw_style_context = scrolled_win.get_style_context()
735740

741+
def font_changed(self, active):
742+
self.font = config.get('utf8.selected-font')
743+
if self.parser:
744+
self.parser.font_changed()
745+
self.populate(active)
746+
736747
def set_ancestors_generations(self, widget):
737748
"""
738749
Set count of ancestors generations to show.
@@ -921,7 +932,7 @@ def fit_to_page(self, button):
921932
width_canvas = bounds.x2 - bounds.x1
922933

923934
# get scroll window size
924-
width = self.hadjustment.get_page_size()
935+
width = self.hadjustment.get_page_size()
925936
height = self.vadjustment.get_page_size()
926937

927938
# prevent division by zero
@@ -1787,6 +1798,10 @@ def __init__(self, widget, view):
17871798
"Arial": "Helvetica",}
17881799

17891800
self.transform_scale = 1
1801+
self.font_changed()
1802+
1803+
def font_changed(self):
1804+
self.font = config.get('utf8.selected-font')
17901805

17911806
def parse(self, ifile):
17921807
"""
@@ -2039,6 +2054,7 @@ def stop_text(self, tag):
20392054
anchor = self.text_attrs.get('text-anchor')
20402055
style = self.text_attrs.get('style')
20412056

2057+
# does the following always work with symbols?
20422058
if style:
20432059
p_style = self.parse_style(style)
20442060
try:
@@ -2132,7 +2148,6 @@ def parse_style(self, style):
21322148
style = style.rstrip(';')
21332149
return dict([i.split(':') for i in style.split(';')])
21342150

2135-
21362151
#------------------------------------------------------------------------
21372152
#
21382153
# DotSvgGenerator
@@ -2147,6 +2162,7 @@ def __init__(self, dbstate, view):
21472162
Initialise the DotSvgGenerator class.
21482163
"""
21492164
self.dbstate = dbstate
2165+
self.uistate = uistate
21502166
self.database = dbstate.db
21512167
self.view = view
21522168

@@ -2270,6 +2286,21 @@ def init_dot(self):
22702286
self.write(' node [style=filled fontsize=%d fontcolor="%s"];\n'
22712287
% (fontsize, font_color))
22722288
self.write('\n')
2289+
self.uistate.connect('font-changed', self.font_changed)
2290+
self.symbols = Symbols()
2291+
self.font_changed()
2292+
2293+
def font_changed(self):
2294+
self.font = config.get('utf8.selected-font')
2295+
dth_idx = self.uistate.death_symbol
2296+
if self.uistate.symbols:
2297+
self.bth = self.symbols.get_symbol_for_string(
2298+
self.symbols.SYMBOL_BIRTH)
2299+
self.dth = self.symbols.get_death_symbol_for_char(dth_idx)
2300+
else:
2301+
self.bth = self.symbols.get_symbol_fallback(
2302+
self.symbols.SYMBOL_BIRTH)
2303+
self.dth = self.symbols.get_death_symbol_fallback(dth_idx)
22732304

22742305
def build_graph(self, active_person):
22752306
"""
@@ -2683,12 +2714,14 @@ def get_person_label(self, person):
26832714
# d. 1960-01-02 - DeathPlace
26842715
if self.show_full_dates or self.show_places:
26852716
if birth:
2686-
txt = _('b. %s') % birth # short for "born" (could be "*")
2717+
txt = _('%s %s') % (self.bth, birth)
2718+
# line separator required only if we have both birth and death
26872719
label += txt
26882720
if death:
26892721
if birth:
26902722
label += line_delimiter
2691-
txt = _('d. %s') % death # short for "died" (could be "+")
2723+
#txt = _('d. %s') % death # short for "died" (could be "+")
2724+
txt = _('%s %s') % (self.dth, death)
26922725
label += txt
26932726
# 2) simple and on one line:
26942727
# (1890 - 1960)
@@ -2896,7 +2929,6 @@ def write(self, text):
28962929
if self.dot:
28972930
self.dot.write(text)
28982931

2899-
29002932
#-------------------------------------------------------------------------
29012933
#
29022934
# CanvasAnimation

QuiltView/QuiltView.py

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
from gramps.gen.utils.libformatting import FormattingHelper
7979
from gramps.gen.db import DbTxn
8080
from gramps.gui.display import display_url
81+
from gramps.gen.utils.symbols import Symbols
82+
from gramps.gen.utils.alive import probably_alive
8183

8284
BORDER = 10
8385
HEIGHT = 18
@@ -110,15 +112,18 @@ def draw(self, canvas, cr):
110112
pass
111113

112114
class PersonNode(Node):
113-
def __init__(self, handle, layer, name, sex, ident, fg_color, bg_color):
115+
def __init__(self, handle, layer, name, sex, ident,
116+
fg_color, bg_color, dead):
114117
Node.__init__(self, handle, layer)
115118
self.name = name
116119
self.sex = sex
117120
self.ident = ident
118121
self.fg_color = fg_color
119122
self.bg_color = bg_color
123+
self.dead = dead
120124
self.parents = []
121125
self.children = []
126+
self.symbols = Symbols()
122127

123128
def add_main_family(self, family):
124129
self.parents.append(family)
@@ -127,12 +132,16 @@ def add_family(self, family):
127132
self.children.append(family)
128133

129134
def draw(self, canvas, cr):
130-
if self.sex == Person.MALE:
131-
label = '\u2642 ' + self.name
132-
elif self.sex == Person.FEMALE:
133-
label = '\u2640 ' + self.name
135+
if self.sex is not None:
136+
sex_char = self.symbols.get_symbol_for_string(self.sex)
134137
else:
135-
label = '\u2650 ' + self.name
138+
sex_char = ''
139+
if config.get('utf8.in-use'):
140+
if self.sex is not None:
141+
sex_char = self.symbols.get_symbol_for_string(self.sex)
142+
else:
143+
sex_char = ''
144+
label = sex_char + ' ' + self.dead + ' ' + self.name
136145

137146
layout = canvas.create_pango_layout(label)
138147
if is_quartz():
@@ -219,6 +228,8 @@ def __init__(self, pdata, dbstate, uistate, nav_group=0):
219228
self.dbstate = dbstate
220229
self.uistate = uistate
221230
self.dbstate.connect('database-changed', self.change_db)
231+
self.uistate.connect('font-changed', self.rebuild)
232+
self.uistate.connect('nameformat-changed', self.rebuild)
222233

223234
self.additional_uis.append(self.additional_ui)
224235

@@ -230,7 +241,7 @@ def __init__(self, pdata, dbstate, uistate, nav_group=0):
230241
self.layers = None
231242
self.people = []
232243
self.paths = []
233-
self.format_helper = FormattingHelper(self.dbstate)
244+
self.format_helper = FormattingHelper(self.dbstate, self.uistate)
234245
scheme = config.get('colors.scheme')
235246
self.home_person_color = config.get('colors.home-person')[scheme]
236247
self.timeout = None
@@ -239,6 +250,7 @@ def __init__(self, pdata, dbstate, uistate, nav_group=0):
239250
self.total = 0
240251
self.progress = None
241252
self.load = 0 # avoid to load the database twice
253+
self.symbols = Symbols()
242254

243255
def get_stock(self):
244256
"""
@@ -275,6 +287,7 @@ def build_widget(self):
275287
Gdk.EventMask.POINTER_MOTION_MASK |
276288
Gdk.EventMask.SCROLL_MASK |
277289
Gdk.EventMask.KEY_PRESS_MASK)
290+
self.on_draw_ok = -1
278291

279292
self.scrolledwindow.add(self.canvas)
280293

@@ -549,11 +562,14 @@ def _entry_key_event(self, combobox):
549562
count += 1
550563
found = name[0]
551564
self.name_store.append(name)
565+
self.show_message(count)
566+
567+
def show_message(self, count=0):
552568
self.message.set_label(
553569
_("You have %(filter)d filtered people, "
554570
"%(count)d people shown on the tree "
555571
"and %(total)d people in your database."
556-
% {'filter': count if search != "" else 0,
572+
% {'filter': count,
557573
'count': len(self.plist),
558574
'total': self.total}))
559575

@@ -568,6 +584,7 @@ def _erase_name_selection(self, arg=None):
568584
"""
569585
We erase the name in the entrybox
570586
"""
587+
self.name_combo.get_child().set_text(" ") # force entry change
571588
self.name_combo.get_child().set_text("")
572589

573590
def add_bookmark(self, handle):
@@ -608,7 +625,6 @@ def center_on_node(self, obj, handle):
608625
self.set_path_lines(self.people[handle])
609626

610627
def goto_handle(self, handle=None):
611-
self._erase_name_selection()
612628
self._clear_list_store()
613629
if self.load < 3: # avoid to load the database twice
614630
self.load = 3
@@ -647,6 +663,11 @@ def read_data(self, handle):
647663
self.progress.set_pass(message, self.total)
648664
todo = [(handle, 0)]
649665
count = 0
666+
death_idx = self.uistate.death_symbol
667+
if self.uistate.symbols:
668+
death_char = self.symbols.get_death_symbol_for_char(death_idx)
669+
else:
670+
death_char = self.symbols.get_death_symbol_fallback(death_idx)
650671
while todo:
651672
handle, layer = todo.pop()
652673
count += 1 # persons + families
@@ -672,8 +693,10 @@ def read_data(self, handle):
672693
death_event = get_death_or_fallback(self.dbstate.db, person)
673694
if death_event:
674695
fill, color = color_graph_box(False, sex)
696+
dead = death_char
675697
else:
676698
fill, color = color_graph_box(True, sex)
699+
dead = ' '
677700
color = Gdk.color_parse(color)
678701
fg_color = (float(color.red / 65535.0),
679702
float(color.green / 65535.0),
@@ -689,8 +712,8 @@ def read_data(self, handle):
689712
float(color.green / 65535.0),
690713
float(color.blue / 65535.0))
691714

692-
people[handle] = PersonNode(handle, layer, name,
693-
sex, ident, fg_color, bg_color)
715+
people[handle] = PersonNode(handle, layer, name, sex, ident,
716+
fg_color, bg_color, dead)
694717

695718
for fhandle in person.get_family_handle_list():
696719
people[handle].add_main_family(fhandle)
@@ -746,15 +769,31 @@ def rebuild(self):
746769
if self.load < 3: # avoid to load the database twice
747770
return
748771
self.total = self.dbstate.db.get_number_of_people()
772+
self._erase_name_selection()
749773
active = self.get_active()
750774
if active != "":
775+
self.on_draw_ok = -1
751776
self.people, self.families, self.layers = self.read_data(active)
752-
self.name_combo.get_child().set_text(" ") # force entry change
753-
self.name_combo.get_child().set_text("")
754777
self.canvas.queue_draw()
755778
self.canvas.grab_focus()
756-
self.center_on_node(None, active)
757-
self.set_path_lines(active)
779+
# We need to wait on_draw is called to draw path lines.
780+
self.on_draw_ok = 0
781+
GLib.timeout_add(int(200), self.after_on_draw_on_rebuild)
782+
783+
def after_on_draw_on_rebuild(self):
784+
"""
785+
Loop to see if we can draw the path lines
786+
"""
787+
if self.on_draw_ok == 0:
788+
return True # continue to wait
789+
#We can now set path lines. Nodes are totaly initialized.
790+
active = self.get_active()
791+
if active != "":
792+
node = self.people[active]
793+
self.center_on_node(None, node)
794+
self.set_path_lines(node)
795+
self.show_message()
796+
return False
758797

759798
def on_draw(self, canvas, cr):
760799
"""
@@ -887,6 +926,8 @@ def on_draw(self, canvas, cr):
887926
(y + BORDER) * self.scale)
888927

889928
#print ('draw time', clock()- c)
929+
if self.on_draw_ok == 0:
930+
self.on_draw_ok = 1 # We can now draw path lines
890931

891932
def home(self, *obj):
892933
defperson = self.dbstate.db.get_default_person()
@@ -1716,6 +1757,8 @@ def set_path_lines(self, obj):
17161757
"""
17171758
obj : either a person or a family
17181759
"""
1760+
if obj.x is None:
1761+
return
17191762
self.paths = []
17201763
_col = self._config.get
17211764
color_path = _col('interface.quiltview-color-path')
@@ -1753,6 +1796,8 @@ def calculate_segment_length(self, obj):
17531796
These coordinates include the name,
17541797
the segment for the parents and the segment for the children
17551798
"""
1799+
if obj.x is None:
1800+
return
17561801
if isinstance(obj, PersonNode):
17571802
x1 = obj.x
17581803
x2 = obj.x + obj.width

TimelinePedigreeView/TimelinePedigreeView.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
from gramps.gui.utils import is_right_click
6565
from gramps.gen.constfunc import is_quartz
6666
from gramps.gen.const import GRAMPS_LOCALE as glocale
67+
from gramps.gen.utils.symbols import Symbols
6768
try:
6869
trans = glocale.get_addon_translator(__file__)
6970
except ValueError:
@@ -341,6 +342,7 @@ def __init__(self, pdata, dbstate, uistate, nav_group=0):
341342
nav_group)
342343

343344
self.dbstate = dbstate
345+
self.uistate = uistate
344346
self.dbstate.connect('database-changed', self.change_db)
345347

346348
self.additional_uis.append(self.additional_ui)
@@ -389,7 +391,7 @@ def __init__(self, pdata, dbstate, uistate, nav_group=0):
389391
# Default - not show, for mo fast display hight tree
390392
self.show_unknown_peoples = self.cman.get('interface.show-unknown-people')
391393

392-
self.format_helper = FormattingHelper(self.dbstate)
394+
self.format_helper = FormattingHelper(self.dbstate, self.uistate)
393395

394396
# Depth of tree.
395397
self._depth = 1
@@ -404,6 +406,11 @@ def __init__(self, pdata, dbstate, uistate, nav_group=0):
404406
self.gtklayout_lines = []
405407
self.gtklayout_boxes = []
406408
self._birth_cache = {}
409+
self.uistate.connect('font-changed', self.font_changed)
410+
411+
def font_changed(self):
412+
self.format_helper.reload_symbols()
413+
self.person_rebuild()
407414

408415
def on_delete(self):
409416
"""Save the configuration settings on shutdown."""

0 commit comments

Comments
 (0)