def __init__(self, dbstate, uistate=None): self.dbstate = dbstate self.uistate = uistate self._text_cache = {} self._markup_cache = {} self.symbols = Symbols() self.reload_symbols()
def out_person_html(self, pid, html): """ draws a box including most important data of a person """ symbols = Symbols() birth_sym = symbols.get_symbol_for_html(symbols.SYMBOL_BIRTH) marr_sym = symbols.get_symbol_for_html(symbols.SYMBOL_MARRIAGE) death_sym = symbols.get_death_symbol_for_html(symbols.DEATH_SYMBOL_SHADOWED_LATIN_CROSS) if self.pid_list[pid]["gender"] == Person.MALE: box_class = "box personbox_m" else: box_class = "box personbox_w" html += ( "<div class='" + box_class + "' id='" + pid + "' style='left:" + str(self.pid_list[pid]["x"]) + "px;top:" + str(self.pid_list[pid]["y"]) + "px;'>\n" + "<b>" + self.pid_list[pid]["firstname"] + "</b>\n" + "<br><b>" + self.pid_list[pid]["name"] + "</b>\n" + "<br>" + birth_sym + " " + self.pid_list[pid]["birthday"] + " " + self.pid_list[pid]["birthplace"] + "\n" ) if self.pid_list[pid]["deathday"]: html += ( "<br>" + death_sym + " " + self.pid_list[pid]["deathday"] + " " + self.pid_list[pid]["deathplace"] + "\n" ) if pid in self.pair_list: for partner_id in self.pair_list[pid]: html += "<hr>" if self.pid_list[pid]["marr"][partner_id]: if ( self.pid_list[pid]["marr"][partner_id][0] != "" or self.pid_list[pid]["marr"][partner_id][1] != "" ): html += ( "<font size=+1>" + marr_sym + "</font> " + self.pid_list[pid]["marr"][partner_id][0] + " " + self.pid_list[pid]["marr"][partner_id][1] + "<br>" ) html += ( "<b>" + self.pid_list[partner_id]["firstname"] + " " + self.pid_list[partner_id]["name"] + "</b>\n" + "<br>" + birth_sym + " " + self.pid_list[partner_id]["birthday"] + " " + self.pid_list[partner_id]["birthplace"] + "\n" ) if self.pid_list[partner_id]["deathday"]: html += ( "<br>" + death_sym + " " + self.pid_list[partner_id]["deathday"] + " " + self.pid_list[partner_id]["deathplace"] + "\n" ) if self.show_id: html += ( "<div style='position:absolute;top:-12px;right:0px;'>" + pid + "</div>" ) html += "</div>\n" return html
def reload_symbols(self): self.symbols = Symbols() self.clear_cache() if self.uistate and self.uistate.symbols: death_idx = self.uistate.death_symbol gsfs = self.symbols.get_symbol_for_string self.male = gsfs(self.symbols.SYMBOL_MALE) self.female = gsfs(self.symbols.SYMBOL_FEMALE) self.bth = gsfs(self.symbols.SYMBOL_BIRTH) self.marr = gsfs(self.symbols.SYMBOL_MARRIAGE) self.dth = self.symbols.get_death_symbol_for_char(death_idx) else: death_idx = self.symbols.DEATH_SYMBOL_LATIN_CROSS gsf = self.symbols.get_symbol_fallback self.male = gsf(self.symbols.SYMBOL_MALE) self.female = gsf(self.symbols.SYMBOL_FEMALE) self.marr = gsf(self.symbols.SYMBOL_MARRIAGE) self.bth = gsf(self.symbols.SYMBOL_BIRTH) self.dth = self.symbols.get_death_symbol_fallback(death_idx)
class FormattingHelper: """Format of commonly used expressions, making use of a cache to not recompute """ def __init__(self, dbstate, uistate=None): self.dbstate = dbstate self.uistate = uistate self._text_cache = {} self._markup_cache = {} self.symbols = Symbols() self.reload_symbols() def reload_symbols(self): self.clear_cache() if self.uistate and self.uistate.symbols: death_idx = self.uistate.death_symbol self.male = self.symbols.get_symbol_for_string( self.symbols.SYMBOL_MALE) self.female = self.symbols.get_symbol_for_string( self.symbols.SYMBOL_FEMALE) self.bth = self.symbols.get_symbol_for_string( self.symbols.SYMBOL_BIRTH) self.marr = self.symbols.get_symbol_for_string( self.symbols.SYMBOL_MARRIAGE) self.dth = self.symbols.get_death_symbol_for_char(death_idx) else: death_idx = self.symbols.DEATH_SYMBOL_LATIN_CROSS self.male = self.symbols.get_symbol_fallback( self.symbols.SYMBOL_MALE) self.female = self.symbols.get_symbol_fallback( self.symbols.SYMBOL_FEMALE) self.marr = self.symbols.get_symbol_fallback( self.symbols.SYMBOL_MARRIAGE) self.bth = self.symbols.get_symbol_fallback( self.symbols.SYMBOL_BIRTH) self.dth = self.symbols.get_death_symbol_fallback(death_idx) def format_relation(self, family, line_count, use_markup=False): """ Format a relation between parents of a family """ if not family: return "" if use_markup: if family.handle in self._markup_cache: if line_count in self._markup_cache[family.handle]: return self._markup_cache[family.handle][line_count] else: if family.handle in self._text_cache: if line_count in self._text_cache[family.handle]: return self._text_cache[family.handle][line_count] text = "" marriage = get_marriage_or_fallback(self.dbstate.db, family) if marriage and use_markup and marriage.get_type( ) != EventType.MARRIAGE: mdate = "<i>%s %s</i>" % (self.marr, escape(get_date(marriage))) mplace = "<i>%s</i>" % escape( self.get_place_name(marriage.get_place_handle())) name = "<i>%s</i>" % str(marriage.get_type()) elif marriage and use_markup: mdate = "%s %s" % (self.marr, escape(get_date(marriage))) mplace = escape(self.get_place_name(marriage.get_place_handle())) name = str(marriage.get_type()) elif marriage: mdate = "%s %s" % (self.marr, get_date(marriage)) mplace = self.get_place_name(marriage.get_place_handle()) name = str(marriage.get_type()) else: mdate = "" mplace = "" name = "" if line_count >= 1: text += mdate text += "\n" if line_count >= 2: text += name text += "\n" if line_count >= 3: text += mplace text += "\n" if not text: text = str(family.get_relationship()) if use_markup: if not family.handle in self._markup_cache: self._markup_cache[family.handle] = {} self._markup_cache[family.handle][line_count] = text else: if not family.handle in self._text_cache: self._text_cache[family.handle] = {} self._text_cache[family.handle][line_count] = text return text def get_place_name(self, place_handle): """ Obtain a place name """ text = "" if place_handle: place = self.dbstate.db.get_place_from_handle(place_handle) if place: place_title = place_displayer.display(self.dbstate.db, place) if place_title != "": if len(place_title) > 25: text = place_title[:24] + "..." else: text = place_title return text def format_person(self, person, line_count, use_markup=False): """fromat how info about a person should be presented """ if not person: return "" if use_markup: if person.handle in self._markup_cache: if line_count in self._markup_cache[person.handle]: return self._markup_cache[person.handle][line_count] name = escape(name_displayer.display(person)) else: if person.handle in self._text_cache: if line_count in self._text_cache[person.handle]: return self._text_cache[person.handle][line_count] name = name_displayer.display(person) text = name if line_count >= 3: birth = get_birth_or_fallback(self.dbstate.db, person) if birth and use_markup and birth.get_type() != EventType.BIRTH: bdate = "<i>%s</i>" % escape(get_date(birth)) bplace = "<i>%s</i>" % escape( self.get_place_name(birth.get_place_handle())) elif birth and use_markup: bdate = escape(get_date(birth)) bplace = escape(self.get_place_name(birth.get_place_handle())) elif birth: bdate = get_date(birth) bplace = self.get_place_name(birth.get_place_handle()) else: bdate = "" bplace = "" death = get_death_or_fallback(self.dbstate.db, person) if death and use_markup and death.get_type() != EventType.DEATH: ddate = "<i>%s</i>" % escape(get_date(death)) dplace = "<i>%s</i>" % escape( self.get_place_name(death.get_place_handle())) elif death and use_markup: ddate = escape(get_date(death)) dplace = escape(self.get_place_name(death.get_place_handle())) elif death: ddate = get_date(death) dplace = self.get_place_name(death.get_place_handle()) else: ddate = "" dplace = "" if line_count < 5: text = "%s\n%s %s\n%s %s" % (name, self.bth, bdate, self.dth, ddate) else: text = "%s\n%s %s\n %s\n%s %s\n %s" % ( name, self.bth, bdate, bplace, self.dth, ddate, dplace) if use_markup: if not person.handle in self._markup_cache: self._markup_cache[person.handle] = {} self._markup_cache[person.handle][line_count] = text else: if not person.handle in self._text_cache: self._text_cache[person.handle] = {} self._text_cache[person.handle][line_count] = text return text def clear_cache(self): """clear the cache of kept format strings """ self._text_cache = {} self._markup_cache = {}
def __init__(self, database, options, user): Report.__init__(self, database, options, user) self.set_locale(options.menu.get_option_by_name('trans').get_value()) stdoptions.run_date_format_option(self, options.menu) stdoptions.run_name_format_option(self, options.menu) self.database = database self._gidlist = options.menu.get_option_by_name( 'gidlist').get_value().split() self._withparents = options.menu.get_option_by_name( 'withparents').get_value() self._withchildren = options.menu.get_option_by_name( 'withchildren').get_value() self._withspouses = options.menu.get_option_by_name( 'withspouses').get_value() self._usesubgraphs = options.menu.get_option_by_name( 'usesubgraphs').get_value() self.fillcolor = { Person.MALE: options.menu.get_option_by_name('colormales').get_value(), Person.FEMALE: options.menu.get_option_by_name('colorfemales').get_value(), Person.UNKNOWN: options.menu.get_option_by_name('colorunknown').get_value() } self.nodestyle = { Person.MALE: 'solid', Person.FEMALE: 'rounded', Person.UNKNOWN: 'solid' } self.nodeshape = { Person.MALE: 'box', Person.FEMALE: 'box', Person.UNKNOWN: 'hexagon' } symbols = Symbols() self.symbols = { Person.FEMALE: symbols.get_symbol_for_string(symbols.SYMBOL_FEMALE), Person.MALE: symbols.get_symbol_for_string(symbols.SYMBOL_MALE), Person.UNKNOWN: symbols.get_symbol_for_string(symbols.SYMBOL_ASEXUAL_SEXLESS), 'birth': symbols.get_symbol_for_string(symbols.SYMBOL_BIRTH), 'death': symbols.get_death_symbol_for_char( symbols.DEATH_SYMBOL_LATIN_CROSS), 'illegitimate': symbols.get_symbol_for_string(symbols.SYMBOL_ILLEGITIM), 'kia': symbols.get_symbol_for_string(symbols.SYMBOL_KILLED_IN_ACTION), # marriage symbols display with extra linebreaks in Graphviz family nodes # todo: using fallbacks for now 'engaged': symbols.get_symbol_fallback(symbols.SYMBOL_ENGAGED), 'married': symbols.get_symbol_fallback(symbols.SYMBOL_MARRIAGE), 'unmarried': symbols.get_symbol_fallback(symbols.SYMBOL_UNMARRIED_PARTNERSHIP), 'divorced': symbols.get_symbol_fallback(symbols.SYMBOL_DIVORCE) }