def _Name_get_styled(name, callname, placeholder=False): """ Return a StyledText object with the name formatted according to the parameters: @param callname: whether the callname should be used instead of the first name (CALLNAME_REPLACE), underlined within the first name (CALLNAME_UNDERLINE_ADD) or not used at all (CALLNAME_DONTUSE). @param placeholder: whether a series of underscores should be inserted as a placeholder if first name or surname are missing. """ # Make a copy of the name object so we don't mess around with the real # data. n = Name(source=name) # Insert placeholders. if placeholder: if not n.first_name: n.first_name = "____________" if not n.surname: n.surname = "____________" if n.call: if callname == _Name_CALLNAME_REPLACE: # Replace first name with call name. n.first_name = n.call elif callname == _Name_CALLNAME_UNDERLINE_ADD: if n.call not in n.first_name: # Add call name to first name. n.first_name = "\"%(call)s\" (%(first)s)" % { 'call': n.call, 'first': n.first_name } text = name_displayer.display_name(n) tags = [] if n.call: if callname == _Name_CALLNAME_UNDERLINE_ADD: # "name" in next line is on purpose: only underline the call name # if it was a part of the *original* first name if n.call in name.first_name: # Underline call name callpos = text.find(n.call) tags = [ StyledTextTag(StyledTextTagType.UNDERLINE, True, [(callpos, callpos + len(n.call))]) ] return StyledText(text, tags)
def get_text(self, start=None, end=None, include_hidden_chars=True): """Return the buffer text. @note: 's_' prefix means StyledText*, while 'g_' prefix means gtk.*. """ if start is None: start = self.get_start_iter() if end is None: end = self.get_end_iter() txt = super(StyledTextBuffer, self).get_text(start, end, include_hidden_chars) txt = unicode(txt) # extract tags out of the buffer g_tags = self._get_tag_from_range() s_tags = [] for g_tagname, g_ranges in g_tags.items(): if g_tagname.startswith('link'): tag = self.get_tag_table().lookup(g_tagname) s_ranges = [(start, end + 1) for (start, end) in g_ranges] s_value = tag.data s_tag = StyledTextTag(_('Link'), s_value, s_ranges) s_tags.append(s_tag) else: style_and_value = g_tagname.split(' ', 1) try: style = int(style_and_value[0]) if len(style_and_value) == 1: s_value = None else: s_value = StyledTextTagType.STYLE_TYPE[style]\ (style_and_value[1]) if style in ALLOWED_STYLES: s_ranges = [(start, end + 1) for (start, end) in g_ranges] s_tag = StyledTextTag(style, s_value, s_ranges) s_tags.append(s_tag) except ValueError: _LOG.debug("silently skipping gtk.TextTag '%s'" % g_tagname) return StyledText(txt, s_tags)
def get_notes(self, obj): """ Get the note list for the current object. """ self.left.set_sensitive(False) self.right.set_sensitive(False) self.texteditor.set_text(StyledText()) self.note_list = obj.get_note_list() self.page.set_text('') if len(self.note_list) > 0: self.set_has_data(True) if len(self.note_list) > 1: self.right.set_sensitive(True) self.current = 0 self.display_note() else: self.set_has_data(False)
def linkst(text, url): """ Return text as link styled text """ tags = [StyledTextTag(StyledTextTagType.LINK, url, [(0, len(text))])] return StyledText(text, tags)
def boldst(text): """ Return text as bold styled text """ tags = [StyledTextTag(StyledTextTagType.BOLD, True, [(0, len(text))])] return StyledText(text, tags)
def st(text): """ Return text as styled text """ return StyledText(text)
def _find_records(db, filter, callname): today = datetime.date.today() today_date = Date(today.year, today.month, today.day) # Person records person_youngestliving = [] person_oldestliving = [] person_youngestdied = [] person_oldestdied = [] person_youngestmarried = [] person_oldestmarried = [] person_youngestdivorced = [] person_oldestdivorced = [] person_youngestfather = [] person_youngestmother = [] person_oldestfather = [] person_oldestmother = [] person_handle_list = db.iter_person_handles() if filter: person_handle_list = filter.apply(db, person_handle_list) for person_handle in person_handle_list: person = db.get_person_from_handle(person_handle) birth_ref = person.get_birth_ref() if not birth_ref: # No birth event, so we can't calculate any age. continue birth = db.get_event_from_handle(birth_ref.ref) birth_date = birth.get_date_object() death_date = _find_death_date(db, person) if not _good_date(birth_date): # Birth date unknown or incomplete, so we can't calculate any age. continue name = _Person_get_styled_primary_name(person, callname) if death_date is None: if probably_alive(person, db): # Still living, look for age records _record(person_youngestliving, person_oldestliving, today_date - birth_date, name, 'Person', person_handle) elif _good_date(death_date): # Already died, look for age records _record(person_youngestdied, person_oldestdied, death_date - birth_date, name, 'Person', person_handle) for family_handle in person.get_family_handle_list(): family = db.get_family_from_handle(family_handle) marriage_date = None divorce_date = None for event_ref in family.get_event_ref_list(): event = db.get_event_from_handle(event_ref.ref) if (event.get_type().is_marriage() and (event_ref.get_role().is_family() or event_ref.get_role().is_primary())): marriage_date = event.get_date_object() elif (event.get_type().is_divorce() and (event_ref.get_role().is_family() or event_ref.get_role().is_primary())): divorce_date = event.get_date_object() if _good_date(marriage_date): _record(person_youngestmarried, person_oldestmarried, marriage_date - birth_date, name, 'Person', person_handle) if _good_date(divorce_date): _record(person_youngestdivorced, person_oldestdivorced, divorce_date - birth_date, name, 'Person', person_handle) for child_ref in family.get_child_ref_list(): if person.get_gender() == person.MALE: relation = child_ref.get_father_relation() elif person.get_gender() == person.FEMALE: relation = child_ref.get_mother_relation() else: continue if relation != ChildRefType.BIRTH: continue child = db.get_person_from_handle(child_ref.ref) child_birth_ref = child.get_birth_ref() if not child_birth_ref: continue child_birth = db.get_event_from_handle(child_birth_ref.ref) child_birth_date = child_birth.get_date_object() if not _good_date(child_birth_date): continue if person.get_gender() == person.MALE: _record(person_youngestfather, person_oldestfather, child_birth_date - birth_date, name, 'Person', person_handle) elif person.get_gender() == person.FEMALE: _record(person_youngestmother, person_oldestmother, child_birth_date - birth_date, name, 'Person', person_handle) # Family records family_mostchildren = [] family_youngestmarried = [] family_oldestmarried = [] family_shortest = [] family_longest = [] for family in db.iter_families(): #family = db.get_family_from_handle(family_handle) father_handle = family.get_father_handle() if not father_handle: continue mother_handle = family.get_mother_handle() if not mother_handle: continue # Test if either father or mother are in filter if filter: if not filter.apply(db, [father_handle, mother_handle]): continue father = db.get_person_from_handle(father_handle) mother = db.get_person_from_handle(mother_handle) name = StyledText(_("%(father)s and %(mother)s")) % { 'father': _Person_get_styled_primary_name(father, callname), 'mother': _Person_get_styled_primary_name(mother, callname) } _record(None, family_mostchildren, len(family.get_child_ref_list()), name, 'Family', family.handle) marriage_date = None divorce = None divorce_date = None for event_ref in family.get_event_ref_list(): event = db.get_event_from_handle(event_ref.ref) if (event.get_type().is_marriage() and (event_ref.get_role().is_family() or event_ref.get_role().is_primary())): marriage_date = event.get_date_object() if (event and event.get_type().is_divorce() and (event_ref.get_role().is_family() or event_ref.get_role().is_primary())): divorce = event divorce_date = event.get_date_object() father_death_date = _find_death_date(db, father) mother_death_date = _find_death_date(db, mother) if not _good_date(marriage_date): # Not married or marriage date unknown continue if divorce is not None and not _good_date(divorce_date): # Divorced but date unknown or inexact continue if not probably_alive(father, db) and not _good_date(father_death_date): # Father died but death date unknown or inexact continue if not probably_alive(mother, db) and not _good_date(mother_death_date): # Mother died but death date unknown or inexact continue if divorce_date is None and father_death_date is None and mother_death_date is None: # Still married and alive if probably_alive(father, db) and probably_alive(mother, db): _record(family_youngestmarried, family_oldestmarried, today_date - marriage_date, name, 'Family', family.handle) elif (_good_date(divorce_date) or _good_date(father_death_date) or _good_date(mother_death_date)): end = None if _good_date(father_death_date) and _good_date(mother_death_date): end = min(father_death_date, mother_death_date) elif _good_date(father_death_date): end = father_death_date elif _good_date(mother_death_date): end = mother_death_date if _good_date(divorce_date): if end: end = min(end, divorce_date) else: end = divorce_date duration = end - marriage_date _record(family_shortest, family_longest, duration, name, 'Family', family.handle) return [(text, varname, locals()[varname]) for (text, varname, default) in RECORDS]
def clear_text(self): self.left.set_sensitive(False) self.right.set_sensitive(False) self.texteditor.set_text(StyledText()) self.page.set_text('') self.current = 0