* src/DbPrompter.py: Add new class for new, existing, and import
prompters. Enable opening any format on the startup. * src/gramps_main.py: Use new DbPrompter classes. * src/ArgHandler.py: Use new DbPrompter classes. svn: r3239
This commit is contained in:
@ -1,8 +1,8 @@
|
|||||||
2004-06-28 Alex Roitman <shura@alex.neuro.umn.edu>
|
2004-06-28 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||||
* src/DbPrompter.py: Add NewNativeDbPrompter class for setting up
|
* src/DbPrompter.py: Add new class for new, existing, and import
|
||||||
a native database. Enable opening any format on the startup.
|
prompters. Enable opening any format on the startup.
|
||||||
* src/gramps_main.py: Use NewNativeDbPrompter when opening
|
* src/gramps_main.py: Use new DbPrompter classes.
|
||||||
non-native data.
|
* src/ArgHandler.py: Use new DbPrompter classes.
|
||||||
|
|
||||||
2004-06-27 Don Allingham <dallingham@users.sourceforge.net>
|
2004-06-27 Don Allingham <dallingham@users.sourceforge.net>
|
||||||
* src/gramps_main.py: fix import problem
|
* src/gramps_main.py: fix import problem
|
||||||
|
@ -201,36 +201,34 @@ class ArgHandler:
|
|||||||
print "Opened successfully!"
|
print "Opened successfully!"
|
||||||
else:
|
else:
|
||||||
print "Cannot open %s. Exiting..."
|
print "Cannot open %s. Exiting..."
|
||||||
|
elif filetype in ("application/x-gedcom","x-directory/normal",
|
||||||
|
"application/x-gramps-package"):
|
||||||
|
QuestionDialog.OkDialog( _("Opening non-native format"),
|
||||||
|
_("New GRAMPS database has to be set up when opening non-native formats. The following dialog will let you select the new database."),
|
||||||
|
self.parent.topWindow)
|
||||||
|
prompter = DbPrompter.NewNativeDbPrompter(self.parent)
|
||||||
|
if not prompter.chooser():
|
||||||
|
QuestionDialog.ErrorDialog(
|
||||||
|
_("New GRAMPS database was not set up"),
|
||||||
|
_('GRAMPS cannot open non-native data without setting up new GRAMPS database.'))
|
||||||
|
print "Cannot continue without native database. Exiting..."
|
||||||
|
os._exit(1)
|
||||||
elif filetype == "application/x-gedcom":
|
elif filetype == "application/x-gedcom":
|
||||||
print "Type: GEDCOM"
|
print "Type: GEDCOM"
|
||||||
QuestionDialog.OkDialog( _("Opening non-native format"),
|
|
||||||
_("New gramps database has to be set up when opening non-native formats. The following dialog will let you select the new database."),
|
|
||||||
self.parent.topWindow)
|
|
||||||
DbPrompter.DbPrompter(self.parent,1,self.parent.topWindow,filename)
|
|
||||||
self.parent.read_gedcom(filename)
|
self.parent.read_gedcom(filename)
|
||||||
elif filetype == "x-directory/normal":
|
elif filetype == "x-directory/normal":
|
||||||
print "Type: GRAMPS XML"
|
print "Type: GRAMPS XML"
|
||||||
QuestionDialog.OkDialog( _("Opening non-native format"),
|
|
||||||
_("New gramps database has to be set up when opening non-native formats. The following dialog will let you select the new database."),
|
|
||||||
self.parent.topWindow)
|
|
||||||
DbPrompter.DbPrompter(self.parent,1,self.parent.topWindow,filename)
|
|
||||||
self.parent.read_xml(filename)
|
self.parent.read_xml(filename)
|
||||||
elif filetype == "application/x-gramps-package":
|
elif filetype == "application/x-gramps-package":
|
||||||
print "Type: GRAMPS package"
|
print "Type: GRAMPS package"
|
||||||
QuestionDialog.OkDialog( _("Opening non-native format"),
|
|
||||||
_("New gramps database has to be set up when opening non-native formats. The following dialog will let you select the new database."),
|
|
||||||
self.parent.topWindow)
|
|
||||||
DbPrompter.DbPrompter(self.parent,1,self.parent.topWindow,filename)
|
|
||||||
self.parent.read_pkg(filename)
|
self.parent.read_pkg(filename)
|
||||||
else:
|
else:
|
||||||
print "Unknown file type: %s" % filetype
|
print "Unknown file type: %s" % filetype
|
||||||
QuestionDialog.ErrorDialog(
|
QuestionDialog.ErrorDialog(
|
||||||
_("Cannot open file: unknown type"),
|
_("Cannot open file: unknown type"),
|
||||||
_('File type "%s" is unknown to GRAMPS.\n\nValid types are: GRAMPS database, GRAMPS XML, GRAMPS package, and GEDCOM.') % filetype,
|
_('File type "%s" is unknown to GRAMPS.\n\nValid types are: GRAMPS database, GRAMPS XML, GRAMPS package, and GEDCOM.') % filetype)
|
||||||
self.parent.topWindow)
|
|
||||||
print "Exiting..."
|
print "Exiting..."
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.imports:
|
if self.imports:
|
||||||
@ -287,9 +285,9 @@ class ArgHandler:
|
|||||||
self.parent.import_tool_callback()
|
self.parent.import_tool_callback()
|
||||||
elif GrampsCfg.lastfile and GrampsCfg.autoload:
|
elif GrampsCfg.lastfile and GrampsCfg.autoload:
|
||||||
if self.parent.auto_save_load(GrampsCfg.lastfile) == 0:
|
if self.parent.auto_save_load(GrampsCfg.lastfile) == 0:
|
||||||
DbPrompter.DbPrompter(self.parent,0,self.parent.topWindow)
|
DbPrompter.DbPrompter(self.parent,0)
|
||||||
else:
|
else:
|
||||||
DbPrompter.DbPrompter(self.parent,0,self.parent.topWindow)
|
DbPrompter.DbPrompter(self.parent,0)
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
@ -57,10 +57,9 @@ import Plugins
|
|||||||
class DbPrompter:
|
class DbPrompter:
|
||||||
"""Make sure a database is opened"""
|
"""Make sure a database is opened"""
|
||||||
|
|
||||||
def __init__(self,parent,want_new,parent_window=None,file_hint=None):
|
def __init__(self,parent,want_new,parent_window=None):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.parent_window = parent_window
|
self.parent_window = parent_window
|
||||||
self.file_hint = file_hint
|
|
||||||
opendb = gtk.glade.XML(const.gladeFile, "opendb","gramps")
|
opendb = gtk.glade.XML(const.gladeFile, "opendb","gramps")
|
||||||
top = opendb.get_widget('opendb')
|
top = opendb.get_widget('opendb')
|
||||||
if parent_window:
|
if parent_window:
|
||||||
@ -75,7 +74,11 @@ class DbPrompter:
|
|||||||
while 1:
|
while 1:
|
||||||
response = top.run()
|
response = top.run()
|
||||||
if response == gtk.RESPONSE_OK:
|
if response == gtk.RESPONSE_OK:
|
||||||
if self.chooser(new.get_active()):
|
if new.get_active():
|
||||||
|
prompter = NewNativeDbPrompter(self.parent,self.parent_window)
|
||||||
|
else:
|
||||||
|
prompter = ExistingDbPrompter(self.parent,self.parent_window)
|
||||||
|
if prompter.chooser():
|
||||||
break
|
break
|
||||||
elif response == gtk.RESPONSE_CANCEL:
|
elif response == gtk.RESPONSE_CANCEL:
|
||||||
break
|
break
|
||||||
@ -89,17 +92,30 @@ class DbPrompter:
|
|||||||
if response == gtk.RESPONSE_CANCEL:
|
if response == gtk.RESPONSE_CANCEL:
|
||||||
gtk.main_quit()
|
gtk.main_quit()
|
||||||
|
|
||||||
def chooser(self,save):
|
#-------------------------------------------------------------------------
|
||||||
if save:
|
#
|
||||||
choose = gtk.FileChooserDialog(_('GRAMPS: Create database'),
|
# ExistingDbPrompter
|
||||||
self.parent_window,
|
#
|
||||||
gtk.FILE_CHOOSER_ACTION_SAVE,
|
#-------------------------------------------------------------------------
|
||||||
(gtk.STOCK_CANCEL,
|
class ExistingDbPrompter:
|
||||||
gtk.RESPONSE_CANCEL,
|
"""
|
||||||
gtk.STOCK_OPEN,
|
This class allows to open an existing database.
|
||||||
gtk.RESPONSE_OK))
|
|
||||||
self.parent.clear_database()
|
Any data format is allowed. The available formats are obtained
|
||||||
else:
|
from the plugins. If the selected format is non-native (non-grdb)
|
||||||
|
then the call is made to set up a new native grdb database.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self,parent,parent_window=None):
|
||||||
|
self.parent = parent
|
||||||
|
self.parent_window = parent_window
|
||||||
|
|
||||||
|
def chooser(self):
|
||||||
|
"""
|
||||||
|
Select the new file.
|
||||||
|
Return 1 when selection is made and 0 otherwise.
|
||||||
|
"""
|
||||||
choose = gtk.FileChooserDialog(_('GRAMPS: Open database'),
|
choose = gtk.FileChooserDialog(_('GRAMPS: Open database'),
|
||||||
self.parent_window,
|
self.parent_window,
|
||||||
gtk.FILE_CHOOSER_ACTION_OPEN,
|
gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||||
@ -120,13 +136,6 @@ class DbPrompter:
|
|||||||
filter.add_mime_type('application/x-gramps')
|
filter.add_mime_type('application/x-gramps')
|
||||||
choose.add_filter(filter)
|
choose.add_filter(filter)
|
||||||
|
|
||||||
if save:
|
|
||||||
# Set the suggested filename for the newly created file
|
|
||||||
if self.file_hint:
|
|
||||||
choose.set_filename(self.file_hint)
|
|
||||||
elif GrampsCfg.lastfile:
|
|
||||||
choose.set_filename(GrampsCfg.lastfile)
|
|
||||||
else:
|
|
||||||
# Add more data type selections if opening existing db
|
# Add more data type selections if opening existing db
|
||||||
for (importData,filter,mime_type) in Plugins._imports:
|
for (importData,filter,mime_type) in Plugins._imports:
|
||||||
choose.add_filter(filter)
|
choose.add_filter(filter)
|
||||||
@ -134,13 +143,6 @@ class DbPrompter:
|
|||||||
response = choose.run()
|
response = choose.run()
|
||||||
if response == gtk.RESPONSE_OK:
|
if response == gtk.RESPONSE_OK:
|
||||||
filename = choose.get_filename()
|
filename = choose.get_filename()
|
||||||
if save:
|
|
||||||
if os.path.splitext(filename)[1] != ".grdb":
|
|
||||||
filename = filename + ".grdb"
|
|
||||||
choose.destroy()
|
|
||||||
self.parent.read_file(filename)
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
filetype = gnome.vfs.get_mime_type(filename)
|
filetype = gnome.vfs.get_mime_type(filename)
|
||||||
if filetype == 'application/x-gramps':
|
if filetype == 'application/x-gramps':
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
@ -156,32 +158,119 @@ class DbPrompter:
|
|||||||
"following dialog will let you select "
|
"following dialog will let you select "
|
||||||
"the new database."),
|
"the new database."),
|
||||||
self.parent_window)
|
self.parent_window)
|
||||||
NewNativeDbPrompter(self.parent,self.parent_window,filename)
|
prompter = NewNativeDbPrompter(self.parent,self.parent_window)
|
||||||
|
if prompter.chooser():
|
||||||
importData(self.parent.db,filename)
|
importData(self.parent.db,filename)
|
||||||
self.parent.import_tool_callback()
|
self.parent.import_tool_callback()
|
||||||
return 1
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
QuestionDialog.ErrorDialog( _("Could not open file: %s") % filename,
|
QuestionDialog.ErrorDialog( _("Could not open file: %s") % filename,
|
||||||
_('The type "%s" is not in the list of known file types') % filetype )
|
_('The type "%s" is not in the list of known file types') % filetype )
|
||||||
|
return 0
|
||||||
|
|
||||||
else:
|
else:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# ImportDbPrompter
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
class ImportDbPrompter:
|
||||||
|
"""
|
||||||
|
This class allows to import a database. The data is imported into
|
||||||
|
the currently opened database, so we don't have to worry about
|
||||||
|
setting up the native database.
|
||||||
|
|
||||||
|
Any data format is allowed. The available formats are obtained
|
||||||
|
from the plugins.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self,parent,parent_window=None):
|
||||||
|
self.parent = parent
|
||||||
|
self.parent_window = parent_window
|
||||||
|
|
||||||
|
def chooser(self):
|
||||||
|
"""
|
||||||
|
Select the new file.
|
||||||
|
Return 1 when selection is made and 0 otherwise.
|
||||||
|
"""
|
||||||
|
choose = gtk.FileChooserDialog(_('GRAMPS: Import database'),
|
||||||
|
self.parent_window,
|
||||||
|
gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||||
|
(gtk.STOCK_CANCEL,
|
||||||
|
gtk.RESPONSE_CANCEL,
|
||||||
|
gtk.STOCK_OPEN,
|
||||||
|
gtk.RESPONSE_OK))
|
||||||
|
choose.set_local_only(gtk.FALSE)
|
||||||
|
# Always add automatic (macth all files) filter
|
||||||
|
filter = gtk.FileFilter()
|
||||||
|
filter.set_name(_('Automatic'))
|
||||||
|
filter.add_pattern('*')
|
||||||
|
choose.add_filter(filter)
|
||||||
|
|
||||||
|
# FIXME: Uncomment when we have grdb importer
|
||||||
|
#
|
||||||
|
# # Always add native format filter
|
||||||
|
# filter = gtk.FileFilter()
|
||||||
|
# filter.set_name(_('GRAMPS databases'))
|
||||||
|
# filter.add_mime_type('application/x-gramps')
|
||||||
|
# choose.add_filter(filter)
|
||||||
|
|
||||||
|
# Add more data type selections if opening existing db
|
||||||
|
for (importData,filter,mime_type) in Plugins._imports:
|
||||||
|
choose.add_filter(filter)
|
||||||
|
|
||||||
|
response = choose.run()
|
||||||
|
if response == gtk.RESPONSE_OK:
|
||||||
|
filename = choose.get_filename()
|
||||||
|
filetype = gnome.vfs.get_mime_type(filename)
|
||||||
|
# FIXME: Uncomment when we have grdb importer
|
||||||
|
#
|
||||||
|
# if filetype == 'application/x-gramps':
|
||||||
|
# choose.destroy()
|
||||||
|
# self.parent.read_file(filename)
|
||||||
|
# return 1
|
||||||
|
(junk,the_file) = os.path.split(filename)
|
||||||
|
for (importData,filter,mime_type) in Plugins._imports:
|
||||||
|
if filetype == mime_type or the_file == mime_type:
|
||||||
|
choose.destroy()
|
||||||
|
importData(self.parent.db,filename)
|
||||||
|
self.parent.import_tool_callback()
|
||||||
|
return 1
|
||||||
|
QuestionDialog.ErrorDialog( _("Could not open file: %s") % filename,
|
||||||
|
_('The type "%s" is not in the list of known file types') % filetype )
|
||||||
|
return 0
|
||||||
|
|
||||||
|
else:
|
||||||
|
choose.destroy()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# NewNativeDbPrompter
|
# NewNativeDbPrompter
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class NewNativeDbPrompter:
|
class NewNativeDbPrompter:
|
||||||
"""Set up a new empty native database."""
|
"""
|
||||||
|
This class allows to set up a new empty native (grdb) database.
|
||||||
|
The filename is forced to have an '.grdb' extension. If not given,
|
||||||
|
it is appended.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self,parent,parent_window=None,file_hint=None):
|
def __init__(self,parent,parent_window=None):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.parent_window = parent_window
|
self.parent_window = parent_window
|
||||||
self.file_hint = file_hint
|
|
||||||
self.chooser()
|
|
||||||
|
|
||||||
def chooser(self):
|
def chooser(self):
|
||||||
|
"""
|
||||||
|
Select the new file. Suggest the Untitled_X.grdb name.
|
||||||
|
Return 1 when selection is made and 0 otherwise.
|
||||||
|
"""
|
||||||
choose = gtk.FileChooserDialog(_('GRAMPS: Create GRAMPS database'),
|
choose = gtk.FileChooserDialog(_('GRAMPS: Create GRAMPS database'),
|
||||||
self.parent_window,
|
self.parent_window,
|
||||||
gtk.FILE_CHOOSER_ACTION_SAVE,
|
gtk.FILE_CHOOSER_ACTION_SAVE,
|
||||||
@ -203,10 +292,10 @@ class NewNativeDbPrompter:
|
|||||||
filter.add_mime_type('application/x-gramps')
|
filter.add_mime_type('application/x-gramps')
|
||||||
choose.add_filter(filter)
|
choose.add_filter(filter)
|
||||||
|
|
||||||
if self.file_hint:
|
new_filename = self.get_new_filename()
|
||||||
choose.set_filename(self.file_hint)
|
|
||||||
elif GrampsCfg.lastfile:
|
choose.set_filename(new_filename)
|
||||||
choose.set_filename(GrampsCfg.lastfile)
|
choose.set_current_name(os.path.split(new_filename)[1])
|
||||||
|
|
||||||
response = choose.run()
|
response = choose.run()
|
||||||
if response == gtk.RESPONSE_OK:
|
if response == gtk.RESPONSE_OK:
|
||||||
@ -219,3 +308,9 @@ class NewNativeDbPrompter:
|
|||||||
else:
|
else:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def get_new_filename(self):
|
||||||
|
ix = 1
|
||||||
|
while os.path.isfile(os.path.expanduser('~/Untitled_%d.grdb' % ix ) ):
|
||||||
|
ix = ix + 1
|
||||||
|
return os.path.expanduser('~/Untitled_%d.grdb' % ix )
|
||||||
|
@ -313,7 +313,6 @@ class Gramps:
|
|||||||
"on_home_clicked" : self.on_home_clicked,
|
"on_home_clicked" : self.on_home_clicked,
|
||||||
"on_new_clicked" : self.on_new_clicked,
|
"on_new_clicked" : self.on_new_clicked,
|
||||||
"on_notebook1_switch_page" : self.on_views_switch_page,
|
"on_notebook1_switch_page" : self.on_views_switch_page,
|
||||||
"on_ok_button1_clicked" : self.on_ok_button1_clicked,
|
|
||||||
"on_open_activate" : self.on_open_activate,
|
"on_open_activate" : self.on_open_activate,
|
||||||
"on_import_activate" : self.on_import_activate,
|
"on_import_activate" : self.on_import_activate,
|
||||||
"on_export_activate" : self.on_export_activate,
|
"on_export_activate" : self.on_export_activate,
|
||||||
@ -906,7 +905,9 @@ class Gramps:
|
|||||||
|
|
||||||
def on_new_clicked(self,obj):
|
def on_new_clicked(self,obj):
|
||||||
"""Prompt for permission to close the current database"""
|
"""Prompt for permission to close the current database"""
|
||||||
DbPrompter.DbPrompter(self,1,self.topWindow)
|
self.db.close()
|
||||||
|
prompter = DbPrompter.NewNativeDbPrompter(self,self.topWindow)
|
||||||
|
prompter.chooser()
|
||||||
|
|
||||||
def clear_database(self):
|
def clear_database(self):
|
||||||
"""Clear out the database if permission was granted"""
|
"""Clear out the database if permission was granted"""
|
||||||
@ -959,16 +960,6 @@ class Gramps:
|
|||||||
if self.active_person:
|
if self.active_person:
|
||||||
Plugins.ReportPlugins(self,self.db,self.active_person)
|
Plugins.ReportPlugins(self,self.db,self.active_person)
|
||||||
|
|
||||||
def on_ok_button1_clicked(self,obj):
|
|
||||||
filename = self.filesel.get_filename()
|
|
||||||
if filename == "" or filename == None:
|
|
||||||
return
|
|
||||||
filename = os.path.normpath(os.path.abspath(filename))
|
|
||||||
self.filesel.destroy()
|
|
||||||
self.clear_database()
|
|
||||||
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"""
|
||||||
try:
|
try:
|
||||||
@ -1096,14 +1087,6 @@ class Gramps:
|
|||||||
self.goto_active_person()
|
self.goto_active_person()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def on_ok_button2_clicked(self,obj):
|
|
||||||
filename = obj.get_filename()
|
|
||||||
filename = os.path.normpath(os.path.abspath(filename))
|
|
||||||
if filename:
|
|
||||||
Utils.destroy_passed_object(obj)
|
|
||||||
self.save_media(filename)
|
|
||||||
self.save_file(filename,_("No Comment Provided"))
|
|
||||||
|
|
||||||
def save_media(self,filename):
|
def save_media(self,filename):
|
||||||
import RelImage
|
import RelImage
|
||||||
missmedia_action = 0
|
missmedia_action = 0
|
||||||
@ -1202,53 +1185,6 @@ class Gramps:
|
|||||||
elif missmedia_action == 3:
|
elif missmedia_action == 3:
|
||||||
select_clicked()
|
select_clicked()
|
||||||
|
|
||||||
def save_file(self,filename,comment):
|
|
||||||
|
|
||||||
path = filename
|
|
||||||
filename = os.path.normpath(os.path.abspath(filename))
|
|
||||||
self.status_text(_("Saving %s ...") % filename)
|
|
||||||
|
|
||||||
if os.path.exists(filename):
|
|
||||||
if not os.path.isdir(filename):
|
|
||||||
DbPrompter.DbPrompter(self,0,self.topWindow)
|
|
||||||
self.displayError(_("Database could not be opened"),
|
|
||||||
_("%s is not a directory.") % filename + ' ' + \
|
|
||||||
_("You should select a directory that contains a "
|
|
||||||
"data.gramps file."))
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
os.mkdir(filename)
|
|
||||||
except (OSError,IOError), msg:
|
|
||||||
emsg = _("Could not create %s") % filename
|
|
||||||
ErrorDialog(emsg,_("An error was detected while attempting to create the file. ",
|
|
||||||
'The operating system reported "%s"' % str(msg)))
|
|
||||||
return
|
|
||||||
except:
|
|
||||||
ErrorDialog(_("Could not create %s") % filename,
|
|
||||||
_("An error was detected while trying to create the file"))
|
|
||||||
return
|
|
||||||
|
|
||||||
old_file = filename
|
|
||||||
filename = "%s/%s" % (filename,self.db.get_base())
|
|
||||||
try:
|
|
||||||
self.db.clear_added_media_objects()
|
|
||||||
except (OSError,IOError), msg:
|
|
||||||
emsg = _("Could not create %s") % filename
|
|
||||||
ErrorDialog(emsg,msg)
|
|
||||||
return
|
|
||||||
|
|
||||||
self.db.set_save_path(old_file)
|
|
||||||
GrampsCfg.save_last_file(old_file)
|
|
||||||
|
|
||||||
filename = self.db.get_save_path()
|
|
||||||
if filename[-1] == '/':
|
|
||||||
filename = filename[:-1]
|
|
||||||
name = os.path.basename(filename)
|
|
||||||
self.topWindow.set_title("%s - GRAMPS" % name)
|
|
||||||
self.status_text("")
|
|
||||||
self.statusbar.set_progress_percentage(0.0)
|
|
||||||
|
|
||||||
def load_selected_people(self,obj):
|
def load_selected_people(self,obj):
|
||||||
"""Display the selected people in the EditPerson display"""
|
"""Display the selected people in the EditPerson display"""
|
||||||
mlist = self.people_view.get_selected_objects()
|
mlist = self.people_view.get_selected_objects()
|
||||||
@ -1427,121 +1363,12 @@ class Gramps:
|
|||||||
self.filesel.destroy()
|
self.filesel.destroy()
|
||||||
|
|
||||||
def on_open_activate(self,obj):
|
def on_open_activate(self,obj):
|
||||||
|
prompter = DbPrompter.ExistingDbPrompter(self,self.topWindow)
|
||||||
choose = gtk.FileChooserDialog(_('GRAMPS: Open database'),
|
prompter.chooser()
|
||||||
self.topWindow,
|
|
||||||
gtk.FILE_CHOOSER_ACTION_OPEN,
|
|
||||||
(gtk.STOCK_CANCEL,
|
|
||||||
gtk.RESPONSE_CANCEL,
|
|
||||||
gtk.STOCK_OPEN,
|
|
||||||
gtk.RESPONSE_OK))
|
|
||||||
|
|
||||||
# Always add automatic (macth all files) filter
|
|
||||||
filter = gtk.FileFilter()
|
|
||||||
filter.set_name(_('Automatic'))
|
|
||||||
filter.add_pattern('*')
|
|
||||||
choose.add_filter(filter)
|
|
||||||
|
|
||||||
# Always add native format filter
|
|
||||||
filter = gtk.FileFilter()
|
|
||||||
filter.set_name(_('GRAMPS databases'))
|
|
||||||
filter.add_mime_type('application/x-gramps')
|
|
||||||
choose.add_filter(filter)
|
|
||||||
|
|
||||||
for (importData,filter,mime_type) in Plugins._imports:
|
|
||||||
choose.add_filter(filter)
|
|
||||||
|
|
||||||
if GrampsCfg.lastfile:
|
|
||||||
choose.set_filename(GrampsCfg.lastfile)
|
|
||||||
|
|
||||||
response = choose.run()
|
|
||||||
if response == gtk.RESPONSE_OK:
|
|
||||||
filename = choose.get_filename()
|
|
||||||
filename = os.path.normpath(os.path.abspath(filename))
|
|
||||||
self.clear_database()
|
|
||||||
filetype = gnome.vfs.get_mime_type(filename)
|
|
||||||
(junk,the_file) = os.path.split(filename)
|
|
||||||
|
|
||||||
if filetype == 'application/x-gramps':
|
|
||||||
if self.auto_save_load(filename) == 0:
|
|
||||||
DbPrompter.DbPrompter(self,0,self.topWindow)
|
|
||||||
else:
|
|
||||||
opened = 0
|
|
||||||
for (importData,filter,mime_type) in Plugins._imports:
|
|
||||||
if filetype == mime_type or the_file == mime_type:
|
|
||||||
OkDialog( _("Opening non-native format"),
|
|
||||||
_("New gramps database has to be set up "
|
|
||||||
"when opening non-native formats. The "
|
|
||||||
"following dialog will let you select "
|
|
||||||
"the new database."),
|
|
||||||
self.topWindow)
|
|
||||||
DbPrompter.NewNativeDbPrompter(self,self.topWindow,filename)
|
|
||||||
importData(self.db,filename)
|
|
||||||
self.import_tool_callback()
|
|
||||||
opened = 1
|
|
||||||
break
|
|
||||||
if not opened:
|
|
||||||
ErrorDialog( _("Could not open file: %s") % filename,
|
|
||||||
_('The type "%s" is not in the list of known file types') % filetype )
|
|
||||||
choose.destroy()
|
|
||||||
|
|
||||||
def on_import_activate(self,obj):
|
def on_import_activate(self,obj):
|
||||||
choose = gtk.FileChooserDialog(_('GRAMPS: Import database'),
|
prompter = DbPrompter.ImportDbPrompter(self,self.topWindow)
|
||||||
self.topWindow,
|
prompter.chooser()
|
||||||
gtk.FILE_CHOOSER_ACTION_OPEN,
|
|
||||||
(gtk.STOCK_CANCEL,
|
|
||||||
gtk.RESPONSE_CANCEL,
|
|
||||||
gtk.STOCK_OPEN,
|
|
||||||
gtk.RESPONSE_OK))
|
|
||||||
|
|
||||||
# Always add automatic (macth all files) filter
|
|
||||||
filter = gtk.FileFilter()
|
|
||||||
filter.set_name(_('Automatic'))
|
|
||||||
filter.add_pattern('*')
|
|
||||||
choose.add_filter(filter)
|
|
||||||
|
|
||||||
# FIXME: Uncomment when we have grdb importer
|
|
||||||
#
|
|
||||||
# # Always add native format filter
|
|
||||||
# filter = gtk.FileFilter()
|
|
||||||
# filter.set_name(_('GRAMPS databases'))
|
|
||||||
# filter.add_mime_type('application/x-gramps')
|
|
||||||
# choose.add_filter(filter)
|
|
||||||
|
|
||||||
for (importData,filter,mime_type) in Plugins._imports:
|
|
||||||
choose.add_filter(filter)
|
|
||||||
|
|
||||||
if GrampsCfg.lastfile:
|
|
||||||
choose.set_filename(GrampsCfg.lastfile)
|
|
||||||
|
|
||||||
response = choose.run()
|
|
||||||
if response == gtk.RESPONSE_OK:
|
|
||||||
filename = choose.get_filename()
|
|
||||||
filename = os.path.normpath(os.path.abspath(filename))
|
|
||||||
filetype = gnome.vfs.get_mime_type(filename)
|
|
||||||
(junk,the_file) = os.path.split(filename)
|
|
||||||
|
|
||||||
# FIXME: Uncomment when we have grdb importer
|
|
||||||
#
|
|
||||||
# if filetype == 'application/x-gramps':
|
|
||||||
# if self.auto_save_load(filename) == 0:
|
|
||||||
# DbPrompter.DbPrompter(self,0,self.topWindow)
|
|
||||||
# else:
|
|
||||||
if True:
|
|
||||||
opened = 0
|
|
||||||
for (importData,filter,mime_type) in Plugins._imports:
|
|
||||||
if filetype == mime_type or the_file == mime_type:
|
|
||||||
print mime_type
|
|
||||||
print "Keys before:", self.db.get_person_keys()
|
|
||||||
importData(self.db,filename)
|
|
||||||
self.import_tool_callback()
|
|
||||||
opened = 1
|
|
||||||
print "Keys after:", self.db.get_person_keys()
|
|
||||||
break
|
|
||||||
if not opened:
|
|
||||||
ErrorDialog( _("Could not open file: %s") % filename,
|
|
||||||
_('The type "%s" is not in the list of known file types') % filetype )
|
|
||||||
choose.destroy()
|
|
||||||
|
|
||||||
def on_export_activate(self,obj):
|
def on_export_activate(self,obj):
|
||||||
choose = gtk.FileChooserDialog(_('GRAMPS: Export database'),
|
choose = gtk.FileChooserDialog(_('GRAMPS: Export database'),
|
||||||
|
Reference in New Issue
Block a user