forked from gramps-project/addons-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlines-of-descendency.py
183 lines (155 loc) · 6.92 KB
/
lines-of-descendency.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
#
# Lines of Descendency Report - a plugin for Gramps, the GTK+/GNOME based
# genealogy program.
#
# This program is released under the MIT License.
# Cf. http://www.opensource.org/licenses/mit-license.php.
#
# Copyright (c) 2010, 2012 lcc <lcc.mailaddress@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
from gramps.gen.const import GRAMPS_LOCALE as glocale
try:
_trans = glocale.get_addon_translator(__file__)
except ValueError:
_trans = glocale.translation
_ = _trans.gettext
from gramps.gen.plug.docgen import FontStyle, ParagraphStyle, FONT_SANS_SERIF, \
PARA_ALIGN_CENTER
from gramps.gen.plug.menu import PersonOption
from gramps.gen.lib import FamilyRelType
from gramps.gen.display.name import displayer as _nd
from gramps.gen.plug.report import Report
from gramps.gen.plug.report import CATEGORY_TEXT
from gramps.gen.plug.report import MenuReportOptions
import gramps.gen.plug.report.utils as ReportUtils
class LODOptions(MenuReportOptions):
def __init__(self, name, dbase):
MenuReportOptions.__init__(self, name, dbase)
def add_menu_options(self, menu):
category = _('People')
option = PersonOption(_('Ancestor'))
option.set_help(_('The ancestor from which to start the line'))
menu.add_option(category, 'ancestor', option)
pid = PersonOption(_('Descendent'))
pid.set_help(_('The descendent to which to build the line'))
menu.add_option(category, 'pid', pid)
def make_default_style(self, default_style):
font = FontStyle()
font.set(face=FONT_SANS_SERIF, size=16, bold=1)
para = ParagraphStyle()
para.set_font(font)
para.set_header_level(1)
para.set_top_margin(0.25)
para.set_bottom_margin(0.25)
para.set_alignment(PARA_ALIGN_CENTER)
para.set_description(_('The style used for the title of the page.'))
default_style.add_paragraph_style("LOD-Title", para)
font = FontStyle()
font.set(face=FONT_SANS_SERIF, size=15, bold=1)
para = ParagraphStyle()
para.set_font(font)
para.set(lmargin=1.5)
para.set_top_margin(0.25)
para.set_bottom_margin(0.25)
para.set_description(_('The style used for the title of a line.'))
default_style.add_paragraph_style("LOD-Line", para)
para = ParagraphStyle()
para.set(lmargin=1.5)
para.set_top_margin(0.25)
para.set_bottom_margin(0.25)
para.set_description(_('The basic style used for the text display.'))
default_style.add_paragraph_style("LOD-Entry", para)
class LinesOfDescendency(Report):
def __init__(self, database, options, user):
Report.__init__(self, database, options, user)
menu = options.menu
pid = menu.get_option_by_name('pid').get_value()
self.descendent = database.get_person_from_gramps_id(pid)
self.descendent_handle = self.descendent.get_handle()
ancestor = menu.get_option_by_name('ancestor').get_value()
self.ancestor = database.get_person_from_gramps_id(ancestor)
if (self.descendent == None) :
raise ReportError(_("Person %s is not in the Database") % pid )
def write_path(self, path):
gen = 1
handle = path[0]
next_person = self.database.get_person_from_handle(path[0])
self.doc.start_paragraph('LOD-Line')
self.doc.write_text(_('%(line)s. line:') % { 'line': self.line })
self.doc.end_paragraph()
self.line +=1
for next_handle in path[1:]:
person = next_person
next_person = self.database.get_person_from_handle(next_handle)
name = _nd.display(person)
family_handle = next_person.get_main_parents_family_handle()
family = self.database.get_family_from_handle(family_handle)
mother = family.get_mother_handle()
spouse_handle = \
mother if mother != handle \
else family.get_father_handle()
handle = next_handle
spouse = self.database.get_person_from_handle(spouse_handle)
if spouse:
spouse_name = _nd.display(spouse)
else:
spouse_name = 'N.N.'
if family.get_relationship() == FamilyRelType.MARRIED:
abbrev = 'm.'
else:
abbrev = 'rw.'
self.doc.start_paragraph("LOD-Entry")
self.doc.write_text("%(gen)s. %(person)s %(abbrev)s %(spouse)s" % {
'gen' : gen,
'person' : name,
'abbrev' : abbrev,
'spouse' : spouse_name
})
self.doc.end_paragraph()
gen += 1
self.doc.start_paragraph("LOD-Entry")
self.doc.write_text("%(gen)s. %(person)s" % {
'gen' : gen,
'person' : _nd.display(next_person)
})
self.doc.end_paragraph()
def traverse(self, person_handle, person_path=[], cur_gen=1):
if (not person_handle):
return
next_path = list(person_path)
next_path.append(person_handle)
if person_handle == self.descendent_handle:
self.write_path(next_path)
return
person = self.database.get_person_from_handle(person_handle)
index = 0
for family_handle in person.get_family_handle_list():
family = self.database.get_family_from_handle(family_handle)
for child_ref in family.get_child_ref_list():
self.traverse(child_ref.ref, next_path, cur_gen+1)
def write_report(self):
self.doc.start_paragraph("LOD-Title")
self.doc.write_text(_("Lines of Descendency from %(ancestor)s to"
" %(descendent)s") % { 'ancestor' : _nd.display(self.ancestor),
'descendent' : _nd.display(self.descendent) })
self.doc.end_paragraph()
self.line = 1
self.traverse(self.ancestor.get_handle())