From 98f5e48e37e9870b509363b23f8b6ea459b56d2f Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sat, 10 Apr 2004 03:38:48 +0000 Subject: [PATCH] Improved error handling svn: r3083 --- gramps2/src/DbPrompter.py | 8 ++-- gramps2/src/PeopleView.py | 21 ++++++---- gramps2/src/RelLib.py | 5 ++- gramps2/src/gramps.glade | 8 ++-- gramps2/src/gramps_main.py | 69 ++++++++++++++++++++++++++------- gramps2/src/plugins/Makefile.am | 1 - 6 files changed, 81 insertions(+), 31 deletions(-) diff --git a/gramps2/src/DbPrompter.py b/gramps2/src/DbPrompter.py index 3d47fd2e1..c9be0b8b5 100644 --- a/gramps2/src/DbPrompter.py +++ b/gramps2/src/DbPrompter.py @@ -97,8 +97,8 @@ class DbPrompter: def save_ok_button_clicked(self,obj): filename = obj.get_filename().encode('iso8859-1') if filename: - Utils.destroy_passed_object(obj) - self.db.read_file(filename) + if self.db.read_file(filename) == 1: + Utils.destroy_passed_object(obj) def open_activate(self): @@ -122,8 +122,8 @@ class DbPrompter: if not filename: return - Utils.destroy_passed_object(obj) - self.db.read_file(filename) + if self.db.read_file(filename) == 1: + Utils.destroy_passed_object(obj) def open_delete_event(self,obj,event): gtk.mainquit() diff --git a/gramps2/src/PeopleView.py b/gramps2/src/PeopleView.py index 81031481d..a7313a785 100644 --- a/gramps2/src/PeopleView.py +++ b/gramps2/src/PeopleView.py @@ -27,6 +27,7 @@ # #------------------------------------------------------------------------- from gettext import gettext as _ +import os #------------------------------------------------------------------------- # @@ -68,6 +69,8 @@ class PeopleView: def __init__(self,parent): self.parent = parent + self.nosort = os.environ.has_key('NOSORT') + self.DataFilter = Filter.Filter("") self.pscroll = self.parent.gtop.get_widget("pscroll") self.person_tree = self.parent.gtop.get_widget("person_tree") @@ -84,9 +87,10 @@ class PeopleView: column = gtk.TreeViewColumn(_('Name'), self.renderer,text=0) column.set_resizable(gtk.TRUE) - column.set_clickable(gtk.TRUE) column.set_min_width(225) - column.set_sort_column_id(PeopleModel.COLUMN_NAME_SORT) + if not self.nosort: + column.set_clickable(gtk.TRUE) + column.set_sort_column_id(PeopleModel.COLUMN_NAME_SORT) self.person_tree.append_column(column) self.columns = [column] @@ -108,18 +112,18 @@ class PeopleView: self.person_tree.set_model(None) self.person_model = PeopleModel.PeopleModel(self.parent.db) - self.sort_model = gtk.TreeModelSort(self.person_model) + if self.nosort: + self.sort_model = self.person_model + else: + self.sort_model = gtk.TreeModelSort(self.person_model) self.person_tree.set_model(self.sort_model) - #self.person_tree.set_model(self.person_model) - self.person_selection = self.person_tree.get_selection() self.person_selection.connect('changed',self.row_changed) self.person_tree.connect('row_activated', self.alpha_event) self.person_tree.connect('button-press-event',self.on_plist_button_press) def blist(self,store,path,iter,id_list): - #id_list.append(self.person_model.get_value(iter,1)) id_list.append(self.sort_model.get_value(iter,1)) def get_selected_objects(self): @@ -250,6 +254,9 @@ class PeopleView: def redisplay_person_list(self,person): self.person_model = PeopleModel.PeopleModel(self.parent.db) - self.sort_model = gtk.TreeModelSort(self.person_model) + if self.nosort: + self.sort_model = self.person_model + else: + self.sort_model = gtk.TreeModelSort(self.person_model) self.person_tree.set_model(self.sort_model) diff --git a/gramps2/src/RelLib.py b/gramps2/src/RelLib.py index 8f9900fb0..c19b0eb17 100644 --- a/gramps2/src/RelLib.py +++ b/gramps2/src/RelLib.py @@ -2407,11 +2407,11 @@ class GrampsDB: def load(self,name,callback): if self.person_map: self.close() - + self.env = db.DBEnv() flags = db.DB_CREATE|db.DB_INIT_MPOOL|db.DB_PRIVATE - self.env.open(os.path.dirname(name), flags) + name = os.path.basename(name) self.person_map = dbshelve.open(name, dbname="person", dbenv=self.env) self.family_map = dbshelve.open(name, dbname="family", dbenv=self.env) @@ -2426,6 +2426,7 @@ class GrampsDB: self.surnames.open(name, "surnames", db.DB_HASH, flags=db.DB_CREATE) self.person_map.associate(self.surnames, find_surname, db.DB_CREATE) + return 1 def close(self): self.person_map.close() diff --git a/gramps2/src/gramps.glade b/gramps2/src/gramps.glade index fd10c980d..bf843cc3f 100644 --- a/gramps2/src/gramps.glade +++ b/gramps2/src/gramps.glade @@ -25655,7 +25655,7 @@ 0 1 0 - 2 + 1 fill fill @@ -25681,14 +25681,14 @@ 0 1 expand|shrink|fill - + fill 0 - True - True + False + False diff --git a/gramps2/src/gramps_main.py b/gramps2/src/gramps_main.py index 3edf5f7ca..5ef370a2d 100755 --- a/gramps2/src/gramps_main.py +++ b/gramps2/src/gramps_main.py @@ -59,7 +59,7 @@ import FamilyView import SourceView import PeopleView -from QuestionDialog import QuestionDialog, ErrorDialog, WarningDialog, SaveDialog, OptionDialog, MissingMediaDialog +from QuestionDialog import * import DisplayTrace import Filter @@ -71,6 +71,12 @@ import GrampsCfg import EditPerson import Find import ReadXML +import DbPrompter + +try: # First try python2.3 and later: this is the future + from bsddb import db +except ImportError: # try python2.2 + from bsddb3 import db #------------------------------------------------------------------------- # @@ -139,9 +145,9 @@ class Gramps: import ArgHandler ArgHandler.ArgHandler(self,args) elif GrampsCfg.lastfile and GrampsCfg.autoload: - self.auto_save_load(GrampsCfg.lastfile) + if self.auto_save_load(GrampsCfg.lastfile) == 0: + DbPrompter.DbPrompter(self,0,self.topWindow) else: - import DbPrompter DbPrompter.DbPrompter(self,0,self.topWindow) self.db.set_researcher(GrampsCfg.get_researcher()) @@ -962,7 +968,8 @@ class Gramps: filename = os.path.normpath(os.path.abspath(filename)) self.filesel.destroy() self.clear_database() - self.auto_save_load(filename) + if self.auto_save_load(filename) == 0: + DbPrompter.DbPrompter(self,0,self.topWindow) def on_help_dbopen_clicked(self,obj): """Display the relevant portion of GRAMPS manual""" @@ -970,7 +977,6 @@ class Gramps: self.dbopen_button = self.dbopen_fs.run() def auto_save_load(self,filename): - filename = os.path.normpath(os.path.abspath(filename)) if os.path.isdir(filename): dirname = filename @@ -978,7 +984,7 @@ class Gramps: dirname = os.path.dirname(filename) self.active_person = None - self.read_file(filename) + return self.read_file(filename) def read_gedcom(self,filename): import ReadGedcom @@ -994,15 +1000,51 @@ class Gramps: def read_file(self,filename): self.topWindow.set_resizable(gtk.FALSE) filename = os.path.normpath(os.path.abspath(filename)) - if self.load_database(filename) == 1: - if filename[-1] == '/': - filename = filename[:-1] - name = os.path.basename(filename) - self.topWindow.set_title("%s - GRAMPS" % name) + new_db = 0 + + if os.path.isdir(filename): + ErrorDialog(_('Cannot open database'), + _('The selected file is a directory, not ' + 'a file.\nA GRAMPS database must be a file.')) + return 0 + elif os.path.exists(filename): + if not os.access(filename,os.R_OK): + ErrorDialog(_('Cannot open database'), + _('You do not have read access to the selected ' + 'file.')) + return 0 + elif not os.access(filename,os.W_OK): + ErrorDialog(_('Cannot open database'), + _('You do not have write access to the selected ' + 'file.')) + return 0 else: - GrampsCfg.save_last_file("") + new_db = 1 + + try: + if self.load_database(filename) == 1: + if filename[-1] == '/': + filename = filename[:-1] + name = os.path.basename(filename) + self.topWindow.set_title("%s - GRAMPS" % name) + else: + GrampsCfg.save_last_file("") + ErrorDialog(_('Cannot open database'), + _('The database file specified could not be opened file.')) + return 0 + except db.DBAccessError, msg: + ErrorDialog(_('Cannot open database'), + _('%s could not be opened.' % filename) + '\n' + msg[1]) + return 0 + + if new_db: + OkDialog(_('New database created'), + _('GRAMPS has created a new database called %s') % + filename) + self.topWindow.set_resizable(gtk.TRUE) self.people_view.apply_filter() + return 1 def on_ok_button2_clicked(self,obj): filename = obj.get_filename() @@ -1573,12 +1615,13 @@ class Gramps: def load_database(self,name): filename = name - #self.clear_database() self.status_text(_("Loading %s...") % name) + if self.db.load(filename,self.load_progress) == 0: self.status_text('') return 0 + self.status_text('') self.db.clear_added_media_objects() return self.post_load(name) diff --git a/gramps2/src/plugins/Makefile.am b/gramps2/src/plugins/Makefile.am index 056140807..f96f7f664 100644 --- a/gramps2/src/plugins/Makefile.am +++ b/gramps2/src/plugins/Makefile.am @@ -61,7 +61,6 @@ GLADEFILES = \ gedcomexport.glade\ gedcomimport.glade\ merge.glade\ - pafexport.glade\ patchnames.glade\ pkgexport.glade\ relcalc.glade\