Improved error handling
svn: r3083
This commit is contained in:
parent
96579ed88f
commit
358e8f8404
@ -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()
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
@ -25655,7 +25655,7 @@
|
||||
<property name="left_attach">0</property>
|
||||
<property name="right_attach">1</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="y_options">fill</property>
|
||||
</packing>
|
||||
@ -25681,14 +25681,14 @@
|
||||
<property name="top_attach">0</property>
|
||||
<property name="bottom_attach">1</property>
|
||||
<property name="x_options">expand|shrink|fill</property>
|
||||
<property name="y_options"></property>
|
||||
<property name="y_options">fill</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
|
@ -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)
|
||||
|
@ -61,7 +61,6 @@ GLADEFILES = \
|
||||
gedcomexport.glade\
|
||||
gedcomimport.glade\
|
||||
merge.glade\
|
||||
pafexport.glade\
|
||||
patchnames.glade\
|
||||
pkgexport.glade\
|
||||
relcalc.glade\
|
||||
|
Loading…
Reference in New Issue
Block a user