예제 #1
0
    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, None)

            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
                path = os.path.join(db_path, "name.txt")
                try:
                    ifile = open(path)
                    title = ifile.readline().strip()
                    ifile.close()
                except:
                    title = db_path
                RecentFiles.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
예제 #2
0
    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, None)

            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
                path = os.path.join(db_path, "name.txt")
                try:
                    ifile = open(path)
                    title = ifile.readline().strip()
                    ifile.close()
                except:
                    title = db_path
                RecentFiles.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
예제 #3
0
    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)
        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 res.get_name() == "" and owner.get_name() != "":
            self.dbstate.db.set_researcher(owner)
        
        name_displayer.set_name_format(self.dbstate.db.name_formats)
        fmt_default = config.get('preferences.name-format')
        if fmt_default < 0:
            name_displayer.set_default_format(fmt_default)

        self.dbstate.db.enable_signals()
        self.dbstate.signal_change()

        config.set('paths.recent-file', filename)

        try:
            initial_person = self.dbstate.db.find_initial_person().get_handle()
            self.uistate.set_active(initial_person, 'Person')
        except:
            pass
        
        RecentFiles.recent_files(filename, name)
        self.file_loaded = True
예제 #4
0
    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.is_empty():
            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)

        RecentFiles.recent_files(filename, name)
        self.file_loaded = True