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 handle_args_gui(self): """ Method to handle the arguments that can be given for a GUI session. :returns: the filename of the family tree that should be opened if user just passed a famtree or a filename. 1. no options: a family tree can be given, if so, this name is tested and returned. If a filename, it is imported in a new db and name of new db returned 2. an open and/or import option can have been given, if so, this is handled, and None is returned """ if self.open_gui: # First check if a Gramps database was provided # (either a database path or a database name) db_path = self.__deduce_db_path(self.open_gui) if not db_path: # Apparently it is not a database. See if it is a file that # can be imported. db_path, title = self.dbman.import_new_db( self.open_gui, self.user) if db_path: # Test if not locked or problematic if not self.check_db(db_path, self.force_unlock): sys.exit(0) # Add the file to the recent items title = self.dbstate.db.get_dbname() if not title: title = db_path recent_files(db_path, title) self.open = db_path self.__open_action() else: sys.exit(0) return db_path # if not open_gui, parse any command line args. We can only have one # open argument, and perhaps some import arguments self.__open_action() self.__import_action() return None
def handle_args_gui(self): """ Method to handle the arguments that can be given for a GUI session. :returns: the filename of the family tree that should be opened if user just passed a famtree or a filename. 1. no options: a family tree can be given, if so, this name is tested and returned. If a filename, it is imported in a new db and name of new db returned 2. an open and/or import option can have been given, if so, this is handled, and None is returned """ if self.open_gui: # First check if a Gramps database was provided # (either a database path or a database name) db_path = self.__deduce_db_path(self.open_gui) if not db_path: # Apparently it is not a database. See if it is a file that # can be imported. db_path, title = self.dbman.import_new_db(self.open_gui, self.user) if db_path: # Test if not locked or problematic if not self.check_db(db_path, self.force_unlock): sys.exit(1) # Add the file to the recent items title = self.dbstate.db.get_dbname() if not title: title = db_path recent_files(db_path, title) self.open = db_path self.__open_action() else: sys.exit(1) return db_path # if not open_gui, parse any command line args. We can only have one # open argument, and perhaps some import arguments self.__open_action() self.__import_action() return None
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