Improved error handling

svn: r3083
This commit is contained in:
Don Allingham 2004-04-10 03:38:48 +00:00
parent 96579ed88f
commit 358e8f8404
6 changed files with 81 additions and 31 deletions

View File

@ -97,8 +97,8 @@ class DbPrompter:
def save_ok_button_clicked(self,obj): def save_ok_button_clicked(self,obj):
filename = obj.get_filename().encode('iso8859-1') filename = obj.get_filename().encode('iso8859-1')
if filename: if filename:
Utils.destroy_passed_object(obj) if self.db.read_file(filename) == 1:
self.db.read_file(filename) Utils.destroy_passed_object(obj)
def open_activate(self): def open_activate(self):
@ -122,8 +122,8 @@ class DbPrompter:
if not filename: if not filename:
return return
Utils.destroy_passed_object(obj) if self.db.read_file(filename) == 1:
self.db.read_file(filename) Utils.destroy_passed_object(obj)
def open_delete_event(self,obj,event): def open_delete_event(self,obj,event):
gtk.mainquit() gtk.mainquit()

View File

@ -27,6 +27,7 @@
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gettext import gettext as _ from gettext import gettext as _
import os
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -68,6 +69,8 @@ class PeopleView:
def __init__(self,parent): def __init__(self,parent):
self.parent = parent self.parent = parent
self.nosort = os.environ.has_key('NOSORT')
self.DataFilter = Filter.Filter("") self.DataFilter = Filter.Filter("")
self.pscroll = self.parent.gtop.get_widget("pscroll") self.pscroll = self.parent.gtop.get_widget("pscroll")
self.person_tree = self.parent.gtop.get_widget("person_tree") 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 = gtk.TreeViewColumn(_('Name'), self.renderer,text=0)
column.set_resizable(gtk.TRUE) column.set_resizable(gtk.TRUE)
column.set_clickable(gtk.TRUE)
column.set_min_width(225) 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.person_tree.append_column(column)
self.columns = [column] self.columns = [column]
@ -108,18 +112,18 @@ class PeopleView:
self.person_tree.set_model(None) self.person_tree.set_model(None)
self.person_model = PeopleModel.PeopleModel(self.parent.db) 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.sort_model)
#self.person_tree.set_model(self.person_model)
self.person_selection = self.person_tree.get_selection() self.person_selection = self.person_tree.get_selection()
self.person_selection.connect('changed',self.row_changed) self.person_selection.connect('changed',self.row_changed)
self.person_tree.connect('row_activated', self.alpha_event) self.person_tree.connect('row_activated', self.alpha_event)
self.person_tree.connect('button-press-event',self.on_plist_button_press) self.person_tree.connect('button-press-event',self.on_plist_button_press)
def blist(self,store,path,iter,id_list): 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)) id_list.append(self.sort_model.get_value(iter,1))
def get_selected_objects(self): def get_selected_objects(self):
@ -250,6 +254,9 @@ class PeopleView:
def redisplay_person_list(self,person): def redisplay_person_list(self,person):
self.person_model = PeopleModel.PeopleModel(self.parent.db) 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.sort_model)

View File

@ -2407,11 +2407,11 @@ class GrampsDB:
def load(self,name,callback): def load(self,name,callback):
if self.person_map: if self.person_map:
self.close() self.close()
self.env = db.DBEnv() self.env = db.DBEnv()
flags = db.DB_CREATE|db.DB_INIT_MPOOL|db.DB_PRIVATE flags = db.DB_CREATE|db.DB_INIT_MPOOL|db.DB_PRIVATE
self.env.open(os.path.dirname(name), flags) self.env.open(os.path.dirname(name), flags)
name = os.path.basename(name) name = os.path.basename(name)
self.person_map = dbshelve.open(name, dbname="person", dbenv=self.env) self.person_map = dbshelve.open(name, dbname="person", dbenv=self.env)
self.family_map = dbshelve.open(name, dbname="family", 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.surnames.open(name, "surnames", db.DB_HASH, flags=db.DB_CREATE)
self.person_map.associate(self.surnames, find_surname, db.DB_CREATE) self.person_map.associate(self.surnames, find_surname, db.DB_CREATE)
return 1
def close(self): def close(self):
self.person_map.close() self.person_map.close()

View File

@ -25655,7 +25655,7 @@
<property name="left_attach">0</property> <property name="left_attach">0</property>
<property name="right_attach">1</property> <property name="right_attach">1</property>
<property name="top_attach">0</property> <property name="top_attach">0</property>
<property name="bottom_attach">2</property> <property name="bottom_attach">1</property>
<property name="x_options">fill</property> <property name="x_options">fill</property>
<property name="y_options">fill</property> <property name="y_options">fill</property>
</packing> </packing>
@ -25681,14 +25681,14 @@
<property name="top_attach">0</property> <property name="top_attach">0</property>
<property name="bottom_attach">1</property> <property name="bottom_attach">1</property>
<property name="x_options">expand|shrink|fill</property> <property name="x_options">expand|shrink|fill</property>
<property name="y_options"></property> <property name="y_options">fill</property>
</packing> </packing>
</child> </child>
</widget> </widget>
<packing> <packing>
<property name="padding">0</property> <property name="padding">0</property>
<property name="expand">True</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">False</property>
</packing> </packing>
</child> </child>
</widget> </widget>

View File

@ -59,7 +59,7 @@ import FamilyView
import SourceView import SourceView
import PeopleView import PeopleView
from QuestionDialog import QuestionDialog, ErrorDialog, WarningDialog, SaveDialog, OptionDialog, MissingMediaDialog from QuestionDialog import *
import DisplayTrace import DisplayTrace
import Filter import Filter
@ -71,6 +71,12 @@ import GrampsCfg
import EditPerson import EditPerson
import Find import Find
import ReadXML 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 import ArgHandler
ArgHandler.ArgHandler(self,args) ArgHandler.ArgHandler(self,args)
elif GrampsCfg.lastfile and GrampsCfg.autoload: 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: else:
import DbPrompter
DbPrompter.DbPrompter(self,0,self.topWindow) DbPrompter.DbPrompter(self,0,self.topWindow)
self.db.set_researcher(GrampsCfg.get_researcher()) self.db.set_researcher(GrampsCfg.get_researcher())
@ -962,7 +968,8 @@ class Gramps:
filename = os.path.normpath(os.path.abspath(filename)) filename = os.path.normpath(os.path.abspath(filename))
self.filesel.destroy() self.filesel.destroy()
self.clear_database() 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): def on_help_dbopen_clicked(self,obj):
"""Display the relevant portion of GRAMPS manual""" """Display the relevant portion of GRAMPS manual"""
@ -970,7 +977,6 @@ class Gramps:
self.dbopen_button = self.dbopen_fs.run() self.dbopen_button = self.dbopen_fs.run()
def auto_save_load(self,filename): def auto_save_load(self,filename):
filename = os.path.normpath(os.path.abspath(filename)) filename = os.path.normpath(os.path.abspath(filename))
if os.path.isdir(filename): if os.path.isdir(filename):
dirname = filename dirname = filename
@ -978,7 +984,7 @@ class Gramps:
dirname = os.path.dirname(filename) dirname = os.path.dirname(filename)
self.active_person = None self.active_person = None
self.read_file(filename) return self.read_file(filename)
def read_gedcom(self,filename): def read_gedcom(self,filename):
import ReadGedcom import ReadGedcom
@ -994,15 +1000,51 @@ class Gramps:
def read_file(self,filename): def read_file(self,filename):
self.topWindow.set_resizable(gtk.FALSE) self.topWindow.set_resizable(gtk.FALSE)
filename = os.path.normpath(os.path.abspath(filename)) filename = os.path.normpath(os.path.abspath(filename))
if self.load_database(filename) == 1: new_db = 0
if filename[-1] == '/':
filename = filename[:-1] if os.path.isdir(filename):
name = os.path.basename(filename) ErrorDialog(_('Cannot open database'),
self.topWindow.set_title("%s - GRAMPS" % name) _('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: 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.topWindow.set_resizable(gtk.TRUE)
self.people_view.apply_filter() self.people_view.apply_filter()
return 1
def on_ok_button2_clicked(self,obj): def on_ok_button2_clicked(self,obj):
filename = obj.get_filename() filename = obj.get_filename()
@ -1573,12 +1615,13 @@ class Gramps:
def load_database(self,name): def load_database(self,name):
filename = name filename = name
#self.clear_database()
self.status_text(_("Loading %s...") % name) self.status_text(_("Loading %s...") % name)
if self.db.load(filename,self.load_progress) == 0: if self.db.load(filename,self.load_progress) == 0:
self.status_text('') self.status_text('')
return 0 return 0
self.status_text('') self.status_text('')
self.db.clear_added_media_objects() self.db.clear_added_media_objects()
return self.post_load(name) return self.post_load(name)

View File

@ -61,7 +61,6 @@ GLADEFILES = \
gedcomexport.glade\ gedcomexport.glade\
gedcomimport.glade\ gedcomimport.glade\
merge.glade\ merge.glade\
pafexport.glade\
patchnames.glade\ patchnames.glade\
pkgexport.glade\ pkgexport.glade\
relcalc.glade\ relcalc.glade\