def _post_load_newdb(self, filename, title=None): """Called after load of a new database.""" if not filename: return if filename[-1] == os.path.sep: filename = filename[:-1] name = os.path.basename(filename) self.dbstate.db.db_name = title if title: name = title # apply preferred researcher if loaded file has none res = self.dbstate.db.get_researcher() owner = get_researcher() # If the DB Owner Info is empty and # [default] Researcher is not empty and # database is empty, then copy default researcher to DB owner if res.is_empty() and not owner.is_empty() and self.dbstate.db.get_total() == 0: self.dbstate.db.set_researcher(owner) name_displayer.clear_custom_formats() name_displayer.set_name_format(self.dbstate.db.name_formats) fmt_default = config.get("preferences.name-format") name_displayer.set_default_format(fmt_default) self.dbstate.db.enable_signals() self.dbstate.signal_change() config.set("paths.recent-file", filename) recent_files(filename, name)
def _get_styled(name, callname, placeholder=False, trans_text=glocale.translation.sgettext, name_format=None): """ 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. @param trans_text: allow deferred translation of strings @type trans_text: a GrampsLocale sgettext instance trans_text is a defined keyword (see po/update_po.py, po/genpot.sh) :param name_format: optional format to control display of person's name :type name_format: None or int """ # 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 == CALLNAME_REPLACE: # Replace first name with call name. n.first_name = n.call elif callname == CALLNAME_UNDERLINE_ADD: if n.call not in n.first_name: # Add call name to first name. # translators: used in French+Russian, ignore otherwise n.first_name = trans_text('"%(callname)s" (%(firstname)s)') % { 'callname': n.call, 'firstname': n.first_name } real_format = name_displayer.get_default_format() if name_format is not None: name_displayer.set_default_format(name_format) text = name_displayer.display_name(n) name_displayer.set_default_format(real_format) tags = [] if n.call: if callname == 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_styled(name, callname, placeholder=False, name_format=None): """ 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 == CALLNAME_REPLACE: # Replace first name with call name. n.first_name = n.call elif callname == 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 } real_format = name_displayer.get_default_format() if name_format is not None: name_displayer.set_default_format(name_format) text = name_displayer.display_name(n) name_displayer.set_default_format(real_format) tags = [] if n.call: if callname == 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_styled(name, callname, placeholder=False, name_format=None): """ 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 == CALLNAME_REPLACE: # Replace first name with call name. n.first_name = n.call elif callname == 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} real_format = name_displayer.get_default_format() if name_format is not None: name_displayer.set_default_format(name_format) text = name_displayer.display_name(n) name_displayer.set_default_format(real_format) tags = [] if n.call: if callname == 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 _post_load_newdb_nongui(self, filename, title=None): """ Called after a new database is loaded. """ if not filename: return if filename[-1] == os.path.sep: filename = filename[:-1] name = os.path.basename(filename) self.dbstate.db.db_name = title if title: name = title # This method is for UI stuff when the database has changed. # Window title, recent files, etc related to new file. self.dbstate.db.set_save_path(filename) # apply preferred researcher if loaded file has none res = self.dbstate.db.get_researcher() owner = get_researcher() # If the DB Owner Info is empty and # [default] Researcher is not empty and # database is empty, then copy default researcher to DB owner if (res.is_empty() and not owner.is_empty() and self.dbstate.db.get_total() == 0): self.dbstate.db.set_researcher(owner) name_displayer.set_name_format(self.dbstate.db.name_formats) fmt_default = config.get('preferences.name-format') name_displayer.set_default_format(fmt_default) self.dbstate.db.enable_signals() self.dbstate.signal_change() config.set('paths.recent-file', filename) recent_files(filename, name) self.file_loaded = True