def display(self): """ display the title box. """ #Set up the Table of Contents here if self.mark_text is None: mark = IndexMark(self.text, INDEX_TYPE_TOC, 1) else: mark = IndexMark(self.mark_text, INDEX_TYPE_TOC, 1) self.doc.center_text(self.boxstr, '', 0, -100, mark)
def write_report(self): self.apply_filter(self.center_person.get_handle(), 1) name = self._nd.display_name(self.center_person.get_primary_name()) if not name: name = self._("Unknown") self.doc.start_paragraph("DAR-Title") # feature request 2356: avoid genitive form title = self._("Ancestral Report for %s") % name mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.write_text(title, mark) self.doc.end_paragraph() generation = 0 for key in sorted(self.map): if generation == 0 or key >= 2**generation: if self.pgbrk and generation > 0: self.doc.page_break() self.doc.start_paragraph("DAR-Generation") text = self._("Generation %d") % (generation+1) mark = IndexMark(text, INDEX_TYPE_TOC, 2) self.doc.write_text(text, mark) self.doc.end_paragraph() generation += 1 if self.childref: self.prev_gen_handles = self.gen_handles.copy() self.gen_handles.clear() person_handle = self.map[key] person = self._db.get_person_from_handle(person_handle) self.gen_handles[person_handle] = key dupperson = self.write_person(key) if dupperson == 0: # Is this a duplicate ind record if self.listchildren or self.inc_events: for family_handle in person.get_family_handle_list(): family = self._db.get_family_from_handle(family_handle) mother_handle = family.get_mother_handle() if (mother_handle is None or mother_handle not in iter(self.map.values()) or person.get_gender() == Person.FEMALE): # The second test above also covers the 1. person's # mate, which is not an ancestor and as such is not # included in the self.map dictionary if self.listchildren: self.write_children(family) if self.inc_events: self.write_family_events(family) if self.inc_sources: if self.pgbrkenotes: self.doc.page_break() # it ignores language set for Note type (use locale) endnotes.write_endnotes(self.bibli, self._db, self.doc, printnotes=self.inc_srcnotes, elocale=self._locale)
def write_report(self): mark_text = _("Custom Text") if self.top_text[0]: mark_text = "%s (%s)" % (_("Custom Text"), self.top_text[0]) elif self.middle_text[0]: mark_text = "%s (%s)" % (_("Custom Text"), self.middle_text[0]) elif self.bottom_text[0]: mark_text = "%s (%s)" % (_("Custom Text"), self.bottom_text[0]) mark = IndexMark(mark_text, INDEX_TYPE_TOC, 1) self.doc.start_paragraph('CBT-Initial') for line in self.top_text: self.doc.write_text(line, mark) self.doc.write_text("\n") self.doc.end_paragraph() self.doc.start_paragraph('CBT-Middle') for line in self.middle_text: self.doc.write_text(line) self.doc.write_text("\n") self.doc.end_paragraph() self.doc.start_paragraph('CBT-Final') for line in self.bottom_text: self.doc.write_text(line) self.doc.write_text("\n") self.doc.end_paragraph()
def write_report(self): """ The routine that actually creates the report. At this point, the document is opened and ready for writing. """ pname = self._name_display.display(self.center_person) self.doc.start_paragraph("EOL-Title") # feature request 2356: avoid genitive form title = self._("End of Line Report for %s") % pname mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.write_text(title, mark) self.doc.end_paragraph() self.doc.start_paragraph("EOL-Subtitle") # feature request 2356: avoid genitive form title = self._( "All the ancestors of %s who are missing a parent") % pname self.doc.write_text(title) self.doc.end_paragraph() self.doc.start_table('EolTable', 'EOL-Table') for generation, handles in self.eol_map.items(): self.write_generation_row(generation) for person_handle, pedigrees in handles.items(): self.write_person_row(person_handle) list(map(self.write_pedigree_row, pedigrees)) self.doc.end_table()
def write_report(self): """ Generate the contents of the report """ mark = IndexMark(self._("Table Of Contents"), INDEX_TYPE_TOC, 1) self.doc.start_paragraph("TOC-Title") self.doc.write_text('', mark) self.doc.end_paragraph() self.doc.toc_title = self._('Contents') self.doc.insert_toc()
def write_report(self): """ Generate the contents of the report """ mark = IndexMark(self._("Alphabetical Index"), INDEX_TYPE_TOC, 1) self.doc.start_paragraph("IDX-Title") self.doc.write_text('', mark) self.doc.end_paragraph() self.doc.index_title = self._('Index') self.doc.insert_index()
def output_barchart(self, title1, typename, data, lookup): pt2cm = utils.pt2cm style_sheet = self.doc.get_style_sheet() pstyle = style_sheet.get_paragraph_style('SC-Text') font = pstyle.get_font() # set layout variables width = self.doc.get_usable_width() row_h = pt2cm(font.get_size()) max_y = self.doc.get_usable_height() - row_h pad = row_h * 0.5 # check maximum value max_value = max(data[k] for k in lookup) if lookup else 0 # horizontal area for the gfx bars margin = 1.0 middle = width / 2.0 textx = middle + margin / 2.0 stopx = middle - margin / 2.0 maxsize = stopx - margin # start output pstyle = style_sheet.get_paragraph_style('SC-Title') mark = IndexMark(title1, INDEX_TYPE_TOC, 2) self.doc.center_text('SC-title', title1, middle, 0, mark) yoffset = pt2cm(pstyle.get_font().get_size()) self.doc.center_text('SC-title', self.fil_name, middle, yoffset) yoffset = 2 * pt2cm(pstyle.get_font().get_size()) self.doc.center_text('SC-title', self.living_desc, middle, yoffset) yoffset = 3 * pt2cm(pstyle.get_font().get_size()) # header yoffset += (row_h + pad) text = self._("%s (persons):") % self._(typename) self.doc.draw_text('SC-text', text, textx, yoffset) for key in lookup: yoffset += (row_h + pad) if yoffset > max_y: # for graphical report, page_break() doesn't seem to work self.doc.end_page() self.doc.start_page() yoffset = 0 # right align bar to the text value = data[key] startx = stopx - (maxsize * value / max_value) self.doc.draw_box('SC-bar', "", startx, yoffset, stopx - startx, row_h) # text after bar text = "%s (%d)" % (self._(key), data[key]) self.doc.draw_text('SC-text', text, textx, yoffset) return
def display(self): """ display the title box. """ if self.page.y_page_num or self.boxstr == "None": return #Set up the Table of Contents here mark = IndexMark(self.text, INDEX_TYPE_TOC, 1) if self.text: self.doc.center_text(self.boxstr, self.text, self.width/2, self.y_cm, mark)
def write_people(self, title, people_handles): """ Write information about a group of people - including the title. """ cap_title = title[0].upper() + title[1:] subtitle = "%s (%d)" % (cap_title, len(people_handles)) self.doc.start_paragraph("KIN-Subtitle") mark = IndexMark(cap_title, INDEX_TYPE_TOC, 2) self.doc.write_text(subtitle, mark) self.doc.end_paragraph() list(map(self.write_person, people_handles))
def write_report(self): """ The short method that runs through each month and creates a page. """ # initialize the dict to fill: self.calendar = {} # get the information, first from holidays: if self.country != 0: self.__get_holidays() # get data from database: self.collect_data() # generate the report: self.doc.start_paragraph('BIR-Title') if self.titletext == _(_TITLE0): title = self._(_TITLE0) + ": " + str(self.year) else: title = str(self.titletext) + ": " + str(self.year) # FIXME those concatenated strings won't work for RTL languages mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.write_text(title, mark) self.doc.end_paragraph() if self.text1.strip() != "": self.doc.start_paragraph('BIR-Text1style') text1 = str(self.text1) if text1 == _(_TITLE1): text1 = self._(_TITLE1) self.doc.write_text(text1) self.doc.end_paragraph() if self.text2.strip() != "": self.doc.start_paragraph('BIR-Text2style') text2 = str(self.text2) if text2 == _(_TITLE2): text2 = self._(_TITLE2) self.doc.write_text(text2) self.doc.end_paragraph() if self.text3.strip() != "": self.doc.start_paragraph('BIR-Text3style') self.doc.write_text(str(self.text3)) self.doc.end_paragraph() if self.relationships: name = self.center_person.get_primary_name() self.doc.start_paragraph('BIR-Text3style') mark = utils.get_person_mark(self.database, self.center_person) # feature request 2356: avoid genitive form self.doc.write_text( self._("Relationships shown are to %s") % self._name_display.display_name(name), mark) self.doc.end_paragraph() with self._user.progress(_('Birthday and Anniversary Report'), _('Formatting months...'), 12) as step: for month in range(1, 13): step() self.print_page(month)
def write_report(self): self.doc.start_paragraph("DR-Title") name = self._name_display.display(self.center_person) # feature request 2356: avoid genitive form title = self._("Descendants of %s") % name mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.write_text(title, mark) self.doc.end_paragraph() recurse = RecurseDown(self.max_generations, self.database, self.obj_print, self._showdups, self._locale) recurse.recurse(1, self.center_person, None)
def write_report(self): """ Overridden function to generate the report. """ self.doc.start_paragraph("SR-Title") title = self._("Database Summary Report") mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.write_text(title, mark) self.doc.end_paragraph() self.summarize_people() self.summarize_families() self.summarize_media()
def write_report(self): """ The routine the actually creates the report. At this point, the document is opened and ready for writing. """ pname = self._name_display.display(self.person) self.doc.start_paragraph("KIN-Title") # feature request 2356: avoid genitive form title = self._("Kinship Report for %s") % pname mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.write_text(title, mark) self.doc.end_paragraph() if self.inc_spouses: spouse_handles = self.get_spouse_handles(self.person.get_handle()) if spouse_handles: self.write_people(self._("Spouses"), spouse_handles) # Collect all descendants of the person self.traverse_down(self.person.get_handle(), 0, 1) # Collect all ancestors/aunts/uncles/nephews/cousins of the person self.traverse_up(self.person.get_handle(), 1, 0) # Write Kin for Ga, Gbs in self.kinship_map.items(): for Gb in Gbs: # To understand these calculations, see: # http://en.wikipedia.org/wiki/Cousin#Mathematical_definitions _x_ = min(Ga, Gb) _y_ = abs(Ga - Gb) # Skip unrequested people if _x_ == 1 and _y_ > 0 and not self.inc_aunts: continue elif _x_ > 1 and not self.inc_cousins: continue get_rel_str = self.rel_calc.get_plural_relationship_string title = get_rel_str(Ga, Gb, in_law_b=False) self.write_people(self._(title), self.kinship_map[Ga][Gb]) if (self.inc_spouses and Ga in self.spouse_map and Gb in self.spouse_map[Ga]): title = get_rel_str(Ga, Gb, in_law_b=True) self.write_people(self._(title), self.spouse_map[Ga][Gb])
def dump_family(self, family_handle, generation): self.doc.start_paragraph('FGR-Title') if self.recursive and self.generations: title = self._("Family Group Report - Generation %d") % generation else: title = self._("Family Group Report") mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.write_text(title, mark) self.doc.end_paragraph() family = self.db.get_family_from_handle(family_handle) self.dump_parent(self._("Husband"), family.get_father_handle()) self.doc.start_paragraph("FGR-blank") self.doc.end_paragraph() if self.inc_par_mar: self.dump_marriage(family) self.doc.start_paragraph("FGR-blank") self.doc.end_paragraph() self.dump_parent(self._("Wife"), family.get_mother_handle()) length = len(family.get_child_ref_list()) if length > 0: self.doc.start_paragraph("FGR-blank") self.doc.end_paragraph() self.doc.start_table('FGR-Children', 'FGR-ChildTable') self.doc.start_row() self.doc.start_cell('FGR-ParentHead', 4) self.doc.start_paragraph('FGR-ParentName') self.doc.write_text(self._("Children")) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() index = 1 for child_ref in family.get_child_ref_list(): self.dump_child(index, child_ref.ref) index += 1 self.doc.end_table() if self.recursive: for child_ref in family.get_child_ref_list(): child = self.db.get_person_from_handle(child_ref.ref) for child_family_handle in child.get_family_handle_list(): if child_family_handle != family_handle: self.doc.page_break() self.dump_family(child_family_handle, (generation + 1))
def write_report(self): "output the selected statistics..." mark = IndexMark(self._('Statistics Charts'), INDEX_TYPE_TOC, 1) self._user.begin_progress(_('Statistics Charts'), _('Saving charts...'), len(self.data)) for data in sorted(self.data): self.doc.start_page() if mark: self.doc.draw_text('SC-title', '', 0, 0, mark) # put it in TOC mark = None # crock, but we only want one of them if len(data[3]) < self.bar_items: self.output_piechart(*data[:4]) else: self.output_barchart(*data[:4]) self.doc.end_page() self._user.step_progress() self._user.end_progress()
def write_report(self): """ The routine that actually creates the report. At this point, the document is opened and ready for writing. """ # Write the title line. Set in INDEX marker so that this section will be # identified as a major category if this is included in a Book report. title = self._("Place Report") mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.start_paragraph("PLC-ReportTitle") self.doc.write_text(title, mark) self.doc.end_paragraph() if self._lv != LivingProxyDb.MODE_INCLUDE_ALL: self.doc.start_paragraph("PLC-ReportSubtitle") self.doc.write_text(self.living_desc) self.doc.end_paragraph() self.__write_all_places()
def output_piechart(self, title1, typename, data, lookup): # set layout variables middle_w = self.doc.get_usable_width() / 2 middle_h = self.doc.get_usable_height() / 2 middle = min(middle_w, middle_h) # start output style_sheet = self.doc.get_style_sheet() pstyle = style_sheet.get_paragraph_style('SC-Title') mark = IndexMark(title1, INDEX_TYPE_TOC, 2) self.doc.center_text('SC-title', title1, middle_w, 0, mark) yoffset = utils.pt2cm(pstyle.get_font().get_size()) self.doc.center_text('SC-title', self.fil_name, middle_w, yoffset) yoffset = 2 * utils.pt2cm(pstyle.get_font().get_size()) self.doc.center_text('SC-title', self.living_desc, middle_w, yoffset) # collect data for output color = 0 chart_data = [] for key in lookup: style = "SC-color-%d" % color text = "%s (%d)" % (self._(key), data[key]) # graphics style, value, and it's label chart_data.append((style, data[key], text)) color = (color + 1) % 7 # There are only 7 color styles defined margin = 1.0 legendx = 2.0 # output data... radius = middle - 2 * margin yoffset += margin + radius draw_pie_chart(self.doc, middle_w, yoffset, radius, chart_data, -90) yoffset += radius + 2 * margin if middle == middle_h: # Landscape legendx = 1.0 yoffset = margin text = self._("%s (persons):") % self._(typename) draw_legend(self.doc, legendx, yoffset, chart_data, text, 'SC-legend')
def draw_title(self, toc): """ Draws the title for the page. """ width = self.doc.get_usable_width() title = "%(str1)s -- %(str2)s" % { 'str1': self._("Timeline Chart"), # feature request 2356: avoid genitive form 'str2': self._("Sorted by %s") % self.sort_name } title3 = self.living_desc mark = None if toc: mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.center_text('TLG-title', title, width / 2.0, 0, mark) style_sheet = self.doc.get_style_sheet() title_font = style_sheet.get_paragraph_style('TLG-Title').get_font() title_y = 1.2 - (utils.pt2cm(title_font.get_size()) * 1.2) self.doc.center_text('TLG-title', self.fil_name, width / 2.0, title_y) title_y = 1.8 - (utils.pt2cm(title_font.get_size()) * 1.2) self.doc.center_text('TLG-title', title3, width / 2.0, title_y)
def write_report(self): self.doc.start_paragraph("TR-Title") # feature request 2356: avoid genitive form title = self._("Tag Report for %s Items") % self.tag mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.write_text(title, mark) self.doc.end_paragraph() if self._lv != LivingProxyDb.MODE_INCLUDE_ALL: self.doc.start_paragraph("TR-ReportSubtitle") self.doc.write_text(self.living_desc) self.doc.end_paragraph() self.write_people() self.write_families() self.write_events() self.write_places() self.write_notes() self.write_media() self.write_repositories() self.write_sources() self.write_citations()
def write_report(self): """ Build the actual report. """ records = find_records(self.database, self.filter, self.top_size, self.callname, trans_text=self._, name_format=self._nf, living_mode=self._lv) self.doc.start_paragraph('REC-Title') title = self._("Records") mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.write_text(title, mark) self.doc.end_paragraph() self.doc.start_paragraph('REC-Subtitle') filter_name = self.filter.get_name(self._locale) self.doc.write_text("(%s)" % filter_name) self.doc.end_paragraph() if self._lv != LivingProxyDb.MODE_INCLUDE_ALL: self.doc.start_paragraph('REC-Subtitle') self.doc.write_text(self.living_desc) self.doc.end_paragraph() for (text, varname, top) in records: if not self.include[varname]: continue self.doc.start_paragraph('REC-Heading') self.doc.write_text(self._(text)) self.doc.end_paragraph() last_value = None rank = 0 for (number, (sort, value, name, handletype, handle)) in enumerate(top): mark = None if handletype == 'Person': person = self.database.get_person_from_handle(handle) mark = utils.get_person_mark(self.database, person) elif handletype == 'Family': family = self.database.get_family_from_handle(handle) # librecords.py checks that the family has both # a father and a mother and also that each one is # in the filter if any filter was used, so we don't # have to do any similar checking here, it's been done f_handle = family.get_father_handle() dad = self.database.get_person_from_handle(f_handle) f_mark = utils.get_person_mark(self.database, dad) m_handle = family.get_mother_handle() mom = self.database.get_person_from_handle(m_handle) m_mark = utils.get_person_mark(self.database, mom) else: raise ReportError( _("Option '%(opt_name)s' is present " "in %(file)s\n but is not known to " "the module. Ignoring...") % { 'opt_name': handletype, 'file': 'libnarrate.py' }) # since the error is very unlikely I reused the string if value != last_value: last_value = value rank = number self.doc.start_paragraph('REC-Normal') self.doc.write_text( self._("%(number)s. ") % {'number': rank + 1}) self.doc.write_markup(str(name), name.get_tags(), mark) if handletype == 'Family': self.doc.write_text('', f_mark) self.doc.write_text('', m_mark) if isinstance(value, Span): tvalue = value.get_repr(dlocale=self._locale) else: tvalue = value self.doc.write_text(" (%s)" % tvalue) self.doc.end_paragraph() self.doc.start_paragraph('REC-Footer') self.doc.write_text(self.footer) self.doc.end_paragraph()
def write_repositories(self): """ write the repositories associated with the tag """ rlist = self.database.get_repository_handles() filter_class = GenericFilterFactory('Repository') a_filter = filter_class() a_filter.add_rule(rules.repository.HasTag([self.tag])) repo_list = a_filter.apply(self.database, rlist) if not repo_list: return self.doc.start_paragraph("TR-Heading") header = self._("Repositories") mark = IndexMark(header, INDEX_TYPE_TOC, 2) self.doc.write_text(header, mark) self.doc.end_paragraph() self.doc.start_table('ReopTable', 'TR-Table') self.doc.start_row() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Id")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Name")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Type")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Email Address")) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() for repo_handle in repo_list: repo = self.database.get_repository_from_handle(repo_handle) self.doc.start_row() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(repo.get_gid()) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(repo.get_name()) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(str(repo.get_type())) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') home_page = '' for url in repo.get_url_list(): if url.get_type() == UrlType.EMAIL: home_page = url.get_path() break self.doc.write_text(home_page) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() self.doc.end_table()
def write_places(self): """ write the places associated with the tag """ plist = self.database.get_place_handles() filter_class = GenericFilterFactory('Place') a_filter = filter_class() a_filter.add_rule(rules.place.HasTag([self.tag])) place_list = a_filter.apply(self.database, plist) if not place_list: return self.doc.start_paragraph("TR-Heading") header = self._("Places") mark = IndexMark(header, INDEX_TYPE_TOC, 2) self.doc.write_text(header, mark) self.doc.end_paragraph() self.doc.start_table('PlaceTable', 'TR-Table') self.doc.start_row() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Id")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Title")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Name")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Type")) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() for place_handle in place_list: place = self.database.get_place_from_handle(place_handle) place_title = _pd.display(self.database, place) self.doc.start_row() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(place.get_gid()) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(place_title) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(place.get_name()) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(str(place.get_type())) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() self.doc.end_table()
def write_report(self): """ The routine that actually creates the report. At this point, the document is opened and ready for writing. """ sdb = SimpleAccess(self.database) self.doc.start_paragraph("NoteLink-Title") title = _("Note Link Check Report") mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.write_text(title, mark) self.doc.end_paragraph() self.doc.start_table('NoteLinkTable', 'NoteLink-Table') self.doc.start_row() self.doc.start_cell('NoteLink-TableCell') self.doc.start_paragraph('NoteLink-Normal-Bold') self.doc.write_text(_("Note ID")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('NoteLink-TableCell') self.doc.start_paragraph('NoteLink-Normal-Bold') self.doc.write_text(_("Link Type")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('NoteLink-TableCell') self.doc.start_paragraph('NoteLink-Normal-Bold') self.doc.write_text(_("Links To")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('NoteLink-TableCell') self.doc.start_paragraph('NoteLink-Normal-Bold') self.doc.write_text(_("Status")) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() for note in self.database.iter_notes(): for (ldomain, ltype, lprop, lvalue) in note.get_links(): if ldomain == "gramps": tagtype = _(ltype) ref_obj = sdb.get_link(ltype, lprop, lvalue) if ref_obj: tagvalue = sdb.describe(ref_obj) tagcheck = _("Ok") else: tagvalue = "%s://%s/%s/%s" % (ldomain, ltype, lprop, lvalue) tagcheck = _("Failed") else: tagtype = _("Internet") tagvalue = lvalue tagcheck = "" self.doc.start_row() self.doc.start_cell('NoteLink-TableCell') self.doc.start_paragraph('NoteLink-Normal') self.doc.write_text(note.gid) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('NoteLink-TableCell') self.doc.start_paragraph('NoteLink-Normal') self.doc.write_text(tagtype) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('NoteLink-TableCell') self.doc.start_paragraph('NoteLink-Normal') self.doc.write_text(tagvalue) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('NoteLink-TableCell') self.doc.start_paragraph('NoteLink-Normal') self.doc.write_text(tagcheck) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() self.doc.end_table()
def write_media(self): """ write the media associated with the tag """ mlist = self.database.get_media_handles(sort_handles=True) filter_class = GenericFilterFactory('Media') a_filter = filter_class() a_filter.add_rule(rules.media.HasTag([self.tag])) media_list = a_filter.apply(self.database, mlist) if not media_list: return self.doc.start_paragraph("TR-Heading") header = self._("Media") mark = IndexMark(header, INDEX_TYPE_TOC, 2) self.doc.write_text(header, mark) self.doc.end_paragraph() self.doc.start_table('MediaTable', 'TR-Table') self.doc.start_row() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Id")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Title")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Type")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Date")) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() for media_handle in media_list: media = self.database.get_media_from_handle(media_handle) self.doc.start_row() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(media.get_gid()) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') title = media.get_description() self.doc.write_text(str(title)) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') mime_type = media.get_mime_type() self.doc.write_text(str(mime_type)) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') date = self._get_date(media.get_date_object()) if date: self.doc.write_text(date) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() self.doc.end_table()
def write_notes(self): """ write the notes associated with the tag """ nlist = self.database.get_note_handles() filter_class = GenericFilterFactory('Note') a_filter = filter_class() a_filter.add_rule(rules.note.HasTag([self.tag])) note_list = a_filter.apply(self.database, nlist) if not note_list: return self.doc.start_paragraph("TR-Heading") header = self._("Notes") mark = IndexMark(header, 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(self._("Id")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Type")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell', 2) self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Text")) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() for note_handle in note_list: 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_gid()) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') note_type = note.get_type() self.doc.write_text(str(note_type)) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell', 2) self.doc.write_styled_note( note.get_styledtext(), note.get_format(), 'TR-Note', contains_html=((note.get_type() == NoteType.HTML_CODE))) self.doc.end_cell() self.doc.end_row() self.doc.end_table()
def write_sources(self): """ write the sources associated with the tag """ slist = self.database.get_source_handles(sort_handles=True) filter_class = GenericFilterFactory('Source') a_filter = filter_class() a_filter.add_rule(rules.source.HasTag([self.tag])) source_list = a_filter.apply(self.database, slist) if not source_list: return self.doc.start_paragraph("TR-Heading") header = self._("Source") mark = IndexMark(header, INDEX_TYPE_TOC, 2) self.doc.write_text(header, mark) self.doc.end_paragraph() self.doc.start_table('SourceTable', 'TR-Table') self.doc.start_row() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Id")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Title")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Author")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Publication Information")) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() for source_handle in source_list: source = self.database.get_source_from_handle(source_handle) self.doc.start_row() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(source.get_gid()) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(source.get_title()) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(source.get_author()) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(source.get_publication_info()) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() self.doc.end_table()
def write_citations(self): """ write the citations associated with the tag """ clist = self.database.get_citation_handles(sort_handles=True) filter_class = GenericFilterFactory('Citation') a_filter = filter_class() a_filter.add_rule(rules.citation.HasTag([self.tag])) citation_list = a_filter.apply(self.database, clist) if not citation_list: return self.doc.start_paragraph("TR-Heading") header = self._("Citations") mark = IndexMark(header, INDEX_TYPE_TOC, 2) self.doc.write_text(header, mark) self.doc.end_paragraph() self.doc.start_table('CitationTable', 'TR-Table') self.doc.start_row() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Id")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Volume/Page")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Date")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Source")) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() for citation_handle in citation_list: citation = self.database.get_citation_from_handle(citation_handle) self.doc.start_row() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(citation.get_gid()) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(citation.get_page()) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') date = self._get_date(citation.get_date_object()) if date: self.doc.write_text(date) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') source_handle = citation.get_reference_handle() source = self.database.get_source_from_handle(source_handle) self.doc.write_text(source.get_title()) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() self.doc.end_table()
def write_person(self, count): """ write a person """ if count != 0: self.doc.page_break() self.bibli = Bibliography( Bibliography.MODE_DATE|Bibliography.MODE_PAGE) title1 = self._("Complete Individual Report") text2 = self._name_display.display(self.person) mark1 = IndexMark(title1, INDEX_TYPE_TOC, 1) mark2 = IndexMark(text2, INDEX_TYPE_TOC, 2) self.doc.start_paragraph("IDS-Title") self.doc.write_text(title1, mark1) self.doc.end_paragraph() self.doc.start_paragraph("IDS-Title") self.doc.write_text(text2, mark2) self.doc.end_paragraph() self.doc.start_paragraph("IDS-Normal") self.doc.end_paragraph() name = self.person.get_primary_name() text = self.get_name(self.person) mark = utils.get_person_mark(self._db, self.person) endnotes = self._cite_endnote(self.person) endnotes = self._cite_endnote(name, prior=endnotes) family_handle = self.person.get_main_parents_family_handle() if family_handle: family = self._db.get_family_from_handle(family_handle) father_inst_id = family.get_father_handle() if father_inst_id: father_inst = self._db.get_person_from_handle( father_inst_id) father = self.get_name(father_inst) fmark = utils.get_person_mark(self._db, father_inst) else: father = "" fmark = None mother_inst_id = family.get_mother_handle() if mother_inst_id: mother_inst = self._db.get_person_from_handle(mother_inst_id) mother = self.get_name(mother_inst) mmark = utils.get_person_mark(self._db, mother_inst) else: mother = "" mmark = None else: father = "" fmark = None mother = "" mmark = None media_list = self.person.get_media_list() p_style = 'IDS-PersonTable2' self.mime0 = None if self.use_images and len(media_list) > 0: media0 = media_list[0] media_handle = media0.get_reference_handle() media = self._db.get_media_from_handle(media_handle) self.mime0 = media.get_mime_type() if self.mime0 and self.mime0.startswith("image"): image_filename = media_path_full(self._db, media.get_path()) if os.path.exists(image_filename): p_style = 'IDS-PersonTable' # this is tested for, also else: self._user.warn(_("Could not add photo to page"), # translators: for French, else ignore _("%(str1)s: %(str2)s" ) % {'str1' : image_filename, 'str2' : _('File does not exist')}) self.doc.start_table('person', p_style) self.doc.start_row() # translators: needed for French, ignore otherwise ignore = self._("%s:") self.doc.start_cell('IDS-NormalCell') self.write_paragraph(self._("%s:") % self._("Name")) self.write_paragraph(self._("%s:") % self._("Gender")) self.write_paragraph(self._("%s:") % self._("Father")) self.write_paragraph(self._("%s:") % self._("Mother")) self.doc.end_cell() self.doc.start_cell('IDS-NormalCell') self.write_paragraph(text, endnotes, mark) if self.person.get_gender() == Person.MALE: self.write_paragraph(self._("Male")) elif self.person.get_gender() == Person.FEMALE: self.write_paragraph(self._("Female")) else: self.write_paragraph(self._("Unknown")) self.write_paragraph(father, mark=fmark) self.write_paragraph(mother, mark=mmark) self.doc.end_cell() if p_style == 'IDS-PersonTable': self.doc.start_cell('IDS-NormalCell') self.doc.add_media(image_filename, "right", 4.0, 4.0, crop=media0.get_rectangle()) endnotes = self._cite_endnote(media0) attr_list = media0.get_attribute_list() if len(attr_list) == 0 or not self.use_attrs: text = _('(image)') else: for attr in attr_list: attr_type = attr.get_type().type2base() # translators: needed for French, ignore otherwise text = self._("%(str1)s: %(str2)s" ) % {'str1' : self._(attr_type), 'str2' : attr.get_value()} endnotes = self._cite_endnote(attr, prior=endnotes) self.write_paragraph("(%s)" % text, endnotes=endnotes, style='IDS-ImageNote') endnotes = '' if endnotes and len(attr_list) == 0: self.write_paragraph(text, endnotes=endnotes, style='IDS-ImageNote') self.doc.end_cell() self.doc.end_row() self.doc.end_table() self.doc.start_paragraph("IDS-Normal") self.doc.end_paragraph() self.write_alt_names() self.write_events() self.write_alt_parents() self.write_families() self.write_addresses() self.write_associations() self.write_attributes() self.write_LDS_ordinances() self.write_tags() self.write_images() self.write_note() if self.use_srcs: if self.use_pagebreak and self.bibli.get_citation_count(): self.doc.page_break() Endnotes.write_endnotes(self.bibli, self._db, self.doc, printnotes=self.use_src_notes, elocale=self._locale)
def write_events(self): """ write the events associated with the tag """ elist = self.database.get_event_handles() filter_class = GenericFilterFactory('Event') a_filter = filter_class() a_filter.add_rule(rules.event.HasTag([self.tag])) event_list = a_filter.apply(self.database, elist) if not event_list: return self.doc.start_paragraph("TR-Heading") header = self._("Events") mark = IndexMark(header, INDEX_TYPE_TOC, 2) self.doc.write_text(header, mark) self.doc.end_paragraph() self.doc.start_table('EventTable', 'TR-Table') self.doc.start_row() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Id")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Type")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Participants")) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal-Bold') self.doc.write_text(self._("Date")) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() for event_handle in event_list: event = self.database.get_event_from_handle(event_handle) self.doc.start_row() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(event.get_gid()) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text(self._(self._get_type(event.get_type()))) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') self.doc.write_text( get_participant_from_event(self.database, event_handle)) self.doc.end_paragraph() self.doc.end_cell() self.doc.start_cell('TR-TableCell') self.doc.start_paragraph('TR-Normal') date = self._get_date(event.get_date_object()) if date: self.doc.write_text(date) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() self.doc.end_table()
def print_page(self, month): """ This method actually writes the calendar page. """ style_sheet = self.doc.get_style_sheet() ptitle = style_sheet.get_paragraph_style("CAL-Title") ptext = style_sheet.get_paragraph_style("CAL-Text") pdaynames = style_sheet.get_paragraph_style("CAL-Daynames") pnumbers = style_sheet.get_paragraph_style("CAL-Numbers") numpos = pt2cm(pnumbers.get_font().get_size()) ptext1style = style_sheet.get_paragraph_style("CAL-Text1style") long_days = self._ldd.long_days self.doc.start_page() width = self.doc.get_usable_width() height = self.doc.get_usable_height() header = 2.54 # one inch mark = None if month == 1: mark = IndexMark(self._('Calendar Report'), INDEX_TYPE_TOC, 1) self.draw_rectangle("CAL-Border", 0, 0, width, height) self.doc.draw_box("CAL-Title", "", 0, 0, width, header, mark) self.doc.draw_line("CAL-Border", 0, header, width, header) year = self.year # TRANSLATORS: see # http://gramps-project.org/wiki/index.php?title=Translating_Gramps#Translating_dates # to learn how to select proper inflection for your language. title = self._("{long_month} {year}").format( long_month=self._ldd.long_months[month], year=year).capitalize() mark = IndexMark(title, INDEX_TYPE_TOC, 2) font_height = pt2cm(ptitle.get_font().get_size()) self.doc.center_text("CAL-Title", title, width / 2, font_height * 0.25, mark) cell_width = width / 7 cell_height = (height - header) / 6 current_date = datetime.date(year, month, 1) spacing = pt2cm(1.25 * ptext.get_font().get_size()) # 158 if current_date.isoweekday() != g2iso(self.start_dow + 1): # Go back to previous first day of week, and start from there current_ord = (current_date.toordinal() - ( (current_date.isoweekday() + 7) - g2iso(self.start_dow + 1)) % 7) else: current_ord = current_date.toordinal() for day_col in range(7): font_height = pt2cm(pdaynames.get_font().get_size()) self.doc.center_text( "CAL-Daynames", long_days[(day_col + g2iso(self.start_dow + 1)) % 7 + 1].capitalize(), day_col * cell_width + cell_width / 2, header - font_height * 1.5) for week_row in range(6): something_this_week = 0 for day_col in range(7): thisday = current_date.fromordinal(current_ord) if thisday.month == month: something_this_week = 1 self.draw_rectangle("CAL-Border", day_col * cell_width, header + week_row * cell_height, (day_col + 1) * cell_width, header + (week_row + 1) * cell_height) last_edge = (day_col + 1) * cell_width self.doc.center_text("CAL-Numbers", str(thisday.day), day_col * cell_width + cell_width / 2, header + week_row * cell_height) list_ = self.calendar.get(month, {}).get(thisday.day, []) list_.sort() # to get CAL-Holiday on bottom position = spacing for (format, p, m_list) in list_: for line in reversed(p.split("\n")): # make sure text will fit: if position - 0.1 >= cell_height - numpos: # font daynums break font = ptext.get_font() line = string_trim(font, line, cm2pt(cell_width + 0.2)) self.doc.draw_text( format, line, day_col * cell_width + 0.1, header + (week_row + 1) * cell_height - position - 0.1, m_list[0]) if len(m_list) > 1: # index the spouse too self.doc.draw_text(format, "", 0, 0, m_list[1]) position += spacing current_ord += 1 if not something_this_week: last_edge = 0 font_height = pt2cm(1.5 * ptext1style.get_font().get_size()) x = last_edge + (width - last_edge) / 2 text1 = str(self.text1) if text1 == _(_TITLE1): text1 = self._(_TITLE1) self.doc.center_text("CAL-Text1style", text1, x, height - font_height * 3) text2 = str(self.text2) if text2 == _(_TITLE2): text2 = self._(_TITLE2) self.doc.center_text("CAL-Text2style", text2, x, height - font_height * 2) self.doc.center_text("CAL-Text3style", self.text3, x, height - font_height * 1) self.doc.end_page()