Ejemplo n.º 1
0
    def write_report(self):
        """
        Build the actual report.
        """

        mark1 = docgen.IndexMark(_('Family Sheet'), docgen.INDEX_TYPE_TOC, 1)
        self.doc.start_paragraph('FSR-Key')
        self.doc.write_text('', mark1)  # for use in a TOC in a book report
        self.doc.end_paragraph()

        person = self.database.get_person_from_gramps_id(self.person_id)
        (rank, ahnentafel, person_key) = self.__calc_person_key(person)
        self.__process_person(person, rank, ahnentafel, person_key)
Ejemplo n.º 2
0
    def write_report(self):
        """
        Generate the report document
        """
        self.doc.start_paragraph("TR-Title")
        title = _("Report on Notes Tagged %s") % self.tag
        mark = docgen.IndexMark(title, docgen.INDEX_TYPE_TOC, 1)
        self.doc.write_text(title, mark)
        self.doc.end_paragraph()

        # get all the notes in the database tagged Todo
        nlist = self.database.get_note_handles()
        FilterClass = GenericFilterFactory('Note')
        my_filter = FilterClass()
        my_filter.add_rule(rules.note.HasTag([self.tag]))
        note_list = my_filter.apply(self.database, nlist)

        if self.can_group:
            self._write_grouped_notes(note_list)
        else:
            self._write_sorted_notes(note_list)
Ejemplo n.º 3
0
    def _write_notes(self, note_list, title=None):
        """
        Generate a table for the list of notes
        """
        if not note_list:
            return

        if title is not None:
            self.doc.start_paragraph("TR-Heading")
            header = _(title)
            mark = docgen.IndexMark(header, docgen.INDEX_TYPE_TOC, 2)
            self.doc.write_text(header, mark)
            self.doc.end_paragraph()

        self.doc.start_table('NoteTable', 'TR-Table')

        self.doc.start_row()

        self.doc.start_cell('TR-TableCell')
        self.doc.start_paragraph('TR-Normal-Bold')
        self.doc.write_text(_("Id"))
        self.doc.end_paragraph()
        self.doc.end_cell()

        self.doc.start_cell('TR-TableCell', 3)
        self.doc.start_paragraph('TR-Normal-Bold')
        self.doc.write_text(_("Text"))
        self.doc.end_paragraph()
        self.doc.end_cell()

        self.doc.end_row()

        for handles in note_list:
            note_handle = handles[_NOTE_HANDLE_POS]
            note = self.database.get_note_from_handle(note_handle)

            self.doc.start_row()

            self.doc.start_cell('TR-TableCell')
            self.doc.start_paragraph('TR-Normal')
            self.doc.write_text(note.get_gramps_id())
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell('TR-TableCell', 3)
            self.doc.write_styled_note(note.get_styledtext(),
                                       note.get_format(), 'TR-Note')
            self.doc.end_cell()

            self.doc.end_row()

            self._write_references(note_handle)

            self.doc.start_row()

            self.doc.start_cell('TR-BorderCell', 4)
            self.doc.start_paragraph('TR-Normal')
            self.doc.write_text('')
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.end_row()

        self.doc.end_table()
Ejemplo n.º 4
0
    def __process_person(self, person, rank, ahnentafel, person_key):
        """
        Recursively build the Family Sheet for this person and all children
        with spouses.

        @param person: Person object for the key person of the Family Sheet.
        @param rank: Numerical distance between the central person in the
            database and the person in the parameter (the number of births
            needed to connect them).
        @param ahnentafel: "Ahnentafel" number of the common ancestor of the
            central person in the database and the person in the parameter,
            seen from the side of the central person in the database.
        @param person_key: Family Sheet key to be printed on the top right of
            the corner.
        """

        # List of (person, rank, ahnentafel, person_key) tuples for persons to
        # process recursively after this one.
        more_sheets = []

        # Numbering of spouses (integer, but printed in roman numbers).
        spouse_index = 0

        # Numbering of children (integer, but printed as lowercase letters).
        child_index = 0

        # Source references to print as footnotes.
        self.__citation_index = 0
        self.__citations = []

        # Notes to print as footnotes.
        self.__note_index = 0
        self.__notes = []

        # --- Now let the party begin! ---

        head_name = str(
            _Name_get_styled(person.get_primary_name(),
                             _Name_CALLNAME_DONTUSE))
        mark2 = docgen.IndexMark(head_name, docgen.INDEX_TYPE_TOC, 2)

        self.doc.start_paragraph('FSR-Key')
        self.doc.write_text(person_key, mark2)
        self.doc.end_paragraph()

        self.doc.start_table(None, 'FSR-Table')

        # Main person
        self.doc.start_row()
        self.doc.start_cell('FSR-HeadCell', 3)
        self.__dump_person(person, False, None)
        self.doc.end_cell()
        self.doc.end_row()

        # Spouses
        for family_handle in person.get_family_handle_list():
            family = self.database.get_family_from_handle(family_handle)

            spouse_index += 1

            spouse_handle = utils.find_spouse(person, family)
            if spouse_handle:
                spouse = self.database.get_person_from_handle(spouse_handle)
            else:
                spouse = None

            # Determine relationship between the center person and the spouse.
            # If the spouse has a closer blood relationship than the current
            # person, we refer to the Family Sheet of the spouse instead of
            # printing the child list, because all children are more closely
            # related to the center person via the spouse than via the current
            # person. The same happens if the relationship is on the same
            # level, but the relationship via the spouse goes via a common
            # ancestor with a lower Ahnentafel numbering (i.e. a relationship
            # stronger father-sided). In these cases, refer_spouse will be set
            # to True.
            (spouse_rank, spouse_at, spouse_key) = \
                    self.__calc_person_key(spouse)
            if self.recurse != FamilySheetOptions.RECURSE_ALL:
                refer_spouse = (spouse_rank != -1 and \
                        (spouse_rank < rank or
                            (spouse_rank == rank and spouse_at < ahnentafel)))
            else:
                refer_spouse = False

            self.doc.start_row()

            self.doc.start_cell('FSR-NumberCell', 1)
            self.doc.start_paragraph('FSR-Number')
            self.doc.write_text(utils.roman(spouse_index))
            self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.start_cell('FSR-DataCell', 2)
            self.__dump_family(family, spouse)
            if refer_spouse:
                self.doc.start_paragraph('FSR-Normal')
                self.doc.write_text(_("\u2192 %s") % spouse_key)
                self.doc.end_paragraph()
            self.doc.end_cell()

            self.doc.end_row()

            if refer_spouse:
                # Spouse with closer relationship than current person? Don't
                # print children on this Family Sheet (but count them for the
                # numbering).
                child_index += len(family.get_child_ref_list())
                continue

            # Children
            for child_ref in family.get_child_ref_list():
                child = self.database.get_person_from_handle(child_ref.ref)
                child_letter = string.ascii_lowercase[child_index]

                self.doc.start_row()

                self.doc.start_cell('FSR-EmptyCell', 1)
                self.doc.end_cell()

                self.doc.start_cell('FSR-NumberCell', 1)
                self.doc.start_paragraph('FSR-Number')
                self.doc.write_text(child_letter)
                self.doc.end_paragraph()
                self.doc.end_cell()

                self.doc.start_cell('FSR-DataCell', 1)

                has_spouses = (child.get_family_handle_list() != [])

                self.__dump_person(child, has_spouses, child_ref)

                if has_spouses:
                    # We have to recalculate the key for this person, it could
                    # be closer related if it is a direct ancestor of the
                    # central person or one of its spouses.
                    (child_rank, child_at, child_key) = \
                            self.__calc_person_key(child)

                    self.doc.start_paragraph('FSR-Normal')
                    self.doc.write_text(_("\u2192 %s") % child_key)
                    self.doc.end_paragraph()

                    # We recursively print this child *only* if its
                    # relationship with the central person is closest via the
                    # current person. This way, we avoid that a person is
                    # printed recursively from more than one of its ancestors.
                    if child_key == person_key + child_letter or \
                            self.recurse == FamilySheetOptions.RECURSE_ALL:
                        more_sheets.append(
                            (child, child_rank, child_at, child_key))

                self.doc.end_cell()

                self.doc.end_row()

                child_index += 1

        self.doc.start_row()
        self.doc.start_cell('FSR-FootCell', 3)
        self.doc.end_cell()
        self.doc.end_row()

        self.doc.end_table()

        self.__dump_sources()
        self.__dump_notes()

        # Now print the sheets for the children.
        if self.recurse != FamilySheetOptions.RECURSE_NONE:
            for (child, child_rank, child_at, child_key) in more_sheets:
                self.doc.page_break()
                self.__process_person(child, child_rank, child_at, child_key)
Ejemplo n.º 5
0
    def write_report(self):
        """
        Build the actual report.
        """

        mark1 = docgen.IndexMark(_('Family Book'), docgen.INDEX_TYPE_TOC, 1)
        self.doc.start_paragraph('FSR-Key')
        self.doc.write_text('', mark1) # for use in a TOC in a book report
        self.doc.end_paragraph()

        self.doc.start_paragraph('FSR-Normal')
        self.doc.write_text('\\documentclass[11pt, msmallroyalvopaper, openany]{')
        self.doc.write_text(self.document_class)
        self.doc.write_text('}\n')
        self.doc.write_text('\\usepackage[utf8]{inputenc}\n')
        self.doc.write_text('\\usepackage[')
        self.doc.write_text(self.language)
        self.doc.write_text(']{babel}\n')
        self.doc.write_text('\\usepackage{caption}\n')
        self.doc.write_text('\\usepackage{graphicx}\n')
        self.doc.write_text('\\usepackage{wrapfig}\n')
        self.doc.write_text('\\usepackage{multicol}\n')
        self.doc.write_text('\\usepackage[superscript,biblabel]{cite}\n')
        self.doc.write_text('\\setcounter{secnumdepth}{-1}\n')
        
        self.doc.write_text('\n% styling\n')
        self.doc.write_text('\\tightlists\n')
        self.doc.write_text('\\usepackage{calc}\n')
        self.doc.write_text('\\usepackage{enumitem}\n')
        self.doc.write_text('\\usepackage{pgfornament}\n')
        self.doc.write_text('\\chapterstyle{bringhurst}\n')
        self.doc.write_text('\\definecolor{steelgrey}{rgb}{0.62, 0.62, 0.62}\n')
        self.doc.write_text('\\newcommand*{\\sclabel}[1]{\\normalfont\\scshape #1}\n')
        self.doc.write_text('\\newcommand{\\fbNoteSeparator}{\\begin{center}\\noindent\\pgfornament[width=2em,color=steelgrey]{94}\\medskip\end{center}}\n')
        self.doc.write_text('\\newcommand{\\fbBeginPersonDescription}{\\begin{description}[before=\\renewcommand{\\makelabel}{\\sclabel},leftmargin=!,labelwidth=\\widthof{\\sclabel{Похоронена}}]}\n')
        self.doc.write_text('\\newcommand{\\fbEndPersonDescription}{\\end{description}}\n')
#        self.doc.write_text('\\newcommand{\\fbBeginPersonDescription}{\\begin{flexlabelled}{sclabel}{2em}{1.0em}{1.0em}{2em}{0pt}}\n')
#        self.doc.write_text('\\newcommand{\\fbEndPersonDescription}{\\end{flexlabelled}}\n')
        self.doc.write_text('\\newcommand{\\fbPersonDescriptionItem}[2]{\\item[#1] #2}\n')
        self.doc.write_text('% end of styling\n\n')
        
        self.doc.write_text('\\begin{document}\n')
        self.doc.write_text('\\tableofcontents\n')
        self.doc.write_text('\\part{Персоналии}\n')
        self.doc.end_paragraph()

        self._build_obj_dict()

#        person = self.database.get_person_from_gramps_id(self.person_id)
#        (rank, ahnentafel, person_key) = self.__calc_person_key(person)
#        self.__process_person(person)

        person_list = list(self.obj_dict[Person].keys())
        person_list.sort(key = lambda x: self.obj_dict[Person][x][0])
        for person_handle in person_list:
            person = self.database.get_person_from_handle(person_handle)
            self.__process_person(person)

        self.doc.start_paragraph('FSR-Normal')
        self.doc.write_text('\\part{Места}\n')
        self.doc.end_paragraph()
            
        self.doc.start_paragraph('FSR-Normal')
        self.doc.write_text('\\begin{thebibliography}{99}\n')
        self.doc.write_text('\\scriptsize\n')
        for cit_handle in self.citation_handles:
            self.doc.write_text(self.__make_bib_item(cit_handle))
        self.doc.write_text('\\end{thebibliography}\n')
        self.doc.write_text('\\end{document}\n')
        self.doc.end_paragraph()