-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathcombinedview.py
707 lines (634 loc) · 23.9 KB
/
combinedview.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
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2001-2007 Donald N. Allingham
# Copyright (C) 2009-2010 Gary Burton
# Copyright (C) 2015-2016 Nick Hall
#
# 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.
#
"""
Combined View
"""
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
from html import escape
from operator import itemgetter
import pickle
import logging
import os
import re
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
from gi.repository import Gdk
from gi.repository import Gtk
from gi.repository import Pango
from gi.repository import GdkPixbuf
#-------------------------------------------------------------------------
#
# Gramps Modules
#
#-------------------------------------------------------------------------
from navigationview import NavigationView
from personpage import PersonPage
from eventpage import EventPage
from gramps.gen.config import config
from gramps.gen.lib import Family, ChildRef, Person
from gramps.gui.uimanager import ActionGroup
from gramps.gui.selectors import SelectorFactory
from gramps.gen.errors import WindowActiveError
from gramps.gui.views.bookmarks import PersonBookmarks
from gramps.gui.editors import FilterEditor
from gramps.gen.const import CUSTOM_FILTERS
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext
_LOG = logging.getLogger("plugin.relview")
class CombinedView(NavigationView):
"""
View showing a textual representation of the relationships and events of
the active person.
"""
#settings in the config file
CONFIGSETTINGS = (
('preferences.family-siblings', True),
('preferences.family-details', True),
('preferences.show-tags', True),
('preferences.relation-display-theme', "CLASSIC"),
('preferences.relation-shade', True),
('preferences.releditbtn', True),
('preferences.show-tags', True),
('preferences.vertical-details', True),
)
def __init__(self, pdata, dbstate, uistate, nav_group=0):
NavigationView.__init__(self, _('Combined'),
pdata, dbstate, uistate,
PersonBookmarks,
nav_group)
dbstate.connect('database-changed', self.change_db)
uistate.connect('nameformat-changed', self.build_tree)
self.redrawing = False
self.pages = {}
self._add_page(PersonPage(self.dbstate, self.uistate, self._config))
self._add_page(EventPage(self.dbstate, self.uistate, self._config))
self.active_page = None
self.additional_uis.append(self.additional_ui)
def _add_page(self, page):
page.connect('object-changed', self.object_changed)
self.pages[page.obj_type()] = page
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-add', self.person_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 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_object(handle)
def config_update(self, client, cnxn_id, entry, data):
for page in self.pages.values():
page.config_update()
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_object(person):
pass
else:
self.change_object(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_object(person):
pass
else:
self.change_object(None)
else:
self.dirty = True
def family_update(self, handle_list):
if self.active:
person = self.get_active()
if person:
while not self.change_object(person):
pass
else:
self.change_object(None)
else:
self.dirty = True
def family_add(self, handle_list):
if self.active:
person = self.get_active()
if person:
while not self.change_object(person):
pass
else:
self.change_object(None)
else:
self.dirty = True
def family_delete(self, handle_list):
if self.active:
person = self.get_active()
if person:
while not self.change_object(person):
pass
else:
self.change_object(None)
else:
self.dirty = True
def family_rebuild(self):
if self.active:
person = self.get_active()
if person:
while not self.change_object(person):
pass
else:
self.change_object(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.header = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.header.show()
self.stack = Gtk.Stack()
ss = Gtk.StackSwitcher()
ss.set_stack(self.stack)
self.stack.show()
ss.show()
container.set_spacing(6)
container.pack_start(self.header, False, False, 0)
container.pack_start(Gtk.Separator(), False, False, 0)
container.pack_start(ss, False, False, 0)
container.pack_start(self.stack, 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.AddParticipant</attribute>
<attribute name="label" translatable="yes">Add Participant...</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 default 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='RO'>
<object class="GtkToolButton" id="EditButton">
<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='Family'>
<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='Family'>
<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='Family'>
<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='ChangeOrder'>
<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>
<child groups='Event'>
<object class="GtkToolButton">
<property name="icon-name">gramps-parents-add</property>
<property name="action-name">win.AddParticipant</property>
<property name="tooltip_text" translatable="yes">'''
'''Add a new participant to the event</property>
<property name="label" translatable="yes">_Reorder</property>
<property name="use-underline">True</property>
</object>
<packing>
<property name="homogeneous">False</property>
</packing>
</child>
<child groups='Event'>
<object class="GtkToolButton">
<property name="icon-name">gramps-parents-open</property>
<property name="action-name">win.ShareParticipant</property>
<property name="tooltip_text" translatable="yes">'''
'''Add an existing participant to the event</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)
for page in self.pages.values():
page.define_actions(self)
self._add_action('Edit', self.edit_active, '<PRIMARY>Return')
self._add_action('FilterEdit', callback=self.filter_editor)
self._add_action('PRIMARY-J', self.jump, '<PRIMARY>J')
def filter_editor(self, *obj):
try:
FilterEditor('Person', CUSTOM_FILTERS,
self.dbstate, self.uistate)
except WindowActiveError:
return
def edit_active(self, *obj):
self.active_page.edit_active()
def change_db(self, db):
#reset the connects
self._change_db(db)
if self.active:
self.bookmarks.redraw()
self.history.clear()
self.redraw()
def redraw(self, *obj):
active_person = self.get_active()
if active_person:
self.change_object(active_person)
else:
self.change_object(None)
def object_changed(self, obj_type, handle):
self.change_active((obj_type, handle))
self.change_object((obj_type, handle))
def change_object(self, obj_tuple):
if obj_tuple is None:
return
if self.redrawing:
return False
self.redrawing = True
obj_type, handle, = obj_tuple
if obj_type == 'Person':
obj = self.dbstate.db.get_person_from_handle(handle)
elif obj_type == 'Event':
obj = self.dbstate.db.get_event_from_handle(handle)
for page in self.pages.values():
page.disable_actions(self.uimanager)
page = self.pages[obj_type]
page.enable_actions(self.uimanager, obj)
self.uimanager.update_menu()
edit_button = self.uimanager.get_widget("EditButton")
if edit_button:
if obj_type == 'Person':
tooltip = _('Edit the active person')
elif obj_type == 'Event':
tooltip = _('Edit the active event')
edit_button.set_tooltip_text(tooltip)
list(map(self.header.remove, self.header.get_children()))
list(map(self.stack.remove, self.stack.get_children()))
mbox = page.write_title(obj)
self.header.pack_start(mbox, False, True, 0)
page.write_stack(obj, self.stack)
self.redrawing = False
self.uistate.modify_statusbar(self.dbstate)
self.dirty = False
self.active_page = page
return True
def info_string(self, handle):
person = self.dbstate.db.get_person_from_handle(handle)
if not person:
return None
birth = get_birth_or_fallback(self.dbstate.db, person)
if birth and birth.get_type() != EventType.BIRTH:
sdate = get_date(birth)
if sdate:
bdate = "<i>%s</i>" % escape(sdate)
else:
bdate = ""
elif birth:
bdate = escape(get_date(birth))
else:
bdate = ""
death = get_death_or_fallback(self.dbstate.db, person)
if death and death.get_type() != EventType.DEATH:
sdate = get_date(death)
if sdate:
ddate = "<i>%s</i>" % escape(sdate)
else:
ddate = ""
elif death:
ddate = escape(get_date(death))
else:
ddate = ""
if bdate and ddate:
value = _("%(birthabbrev)s %(birthdate)s, %(deathabbrev)s %(deathdate)s") % {
'birthabbrev': birth.type.get_abbreviation(),
'deathabbrev': death.type.get_abbreviation(),
'birthdate' : bdate,
'deathdate' : ddate
}
elif bdate:
value = _("%(event)s %(date)s") % {'event': birth.type.get_abbreviation(), 'date': bdate}
elif ddate:
value = _("%(event)s %(date)s") % {'event': death.type.get_abbreviation(), 'date': ddate}
else:
value = ""
return value
def config_connect(self):
"""
Overwriten from :class:`~gui.views.pageview.PageView method
This method will be called after the ini file is initialized,
use it to monitor changes in the ini file
"""
self._config.connect("preferences.relation-shade",
self.config_update)
self._config.connect("preferences.releditbtn",
self.config_update)
self._config.connect("preferences.relation-display-theme",
self.config_update)
self._config.connect("preferences.family-siblings",
self.config_update)
self._config.connect("preferences.family-details",
self.config_update)
self._config.connect("preferences.show-tags",
self.config_update)
self._config.connect("preferences.vertical-details",
self.config_update)
config.connect("interface.toolbar-on",
self.config_update)
def config_panel(self, configdialog):
"""
Function that builds the widget in the configuration dialog
"""
grid = Gtk.Grid()
grid.set_border_width(12)
grid.set_column_spacing(6)
grid.set_row_spacing(6)
configdialog.add_checkbox(grid,
_('Use shading'),
0, 'preferences.relation-shade')
configdialog.add_checkbox(grid,
_('Display edit buttons'),
1, 'preferences.releditbtn')
configdialog.add_checkbox(grid,
_('Show Tags'),
2, 'preferences.show-tags')
checkbox = Gtk.CheckButton(label=_('View links as website links'))
theme = self._config.get('preferences.relation-display-theme')
checkbox.set_active(theme == 'WEBPAGE')
checkbox.connect('toggled', self._config_update_theme)
grid.attach(checkbox, 1, 3, 8, 1)
return _('Layout'), grid
def person_panel(self, configdialog):
"""
Function that builds the widget in the configuration dialog
"""
grid = Gtk.Grid()
grid.set_border_width(12)
grid.set_column_spacing(6)
grid.set_row_spacing(6)
grid.set_column_homogeneous(False)
configdialog.add_text(grid,
_('Relationships'),
0, bold=True)
configdialog.add_checkbox(grid,
_('Show Details'),
1, 'preferences.family-details')
configdialog.add_checkbox(grid,
_('Vertical Details'),
2, 'preferences.vertical-details')
configdialog.add_checkbox(grid,
_('Show Siblings'),
3, 'preferences.family-siblings')
return _('Person'), grid
def _config_update_theme(self, obj):
"""
callback from the theme checkbox
"""
if obj.get_active():
self.theme = 'WEBPAGE'
self._config.set('preferences.relation-display-theme',
'WEBPAGE')
else:
self.theme = 'CLASSIC'
self._config.set('preferences.relation-display-theme',
'CLASSIC')
def _get_configure_page_funcs(self):
"""
Return a list of functions that create gtk elements to use in the
notebook pages of the Configure dialog
:return: list of functions
"""
return [self.config_panel, self.person_panel]
def set_active(self):
"""
Called when the page is displayed.
"""
NavigationView.set_active(self)
self.uistate.viewmanager.tags.tag_enable(update_menu=False)
def set_inactive(self):
"""
Called when the page is no longer displayed.
"""
NavigationView.set_inactive(self)
self.uistate.viewmanager.tags.tag_disable()
def selected_handles(self):
return [self.get_active()[1]]
def add_tag(self, trans, object_handle, tag_handle):
"""
Add the given tag to the active object.
"""
self.active_page.add_tag(trans, object_handle, tag_handle)