-
Notifications
You must be signed in to change notification settings - Fork 398
/
relview.py
2025 lines (1810 loc) · 73.1 KB
/
relview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2001-2007 Donald N. Allingham
# Copyright (C) 2009-2010 Gary Burton
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
"""
Relationship View
"""
# -------------------------------------------------------------------------
#
# Python modules
#
# -------------------------------------------------------------------------
from html import escape
import pickle
# -------------------------------------------------------------------------
#
# Set up logging
#
# -------------------------------------------------------------------------
import logging
_LOG = logging.getLogger("plugin.relview")
# -------------------------------------------------------------------------
#
# GTK/Gnome modules
#
# -------------------------------------------------------------------------
from gi.repository import Gdk
from gi.repository import Gtk
from gi.repository import Pango
# -------------------------------------------------------------------------
#
# Gramps Modules
#
# -------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext
ngettext = glocale.translation.ngettext # else "nearby" comments are ignored
from gramps.gen.lib import (
ChildRef,
EventRoleType,
EventType,
Family,
FamilyRelType,
Name,
Person,
Surname,
)
from gramps.gen.lib.date import Today
from gramps.gen.db import DbTxn
from gramps.gui.views.navigationview import NavigationView
from gramps.gui.uimanager import ActionGroup
from gramps.gui.editors import EditPerson, EditFamily
from gramps.gui.editors import FilterEditor
from gramps.gen.display.name import displayer as name_displayer
from gramps.gen.display.place import displayer as place_displayer
from gramps.gen.utils.file import media_path_full
from gramps.gen.utils.alive import probably_alive
from gramps.gui.utils import open_file_with_default_application
from gramps.gen.datehandler import displayer, get_date
from gramps.gen.utils.thumbnails import get_thumbnail_image
from gramps.gen.config import config
from gramps.gui import widgets
from gramps.gui.widgets.reorderfam import Reorder
from gramps.gui.selectors import SelectorFactory
from gramps.gen.errors import WindowActiveError
from gramps.gui.views.bookmarks import PersonBookmarks
from gramps.gen.const import CUSTOM_FILTERS
from gramps.gen.utils.db import (
get_birth_or_fallback,
get_death_or_fallback,
preset_name,
)
from gramps.gui.ddtargets import DdTargets
from gramps.gen.utils.symbols import Symbols
_NAME_START = 0
_LABEL_START = 0
_LABEL_STOP = 1
_DATA_START = _LABEL_STOP
_DATA_STOP = _DATA_START + 1
_BTN_START = _DATA_STOP
_BTN_STOP = _BTN_START + 2
_PLABEL_START = 1
_PLABEL_STOP = _PLABEL_START + 1
_PDATA_START = _PLABEL_STOP
_PDATA_STOP = _PDATA_START + 2
_PDTLS_START = _PLABEL_STOP
_PDTLS_STOP = _PDTLS_START + 2
_CLABEL_START = _PLABEL_START + 1
_CLABEL_STOP = _CLABEL_START + 1
_CDATA_START = _CLABEL_STOP
_CDATA_STOP = _CDATA_START + 1
_CDTLS_START = _CDATA_START
_CDTLS_STOP = _CDTLS_START + 1
_ALABEL_START = 0
_ALABEL_STOP = _ALABEL_START + 1
_ADATA_START = _ALABEL_STOP
_ADATA_STOP = _ADATA_START + 3
_SDATA_START = 2
_SDATA_STOP = 4
_RETURN = Gdk.keyval_from_name("Return")
_KP_ENTER = Gdk.keyval_from_name("KP_Enter")
_SPACE = Gdk.keyval_from_name("space")
_LEFT_BUTTON = 1
_RIGHT_BUTTON = 3
class RelationshipView(NavigationView):
"""
View showing a textual representation of the relationships of the
active person
"""
# settings in the config file
CONFIGSETTINGS = (
("preferences.family-siblings", True),
("preferences.family-details", True),
("preferences.relation-display-theme", "CLASSIC"),
("preferences.relation-shade", True),
("preferences.releditbtn", True),
)
def __init__(self, pdata, dbstate, uistate, nav_group=0):
NavigationView.__init__(
self,
_("Relationships"),
pdata,
dbstate,
uistate,
PersonBookmarks,
nav_group,
)
dbstate.connect("database-changed", self.change_db)
uistate.connect("nameformat-changed", self.build_tree)
uistate.connect("placeformat-changed", self.build_tree)
uistate.connect("font-changed", self.font_changed)
self.redrawing = False
self.child = None
self.old_handle = None
self.reorder_sensitive = False
self.collapsed_items = {}
self.additional_uis.append(self.additional_ui)
self.show_siblings = self._config.get("preferences.family-siblings")
self.show_details = self._config.get("preferences.family-details")
self.use_shade = self._config.get("preferences.relation-shade")
self.theme = self._config.get("preferences.relation-display-theme")
self.toolbar_visible = config.get("interface.toolbar-on")
self.age_precision = config.get("preferences.age-display-precision")
self.reload_symbols()
def get_handle_from_gramps_id(self, gid):
"""
returns the handle of the specified object
"""
obj = self.dbstate.db.get_person_from_gramps_id(gid)
if obj:
return obj.get_handle()
else:
return None
def _connect_db_signals(self):
"""
implement from base class DbGUIElement
Register the callbacks we need.
"""
# Add a signal to pick up event changes, bug #1416
self.callman.add_db_signal("event-update", self.family_update)
self.callman.add_db_signal("person-update", self.person_update)
self.callman.add_db_signal("person-rebuild", self.person_rebuild)
self.callman.add_db_signal("family-update", self.family_update)
self.callman.add_db_signal("family-add", self.family_add)
self.callman.add_db_signal("family-delete", self.family_delete)
self.callman.add_db_signal("family-rebuild", self.family_rebuild)
self.callman.add_db_signal("person-delete", self.redraw)
def reload_symbols(self):
self.symbols = Symbols()
if self.uistate and self.uistate.symbols:
gsfs = self.symbols.get_symbol_for_string
self.male = gsfs(self.symbols.SYMBOL_MALE)
self.female = gsfs(self.symbols.SYMBOL_FEMALE)
self.bth = gsfs(self.symbols.SYMBOL_BIRTH)
self.bptsm = gsfs(self.symbols.SYMBOL_BAPTISM)
self.marriage = gsfs(self.symbols.SYMBOL_MARRIAGE)
self.marr = gsfs(self.symbols.SYMBOL_HETEROSEXUAL)
self.homom = gsfs(self.symbols.SYMBOL_MALE_HOMOSEXUAL)
self.homof = gsfs(self.symbols.SYMBOL_LESBIAN)
self.divorce = gsfs(self.symbols.SYMBOL_DIVORCE)
self.unmarr = gsfs(self.symbols.SYMBOL_UNMARRIED_PARTNERSHIP)
death_idx = self.uistate.death_symbol
self.dth = self.symbols.get_death_symbol_for_char(death_idx)
self.burial = gsfs(self.symbols.SYMBOL_BURIED)
self.cremation = gsfs(self.symbols.SYMBOL_CREMATED)
else:
gsf = self.symbols.get_symbol_fallback
self.male = gsf(self.symbols.SYMBOL_MALE)
self.female = gsf(self.symbols.SYMBOL_FEMALE)
self.bth = gsf(self.symbols.SYMBOL_BIRTH)
self.bptsm = gsf(self.symbols.SYMBOL_BAPTISM)
self.marriage = gsf(self.symbols.SYMBOL_MARRIAGE)
self.marr = gsf(self.symbols.SYMBOL_HETEROSEXUAL)
self.homom = gsf(self.symbols.SYMBOL_MALE_HOMOSEXUAL)
self.homof = gsf(self.symbols.SYMBOL_LESBIAN)
self.divorce = gsf(self.symbols.SYMBOL_DIVORCE)
self.unmarr = gsf(self.symbols.SYMBOL_UNMARRIED_PARTNERSHIP)
death_idx = self.symbols.DEATH_SYMBOL_LATIN_CROSS
self.dth = self.symbols.get_death_symbol_fallback(death_idx)
self.burial = gsf(self.symbols.SYMBOL_BURIED)
self.cremation = gsf(self.symbols.SYMBOL_CREMATED)
def font_changed(self):
self.reload_symbols()
self.build_tree()
def navigation_type(self):
return "Person"
def can_configure(self):
"""
See :class:`~gui.views.pageview.PageView
:return: bool
"""
return True
def goto_handle(self, handle):
self.change_person(handle)
def shade_update(self, client, cnxn_id, entry, data):
self.use_shade = self._config.get("preferences.relation-shade")
self.toolbar_visible = config.get("interface.toolbar-on")
self.uistate.modify_statusbar(self.dbstate)
self.redraw()
def config_update(self, client, cnxn_id, entry, data):
self.show_siblings = self._config.get("preferences.family-siblings")
self.show_details = self._config.get("preferences.family-details")
self.redraw()
def build_tree(self):
self.redraw()
def person_update(self, handle_list):
if self.active:
person = self.get_active()
if person:
while not self.change_person(person):
pass
else:
self.change_person(None)
else:
self.dirty = True
def person_rebuild(self):
"""Large change to person database"""
if self.active:
self.bookmarks.redraw()
person = self.get_active()
if person:
while not self.change_person(person):
pass
else:
self.change_person(None)
else:
self.dirty = True
def family_update(self, handle_list):
if self.active:
person = self.get_active()
if person:
while not self.change_person(person):
pass
else:
self.change_person(None)
else:
self.dirty = True
def family_add(self, handle_list):
if self.active:
person = self.get_active()
if person:
while not self.change_person(person):
pass
else:
self.change_person(None)
else:
self.dirty = True
def family_delete(self, handle_list):
if self.active:
person = self.get_active()
if person:
while not self.change_person(person):
pass
else:
self.change_person(None)
else:
self.dirty = True
def family_rebuild(self):
if self.active:
person = self.get_active()
if person:
while not self.change_person(person):
pass
else:
self.change_person(None)
else:
self.dirty = True
def change_page(self):
NavigationView.change_page(self)
self.uistate.clear_filter_results()
def get_stock(self):
"""
Return the name of the stock icon to use for the display.
This assumes that this icon has already been registered with
GNOME as a stock icon.
"""
return "gramps-relation"
def get_viewtype_stock(self):
"""Type of view in category"""
return "gramps-relation"
def build_widget(self):
"""
Build the widget that contains the view, see
:class:`~gui.views.pageview.PageView
"""
container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
container.set_border_width(12)
self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.vbox.show()
self.header = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.header.show()
self.child = None
self.scroll = Gtk.ScrolledWindow()
self.scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
self.scroll.show()
vp = Gtk.Viewport()
vp.set_shadow_type(Gtk.ShadowType.NONE)
vp.add(self.vbox)
self.scroll.add(vp)
self.scroll.show_all()
container.set_spacing(6)
container.pack_start(self.header, False, False, 0)
container.pack_start(Gtk.Separator(), False, False, 0)
container.pack_start(self.scroll, True, True, 0)
container.show_all()
return container
additional_ui = [ # Defines the UI string for UIManager
"""
<placeholder id="CommonGo">
<section>
<item>
<attribute name="action">win.Back</attribute>
<attribute name="label" translatable="yes">_Add Bookmark</attribute>
</item>
<item>
<attribute name="action">win.Forward</attribute>
<attribute name="label" translatable="yes">"""
"""Organize Bookmarks...</attribute>
</item>
</section>
<section>
<item>
<attribute name="action">win.HomePerson</attribute>
<attribute name="label" translatable="yes">_Home</attribute>
</item>
</section>
</placeholder>
""",
"""
<placeholder id='otheredit'>
<item>
<attribute name="action">win.Edit</attribute>
<attribute name="label" translatable="yes">Edit...</attribute>
</item>
<item>
<attribute name="action">win.AddParents</attribute>
<attribute name="label" translatable="yes">"""
"""Add New Parents...</attribute>
</item>
<item>
<attribute name="action">win.ShareFamily</attribute>
<attribute name="label" translatable="yes">"""
"""Add Existing Parents...</attribute>
</item>
<item>
<attribute name="action">win.AddSpouse</attribute>
<attribute name="label" translatable="yes">Add Partner...</attribute>
</item>
<item>
<attribute name="action">win.ChangeOrder</attribute>
<attribute name="label" translatable="yes">_Reorder</attribute>
</item>
<item>
<attribute name="action">win.FilterEdit</attribute>
<attribute name="label" translatable="yes">"""
"""Person Filter Editor</attribute>
</item>
</placeholder>
""",
"""
<section id="AddEditBook">
<item>
<attribute name="action">win.AddBook</attribute>
<attribute name="label" translatable="yes">_Add Bookmark</attribute>
</item>
<item>
<attribute name="action">win.EditBook</attribute>
<attribute name="label" translatable="no">%s...</attribute>
</item>
</section>
"""
% _("Organize Bookmarks"), # Following are the Toolbar items
"""
<placeholder id='CommonNavigation'>
<child groups='RO'>
<object class="GtkToolButton">
<property name="icon-name">go-previous</property>
<property name="action-name">win.Back</property>
<property name="tooltip_text" translatable="yes">"""
"""Go to the previous object in the history</property>
<property name="label" translatable="yes">_Back</property>
<property name="use-underline">True</property>
</object>
<packing>
<property name="homogeneous">False</property>
</packing>
</child>
<child groups='RO'>
<object class="GtkToolButton">
<property name="icon-name">go-next</property>
<property name="action-name">win.Forward</property>
<property name="tooltip_text" translatable="yes">"""
"""Go to the next object in the history</property>
<property name="label" translatable="yes">_Forward</property>
<property name="use-underline">True</property>
</object>
<packing>
<property name="homogeneous">False</property>
</packing>
</child>
<child groups='RO'>
<object class="GtkToolButton">
<property name="icon-name">go-home</property>
<property name="action-name">win.HomePerson</property>
<property name="tooltip_text" translatable="yes">"""
"""Go to the home person</property>
<property name="label" translatable="yes">_Home</property>
<property name="use-underline">True</property>
</object>
<packing>
<property name="homogeneous">False</property>
</packing>
</child>
</placeholder>
""",
"""
<placeholder id='BarCommonEdit'>
<child groups='RW'>
<object class="GtkToolButton">
<property name="icon-name">gtk-edit</property>
<property name="action-name">win.Edit</property>
<property name="tooltip_text" translatable="yes">"""
"""Edit the active person</property>
<property name="label" translatable="yes">Edit...</property>
</object>
<packing>
<property name="homogeneous">False</property>
</packing>
</child>
<child groups='RW'>
<object class="GtkToolButton">
<property name="icon-name">gramps-parents-add</property>
<property name="action-name">win.AddParents</property>
<property name="tooltip_text" translatable="yes">"""
"""Add a new set of parents</property>
<property name="label" translatable="yes">Add</property>
</object>
<packing>
<property name="homogeneous">False</property>
</packing>
</child>
<child groups='RW'>
<object class="GtkToolButton">
<property name="icon-name">gramps-parents-open</property>
<property name="action-name">win.ShareFamily</property>
<property name="tooltip_text" translatable="yes">"""
"""Add person as child to an existing family</property>
<property name="label" translatable="yes">Share</property>
</object>
<packing>
<property name="homogeneous">False</property>
</packing>
</child>
<child groups='RW'>
<object class="GtkToolButton">
<property name="icon-name">gramps-spouse</property>
<property name="action-name">win.AddSpouse</property>
<property name="tooltip_text" translatable="yes">"""
"""Add a new family with person as parent</property>
<property name="label" translatable="yes">Partner</property>
</object>
<packing>
<property name="homogeneous">False</property>
</packing>
</child>
<child groups='RW'>
<object class="GtkToolButton">
<property name="icon-name">view-sort-ascending</property>
<property name="action-name">win.ChangeOrder</property>
<property name="tooltip_text" translatable="yes">"""
"""Change order of parents and families</property>
<property name="label" translatable="yes">_Reorder</property>
<property name="use-underline">True</property>
</object>
<packing>
<property name="homogeneous">False</property>
</packing>
</child>
</placeholder>
""",
]
def define_actions(self):
NavigationView.define_actions(self)
self.order_action = ActionGroup(name=self.title + "/ChangeOrder")
self.order_action.add_actions([("ChangeOrder", self.reorder)])
self.family_action = ActionGroup(name=self.title + "/Family")
self.family_action.add_actions(
[
("Edit", self.edit_active, "<PRIMARY>Return"),
("AddSpouse", self.add_spouse),
("AddParents", self.add_parents),
("ShareFamily", self.select_parents),
]
)
self._add_action("FilterEdit", callback=self.filter_editor)
self._add_action("PRIMARY-J", self.jump, "<PRIMARY>J")
self._add_action_group(self.order_action)
self._add_action_group(self.family_action)
self.uimanager.set_actions_sensitive(self.order_action, self.reorder_sensitive)
self.uimanager.set_actions_sensitive(self.family_action, False)
def filter_editor(self, *obj):
try:
FilterEditor("Person", CUSTOM_FILTERS, self.dbstate, self.uistate)
except WindowActiveError:
return
def change_db(self, db):
# reset the connects
self._change_db(db)
if self.child:
list(map(self.vbox.remove, self.vbox.get_children()))
list(map(self.header.remove, self.header.get_children()))
self.child = None
if self.active:
self.bookmarks.redraw()
self.redraw()
def get_name(self, handle, use_gender=False):
if handle:
person = self.dbstate.db.get_person_from_handle(handle)
name = name_displayer.display(person)
if use_gender:
gender = self.symbols.get_symbol_for_string(person.gender)
else:
gender = ""
return (name, gender)
else:
return (_("Unknown"), "")
def redraw(self, *obj):
active_person = self.get_active()
if active_person:
self.change_person(active_person)
else:
self.change_person(None)
def change_person(self, obj):
self.change_active(obj)
try:
return self._change_person(obj)
except AttributeError as msg:
import traceback
exc = traceback.format_exc()
_LOG.error(str(msg) + "\n" + exc)
from gramps.gui.dialog import RunDatabaseRepair
RunDatabaseRepair(str(msg), parent=self.uistate.window)
self.redrawing = False
return True
def _change_person(self, obj):
if obj == self.old_handle:
# same object, keep present scroll position
old_vadjust = self.scroll.get_vadjustment().get_value()
self.old_handle = obj
else:
# different object, scroll to top
old_vadjust = self.scroll.get_vadjustment().get_lower()
self.old_handle = obj
self.scroll.get_vadjustment().set_value(
self.scroll.get_vadjustment().get_lower()
)
if self.redrawing:
return False
self.redrawing = True
for old_child in self.vbox.get_children():
self.vbox.remove(old_child)
for old_child in self.header.get_children():
self.header.remove(old_child)
person = None
if obj:
person = self.dbstate.db.get_person_from_handle(obj)
if not person:
self.uimanager.set_actions_sensitive(self.family_action, False)
self.uimanager.set_actions_sensitive(self.order_action, False)
self.redrawing = False
return
self.uimanager.set_actions_sensitive(self.family_action, True)
self.write_title(person)
self.child = Gtk.Grid()
self.child.set_border_width(12)
self.child.set_column_spacing(12)
self.child.set_row_spacing(0)
self.row = 0
family_handle_list = person.get_parent_family_handle_list()
self.reorder_sensitive = len(family_handle_list) > 1
if family_handle_list:
for family_handle in family_handle_list:
if family_handle:
self.write_parents(family_handle, person)
else:
self.write_label(_("%s:") % _("Parents"), None, True, person)
self.row += 1
family_handle_list = person.get_family_handle_list()
if not self.reorder_sensitive:
self.reorder_sensitive = len(family_handle_list) > 1
if family_handle_list:
for family_handle in family_handle_list:
if family_handle:
self.write_family(family_handle, person)
self.child.show_all()
self.vbox.pack_start(self.child, False, True, 0)
# reset scroll position as it was before
self.scroll.get_vadjustment().set_value(old_vadjust)
self.redrawing = False
self.uistate.modify_statusbar(self.dbstate)
self.uimanager.set_actions_sensitive(self.order_action, self.reorder_sensitive)
self.dirty = False
return True
def write_title(self, person):
list(map(self.header.remove, self.header.get_children()))
grid = Gtk.Grid()
grid.set_column_spacing(12)
grid.set_row_spacing(0)
# name and edit button
name = name_displayer.display(person)
fmt = '<span size="larger" weight="bold">%s</span>'
text = fmt % escape(name)
gender_code = self.symbols.get_symbol_for_string(person.gender)
label = widgets.DualMarkupLabel(text, gender_code, halign=Gtk.Align.END)
if self._config.get("preferences.releditbtn"):
button = widgets.IconButton(self.edit_button_press, person.handle)
button.set_tooltip_text(_("Edit Person (%s)") % name)
else:
button = None
eventbox = Gtk.EventBox()
eventbox.set_visible_window(False)
self._set_draggable_person(eventbox, person.get_handle())
hbox = widgets.LinkBox(label, button)
eventbox.add(hbox)
grid.attach(eventbox, 0, 0, 2, 1)
eventbox = widgets.ShadeBox(self.use_shade)
grid.attach(eventbox, 1, 1, 1, 1)
subgrid = Gtk.Grid()
subgrid.set_column_spacing(12)
subgrid.set_row_spacing(0)
eventbox.add(subgrid)
self._set_draggable_person(eventbox, person.get_handle())
# Gramps ID
subgrid.attach(widgets.BasicLabel(_("%s:") % _("ID")), 1, 0, 1, 1)
label = widgets.BasicLabel(person.gramps_id)
label.set_hexpand(True)
subgrid.attach(label, 2, 0, 1, 1)
# Birth event.
birth = get_birth_or_fallback(self.dbstate.db, person)
if birth:
if birth.get_type() == EventType.BAPTISM:
birth_title = self.bptsm
else:
birth_title = self.bth
else:
birth_title = self.bth
subgrid.attach(widgets.BasicLabel(_("%s") % birth_title), 1, 1, 1, 1)
birthwidget = widgets.BasicLabel(self.format_event(birth))
birthwidget.set_selectable(True)
subgrid.attach(birthwidget, 2, 1, 1, 1)
death = get_death_or_fallback(self.dbstate.db, person)
if death:
if death.get_type() == EventType.BURIAL:
death_title = self.burial
elif death.get_type() == EventType.CREMATION:
death_title = self.cremation
else:
death_title = self.dth
else:
death_title = self.dth
showed_death = False
if birth:
birth_date = birth.get_date_object()
if birth_date and birth_date.get_valid():
if death:
death_date = death.get_date_object()
if death_date and death_date.get_valid():
age = (death_date - birth_date).format(
precision=self.age_precision
)
subgrid.attach(
widgets.BasicLabel(_("%s") % death_title), 1, 2, 1, 1
)
deathwidget = widgets.BasicLabel(
"%s (%s)" % (self.format_event(death), age),
Pango.EllipsizeMode.END,
)
deathwidget.set_selectable(True)
subgrid.attach(deathwidget, 2, 2, 1, 1)
showed_death = True
if not showed_death:
age = (Today() - birth_date).format(precision=self.age_precision)
if probably_alive(person, self.dbstate.db):
subgrid.attach(
widgets.BasicLabel(_("%s:") % _("Alive")), 1, 2, 1, 1
)
subgrid.attach(
widgets.BasicLabel("(%s)" % age, Pango.EllipsizeMode.END),
2,
2,
1,
1,
)
else:
subgrid.attach(
widgets.BasicLabel(_("%s") % self.dth), 1, 2, 1, 1
)
subgrid.attach(
widgets.BasicLabel(
"%s (%s)" % (_("unknown"), age), Pango.EllipsizeMode.END
),
2,
2,
1,
1,
)
showed_death = True
if not showed_death:
subgrid.attach(widgets.BasicLabel(_("%s") % death_title), 1, 2, 1, 1)
deathwidget = widgets.BasicLabel(self.format_event(death))
deathwidget.set_selectable(True)
subgrid.attach(deathwidget, 2, 2, 1, 1)
mbox = Gtk.Box()
mbox.add(grid)
# image
image_list = person.get_media_list()
if image_list:
mobj = self.dbstate.db.get_media_from_handle(image_list[0].ref)
if mobj and mobj.get_mime_type()[0:5] == "image":
pixbuf = get_thumbnail_image(
media_path_full(self.dbstate.db, mobj.get_path()),
rectangle=image_list[0].get_rectangle(),
)
image = Gtk.Image()
image.set_from_pixbuf(pixbuf)
button = Gtk.Button()
button.add(image)
button.connect("clicked", lambda obj: self.view_photo(mobj))
mbox.pack_end(button, False, True, 0)
mbox.show_all()
self.header.pack_start(mbox, False, True, 0)
def view_photo(self, photo):
"""
Open this picture in the default picture viewer.
"""
photo_path = media_path_full(self.dbstate.db, photo.get_path())
open_file_with_default_application(photo_path, self.uistate)
def write_person_event(self, ename, event):
if event:
dobj = event.get_date_object()
phandle = event.get_place_handle()
if phandle:
pname = place_displayer.display_event(self.dbstate.db, event)
else:
pname = None
value = {
"date": displayer.display(dobj),
"place": pname,
}
else:
pname = None
dobj = None
if dobj:
if pname:
self.write_person_data(ename, _("%(date)s in %(place)s") % value)
else:
self.write_person_data(ename, "%(date)s" % value)
elif pname:
self.write_person_data(ename, pname)
else:
self.write_person_data(ename, "")
def format_event(self, event):
if event:
dobj = event.get_date_object()
phandle = event.get_place_handle()
if phandle:
pname = place_displayer.display_event(self.dbstate.db, event)
else:
pname = None
value = {
"date": displayer.display(dobj),
"place": pname,
}
else:
pname = None
dobj = None
if dobj:
if pname:
return _("%(date)s in %(place)s") % value
else:
return "%(date)s" % value
elif pname:
return pname
else:
return ""
def write_person_data(self, title, data):
self.child.attach(
widgets.BasicLabel(title),
_ALABEL_START,
self.row,
_ALABEL_STOP - _ALABEL_START,
1,
)
self.child.attach(
widgets.BasicLabel(data),
_ADATA_START,
self.row,
_ADATA_STOP - _ADATA_START,
1,
)
self.row += 1
def marriage_symbol(self, family, markup=True):
if family:
father = mother = None
hdl1 = family.get_father_handle()
if hdl1:
father = self.dbstate.db.get_person_from_handle(hdl1).gender
hdl2 = family.get_mother_handle()
if hdl2:
mother = self.dbstate.db.get_person_from_handle(hdl2).gender
if father != mother:
symbol = self.marr
elif father == Person.MALE:
symbol = self.homom
else:
symbol = self.homof
if markup:
msg = '<span size="12000" >%s</span>' % symbol
else:
msg = symbol
else:
msg = ""
return msg
def write_label(self, title, family, is_parent, person=None):
"""
Write a Family header row
Shows following elements:
(collapse/expand arrow, Parents/Family title label, Family gramps_id,
and add-choose-edit-delete buttons)
"""
msg = '<span style="italic" weight="heavy">%s</span>' % escape(title)
hbox = Gtk.Box()
label = widgets.MarkupLabel(msg, halign=Gtk.Align.END)
# Draw the collapse/expand button:
if family is not None:
if self.check_collapsed(person.handle, family.handle):
arrow = widgets.ExpandCollapseArrow(
True, self.expand_collapse_press, (person, family.handle)
)
else:
arrow = widgets.ExpandCollapseArrow(
False, self.expand_collapse_press, (person, family.handle)
)
else:
arrow = Gtk.Arrow(
arrow_type=Gtk.ArrowType.RIGHT, shadow_type=Gtk.ShadowType.OUT
)
hbox.pack_start(arrow, False, True, 0)
hbox.pack_start(label, True, True, 0)
# Allow to drag this family
eventbox = Gtk.EventBox()
if family is not None:
self._set_draggable_family(eventbox, family.handle)
eventbox.add(hbox)
self.child.attach(
eventbox, _LABEL_START, self.row, _LABEL_STOP - _LABEL_START, 1
)
if family:
value = family.gramps_id
else:
value = ""
eventbox = Gtk.EventBox()
if family is not None:
self._set_draggable_family(eventbox, family.handle)
eventbox.add(widgets.BasicLabel(value))
self.child.attach(eventbox, _DATA_START, self.row, _DATA_STOP - _DATA_START, 1)