~ubuntu-branches/ubuntu/utopic/gramps/utopic

« back to all changes in this revision

Viewing changes to src/plugins/textreport/DetAncestralReport.py

  • Committer: Package Import Robot
  • Author(s): James A. Treacy
  • Date: 2012-05-22 17:18:36 UTC
  • mfrom: (39.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20120522171836-35fi62lp4w7jnrd7
Tags: 3.4.0-1
* New upstream version
* Updated desktop file. Closes: #667472

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
# Copyright (C) 2009      Benny Malengier <benny.malengier@gramps-project.org>
9
9
# Copyright (C) 2010      Jakim Friant
10
10
# Copyright (C) 2010      Vlada Peri\u0107
 
11
# Copyright (C) 2011       Tim G L Lyons
11
12
#
12
13
# This program is free software; you can redistribute it and/or modify
13
14
# it under the terms of the GNU General Public License as published by
24
25
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
26
#
26
27
 
27
 
# $Id: DetAncestralReport.py 17729 2011-06-09 13:33:49Z ldnp $
 
28
# $Id: DetAncestralReport.py 18915 2012-02-17 16:51:40Z romjerome $
28
29
 
29
30
"""Reports/Text Reports/Detailed Ancestral Report"""
30
31
 
33
34
# standard python modules
34
35
#
35
36
#------------------------------------------------------------------------
 
37
import copy
36
38
from gen.ggettext import gettext as _
37
39
 
38
40
#------------------------------------------------------------------------
40
42
# GRAMPS modules
41
43
#
42
44
#------------------------------------------------------------------------
43
 
from gen.display.name import displayer as _nd
 
45
from gen.display.name import displayer as global_name_display
44
46
from Errors import ReportError
45
47
from gen.lib import EventType, FamilyRelType, Person, NoteType
46
48
from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle,
50
52
from gen.plug.report import ( Report, Bibliography )
51
53
from gen.plug.report import endnotes
52
54
from gen.plug.report import utils as ReportUtils
53
 
from gui.plug.report import MenuReportOptions
 
55
from gen.plug.report import MenuReportOptions
54
56
                        
55
57
import DateHandler
56
58
 
72
74
#------------------------------------------------------------------------
73
75
class DetAncestorReport(Report):
74
76
 
75
 
    def __init__(self, database, options_class):
 
77
    def __init__(self, database, options, user):
76
78
        """
77
79
        Create the DetAncestorReport object that produces the report.
78
80
        
79
81
        The arguments are:
80
82
 
81
83
        database        - the GRAMPS database instance
82
 
        person          - currently selected person
83
 
        options_class   - instance of the Options class for this report
 
84
        options         - instance of the Options class for this report
 
85
        user            - a gen.user.User() instance
84
86
 
85
87
        This report needs the following parameters (class variables)
86
88
        that come in the options class.
101
103
        childref      - Whether to add descendant references in child list.
102
104
        addimages     - Whether to include images.
103
105
        pid           - The Gramps ID of the center person for the report.
 
106
        name_format   - Preferred format to display names
104
107
        """
105
 
        Report.__init__(self, database, options_class)
 
108
        Report.__init__(self, database, options, user)
106
109
 
107
110
        self.map = {}
 
111
        self._user = user
108
112
 
109
 
        menu = options_class.menu
 
113
        menu = options.menu
110
114
        get_option_by_name = menu.get_option_by_name
111
115
        get_value = lambda name: get_option_by_name(name).get_value()
112
116
 
136
140
        if (self.center_person == None) :
137
141
            raise ReportError(_("Person %s is not in the Database") % pid )
138
142
 
 
143
        # Copy the global NameDisplay so that we don't change application 
 
144
        # defaults.
 
145
        self._name_display = copy.deepcopy(global_name_display)
 
146
            
 
147
        name_format = menu.get_option_by_name("name_format").get_value()
 
148
        if name_format != 0:
 
149
            self._name_display.set_default_format(name_format)
 
150
 
139
151
        self.gen_handles = {}
140
152
        self.prev_gen_handles = {}
141
153
        
179
191
    def write_report(self):
180
192
        self.apply_filter(self.center_person.get_handle(), 1)
181
193
 
182
 
        name = _nd.display_name(self.center_person.get_primary_name())
 
194
        name = self._name_display.display_name(self.center_person.get_primary_name())
183
195
        self.doc.start_paragraph("DAR-Title")
 
196
        # feature request 2356: avoid genitive form
184
197
        title = self._("Ancestral Report for %s") % name
185
198
        mark = IndexMark(title, INDEX_TYPE_TOC, 1)
186
199
        self.doc.write_text(title, mark)
238
251
        
239
252
        if self.addimages and len(plist) > 0:
240
253
            photo = plist[0]
241
 
            ReportUtils.insert_image(self.database, self.doc, photo)
 
254
            ReportUtils.insert_image(self.database, self.doc, photo, self._user)
242
255
 
243
256
        self.doc.start_paragraph("DAR-First-Entry","%s." % str(key))
244
257
 
245
 
        name = _nd.display_formal(person)
 
258
        name = self._name_display.display_formal(person)
246
259
        mark = ReportUtils.get_person_mark(self.database, person)
247
260
 
248
261
        self.doc.start_bold()
301
314
        notelist = person.get_note_list()
302
315
        if len(notelist) > 0 and self.includenotes:
303
316
            self.doc.start_paragraph("DAR-NoteHeader")
 
317
            # feature request 2356: avoid genitive form
304
318
            self.doc.write_text(self._("Notes for %s") % name)
305
319
            self.doc.end_paragraph()
306
320
            for notehandle in notelist:
341
355
                if first:
342
356
                    self.doc.start_paragraph('DAR-MoreHeader')
343
357
                    self.doc.write_text(self._('More about %(person_name)s:') % { 
344
 
                        'person_name' : _nd.display(person) })
 
358
                        'person_name' : self._name_display.display(person) })
345
359
                    self.doc.end_paragraph()
346
360
                    first = 0
347
361
                    
471
485
            father_handle = family.get_father_handle()
472
486
            if mother_handle:
473
487
                mother = self.database.get_person_from_handle(mother_handle)
474
 
                mother_name = _nd.display_name(mother.get_primary_name())
 
488
                mother_name = \
 
489
                    self._name_display.display_name(mother.get_primary_name())
475
490
                mother_mark = ReportUtils.get_person_mark(self.database, mother)
476
491
            else:
477
492
                mother_name = ""
478
493
                mother_mark = ""
479
494
            if father_handle:
480
495
                father = self.database.get_person_from_handle(father_handle)
481
 
                father_name = _nd.display_name(father.get_primary_name())
 
496
                father_name = \
 
497
                    self._name_display.display_name(father.get_primary_name())
482
498
                father_mark = ReportUtils.get_person_mark(self.database, father)
483
499
            else:
484
500
                father_name = ""
501
517
            family = self.database.get_family_from_handle(family_handle)
502
518
            spouse_handle = ReportUtils.find_spouse(person,family)
503
519
            spouse = self.database.get_person_from_handle(spouse_handle)
 
520
            if spouse:
 
521
                name = self._name_display.display_formal(spouse)
 
522
            else:
 
523
                name = ""
504
524
            text = ""
505
525
            spouse_mark = ReportUtils.get_person_mark(self.database, spouse)
506
526
            
507
 
            text = self.__narrator.get_married_string(family, is_first)
 
527
            text = self.__narrator.get_married_string(family, is_first, self._name_display)
508
528
 
509
529
            if text:
510
530
                self.doc.write_text_citation(text, spouse_mark)
520
540
        mother_handle = family.get_mother_handle()
521
541
        if mother_handle:
522
542
            mother = self.database.get_person_from_handle(mother_handle)
523
 
            mother_name = _nd.display(mother)
 
543
            mother_name = self._name_display.display(mother)
524
544
        else:
525
545
            mother_name = self._("unknown")
526
546
 
527
547
        father_handle = family.get_father_handle()
528
548
        if father_handle:
529
549
            father = self.database.get_person_from_handle(father_handle)
530
 
            father_name = _nd.display(father)
 
550
            father_name = self._name_display.display(father)
531
551
        else:
532
552
            father_name = self._("unknown")
533
553
 
542
562
        for child_ref in family.get_child_ref_list():
543
563
            child_handle = child_ref.ref
544
564
            child = self.database.get_person_from_handle(child_handle)
545
 
            child_name = _nd.display(child)
 
565
            child_name = self._name_display.display(child)
546
566
            child_mark = ReportUtils.get_person_mark(self.database, child)
547
567
 
548
568
            if self.childref and self.prev_gen_handles.get(child_handle):
570
590
        mother_handle = family.get_mother_handle()
571
591
        if mother_handle:
572
592
            mother = self.database.get_person_from_handle(mother_handle)
573
 
            mother_name = _nd.display(mother)
 
593
            mother_name = self._name_display.display(mother)
574
594
        else:
575
595
            mother_name = self._("unknown")
576
596
 
577
597
        father_handle = family.get_father_handle()
578
598
        if father_handle:
579
599
            father = self.database.get_person_from_handle(father_handle)
580
 
            father_name = _nd.display(father)
 
600
            father_name = self._name_display.display(father)
581
601
        else:
582
602
            father_name = self._("unknown")
583
603
 
632
652
                
633
653
                if self.addimages and len(plist) > 0:
634
654
                    photo = plist[0]
635
 
                    ReportUtils.insert_image(self.database, self.doc, photo)
 
655
                    ReportUtils.insert_image(self.database, self.doc, 
 
656
                                             photo, self._user)
636
657
        
637
 
                name = _nd.display_formal(ind)
 
658
                name = self._name_display.display_formal(ind)
638
659
                mark = ReportUtils.get_person_mark(self.database, ind)
639
660
        
640
661
                if family.get_relationship() == FamilyRelType.MARRIED:
678
699
        if not obj or not self.inc_sources:
679
700
            return ""
680
701
        
681
 
        txt = endnotes.cite_source(self.bibli, obj)
 
702
        txt = endnotes.cite_source(self.bibli, self.database, obj)
682
703
        if txt:
683
704
            txt = '<super>' + txt + '</super>'
684
705
        return txt
707
728
        pid = PersonOption(_("Center Person"))
708
729
        pid.set_help(_("The center person for the report"))
709
730
        addopt("pid", pid)
 
731
 
 
732
        # We must figure out the value of the first option before we can
 
733
        # create the EnumeratedListOption
 
734
        fmt_list = global_name_display.get_name_format()
 
735
        name_format = EnumeratedListOption(_("Name format"), 0)
 
736
        name_format.add_item(0, _("Default"))
 
737
        for num, name, fmt_str, act in fmt_list:
 
738
            name_format.add_item(num, name)
 
739
        name_format.set_help(_("Select the format to display names"))
 
740
        addopt("name_format", name_format)
710
741
        
711
742
        gen = NumberOption(_("Generations"),10,1,100)
712
743
        gen.set_help(_("The number of generations to include in the report"))