2006-05-18 02:46:59 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-06-02 11:21:39 +05:30
|
|
|
# Copyright (C) 2005-2007 Donald N. Allingham
|
2006-05-18 02:46:59 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2008-02-18 15:39:50 +05:30
|
|
|
# $Id:DbLoader.py 9912 2008-01-22 09:17:46Z acraphae $
|
2006-05-18 02:46:59 +05:30
|
|
|
|
|
|
|
"""
|
|
|
|
Handling of loading new/existing databases.
|
|
|
|
"""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
|
|
|
from gettext import gettext as _
|
|
|
|
import logging
|
2007-05-20 10:05:46 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-06-02 11:21:39 +05:30
|
|
|
_LOG = logging.getLogger(".")
|
2006-05-18 02:46:59 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK+ modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
2008-01-22 04:24:18 +05:30
|
|
|
import gobject
|
2006-05-18 02:46:59 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
|
|
|
import Config
|
|
|
|
import Mime
|
2007-10-07 08:49:35 +05:30
|
|
|
import gen.db
|
2007-02-03 22:41:05 +05:30
|
|
|
import GrampsDbUtils
|
2006-05-18 02:46:59 +05:30
|
|
|
import Utils
|
|
|
|
from PluginUtils import import_list
|
2008-02-18 15:39:50 +05:30
|
|
|
from QuestionDialog import (DBErrorDialog, ErrorDialog, QuestionDialog2,
|
|
|
|
WarningDialog)
|
2007-06-13 07:57:31 +05:30
|
|
|
import Errors
|
2006-05-18 02:46:59 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
_KNOWN_FORMATS = {
|
2007-09-08 11:24:02 +05:30
|
|
|
const.APP_GRAMPS : _('GRAMPS (grdb)'),
|
|
|
|
const.APP_GRAMPS_XML : _('GRAMPS XML'),
|
|
|
|
const.APP_GEDCOM : _('GEDCOM'),
|
2006-05-18 02:46:59 +05:30
|
|
|
}
|
|
|
|
|
2007-09-08 11:24:02 +05:30
|
|
|
OPEN_FORMATS = [const.APP_GRAMPS_XML, const.APP_GEDCOM]
|
2007-05-20 10:05:46 +05:30
|
|
|
|
2006-05-18 02:46:59 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# DbLoader class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class DbLoader:
|
2007-05-20 10:05:46 +05:30
|
|
|
def __init__(self, dbstate, uistate):
|
2006-05-18 02:46:59 +05:30
|
|
|
self.dbstate = dbstate
|
|
|
|
self.uistate = uistate
|
|
|
|
|
2006-05-18 05:06:31 +05:30
|
|
|
def import_file(self):
|
|
|
|
# First thing first: import is a batch transaction
|
|
|
|
# so we will lose the undo history. Warn the user.
|
2007-04-02 09:26:30 +05:30
|
|
|
|
|
|
|
if self.dbstate.db.get_number_of_people() > 0:
|
2008-02-18 15:39:50 +05:30
|
|
|
warn_dialog = QuestionDialog2(
|
2007-04-02 09:26:30 +05:30
|
|
|
_('Undo history warning'),
|
|
|
|
_('Proceeding with import will erase the undo history '
|
|
|
|
'for this session. In particular, you will not be able '
|
|
|
|
'to revert the import or any changes made prior to it.\n\n'
|
|
|
|
'If you think you may want to revert the import, '
|
|
|
|
'please stop here and backup your database.'),
|
|
|
|
_('_Proceed with import'), _('_Stop'),
|
|
|
|
self.uistate.window)
|
|
|
|
if not warn_dialog.run():
|
|
|
|
return False
|
2007-11-12 21:14:15 +05:30
|
|
|
|
2008-02-18 18:01:31 +05:30
|
|
|
choose_db_dialog = gtk.FileChooserDialog(_('GRAMPS: Import database'),
|
|
|
|
self.uistate.window,
|
|
|
|
gtk.FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
|
|
|
'gramps-import', gtk.RESPONSE_OK))
|
|
|
|
choose_db_dialog.set_local_only(False)
|
2006-05-18 05:06:31 +05:30
|
|
|
|
2008-01-15 04:33:16 +05:30
|
|
|
# Always add automatic (match all files) filter
|
2008-02-18 18:01:31 +05:30
|
|
|
add_all_files_filter(choose_db_dialog)
|
|
|
|
add_grdb_filter(choose_db_dialog)
|
|
|
|
add_xml_filter(choose_db_dialog)
|
|
|
|
add_gedcom_filter(choose_db_dialog)
|
2006-05-18 05:06:31 +05:30
|
|
|
|
2007-06-04 22:41:49 +05:30
|
|
|
format_list = OPEN_FORMATS[:]
|
2006-05-18 05:06:31 +05:30
|
|
|
|
|
|
|
# Add more data type selections if opening existing db
|
|
|
|
for data in import_list:
|
|
|
|
mime_filter = data[1]
|
|
|
|
mime_type = data[2]
|
|
|
|
native_format = data[3]
|
|
|
|
format_name = data[4]
|
|
|
|
|
|
|
|
if not native_format:
|
2008-02-18 18:01:31 +05:30
|
|
|
choose_db_dialog.add_filter(mime_filter)
|
2006-05-18 05:06:31 +05:30
|
|
|
format_list.append(mime_type)
|
|
|
|
_KNOWN_FORMATS[mime_type] = format_name
|
|
|
|
|
|
|
|
(box, type_selector) = format_maker(format_list)
|
2008-02-18 18:01:31 +05:30
|
|
|
choose_db_dialog.set_extra_widget(box)
|
2006-05-18 05:06:31 +05:30
|
|
|
|
|
|
|
# Suggested folder: try last open file, import, then last export,
|
|
|
|
# then home.
|
|
|
|
default_dir = Config.get(Config.RECENT_IMPORT_DIR)
|
|
|
|
if len(default_dir)<=1:
|
2006-05-18 06:32:52 +05:30
|
|
|
default_dir = get_default_dir()
|
2006-05-18 05:06:31 +05:30
|
|
|
|
2008-02-18 18:01:31 +05:30
|
|
|
choose_db_dialog.set_current_folder(default_dir)
|
2008-02-20 10:29:52 +05:30
|
|
|
while True:
|
|
|
|
response = choose_db_dialog.run()
|
|
|
|
if response == gtk.RESPONSE_CANCEL:
|
|
|
|
break
|
|
|
|
elif response == gtk.RESPONSE_OK:
|
|
|
|
filename = Utils.get_unicode_path(choose_db_dialog.get_filename())
|
|
|
|
if self.check_errors(filename):
|
|
|
|
# displays errors if any
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Do not allow importing from the currently open file
|
|
|
|
if filename == self.dbstate.db.full_name:
|
|
|
|
ErrorDialog(_("Cannot import from current file"))
|
|
|
|
continue
|
|
|
|
|
|
|
|
filetype = type_selector.get_value()
|
|
|
|
if filetype == 'auto':
|
|
|
|
try:
|
|
|
|
filetype = Mime.get_type(filename)
|
|
|
|
except RuntimeError, msg:
|
|
|
|
ErrorDialog(_("Could not open file: %s") % filename,
|
|
|
|
str(msg))
|
|
|
|
continue
|
|
|
|
|
|
|
|
# First we try our best formats
|
|
|
|
if filetype in OPEN_FORMATS:
|
|
|
|
importer = GrampsDbUtils.gramps_db_reader_factory(filetype)
|
|
|
|
self.do_import(choose_db_dialog, importer, filename)
|
2006-05-18 05:06:31 +05:30
|
|
|
return True
|
|
|
|
|
2008-02-20 10:29:52 +05:30
|
|
|
# Then we try all the known plugins
|
|
|
|
(the_path, the_file) = os.path.split(filename)
|
|
|
|
Config.set(Config.RECENT_IMPORT_DIR, the_path)
|
|
|
|
for (importData, mime_filter, mime_type, native_format,
|
|
|
|
format_name) in import_list:
|
|
|
|
if filetype == mime_type or the_file == mime_type:
|
|
|
|
self.do_import(choose_db_dialog, importData, filename)
|
|
|
|
return True
|
|
|
|
|
|
|
|
# Finally, we give up and declare this an unknown format
|
|
|
|
ErrorDialog(
|
|
|
|
_("Could not open file: %s") % filename,
|
|
|
|
_('File type "%s" is unknown to GRAMPS.\n\n'
|
|
|
|
'Valid types are: GRAMPS database, GRAMPS XML, '
|
|
|
|
'GRAMPS package, and GEDCOM.') % filetype)
|
2006-05-18 05:06:31 +05:30
|
|
|
|
2008-02-18 18:01:31 +05:30
|
|
|
choose_db_dialog.destroy()
|
2006-05-18 05:06:31 +05:30
|
|
|
return False
|
|
|
|
|
2007-05-20 10:05:46 +05:30
|
|
|
def check_errors(self, filename):
|
2006-05-18 02:46:59 +05:30
|
|
|
"""
|
2008-02-18 18:01:31 +05:30
|
|
|
Run common error checks and return True if any found.
|
|
|
|
|
|
|
|
In this process, a warning dialog can pop up.
|
|
|
|
|
2006-05-18 02:46:59 +05:30
|
|
|
"""
|
|
|
|
|
2007-05-20 10:05:46 +05:30
|
|
|
if type(filename) not in (str, unicode):
|
2006-05-18 02:46:59 +05:30
|
|
|
return True
|
|
|
|
|
|
|
|
filename = os.path.normpath(os.path.abspath(filename))
|
|
|
|
|
|
|
|
if len(filename) == 0:
|
|
|
|
return True
|
|
|
|
elif os.path.isdir(filename):
|
2008-02-18 15:39:50 +05:30
|
|
|
ErrorDialog(
|
2006-05-18 02:46:59 +05:30
|
|
|
_('Cannot open database'),
|
|
|
|
_('The selected file is a directory, not '
|
|
|
|
'a file.\nA GRAMPS database must be a file.'))
|
|
|
|
return True
|
|
|
|
elif os.path.exists(filename):
|
|
|
|
if not os.access(filename, os.R_OK):
|
2008-02-18 15:39:50 +05:30
|
|
|
ErrorDialog(
|
2006-05-18 02:46:59 +05:30
|
|
|
_('Cannot open database'),
|
|
|
|
_('You do not have read access to the selected '
|
|
|
|
'file.'))
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
f = file(filename,'w')
|
|
|
|
f.close()
|
|
|
|
os.remove(filename)
|
|
|
|
except IOError:
|
2008-02-18 15:39:50 +05:30
|
|
|
ErrorDialog(
|
2006-05-18 02:46:59 +05:30
|
|
|
_('Cannot create database'),
|
|
|
|
_('You do not have write access to the selected file.'))
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
def read_file(self, filename):
|
2006-05-18 02:46:59 +05:30
|
|
|
"""
|
2006-05-18 06:32:52 +05:30
|
|
|
This method takes care of changing database, and loading the data.
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
In 3.0 we only allow reading of real databases of filetype
|
|
|
|
'x-directory/normal'
|
2006-05-18 02:46:59 +05:30
|
|
|
|
|
|
|
This method should only return on success.
|
|
|
|
Returning on failure makes no sense, because we cannot recover,
|
|
|
|
since database has already beeen changed.
|
|
|
|
Therefore, any errors should raise exceptions.
|
|
|
|
|
2006-05-18 06:32:52 +05:30
|
|
|
On success, return with the disabled signals. The post-load routine
|
2006-05-18 02:46:59 +05:30
|
|
|
should enable signals, as well as finish up with other UI goodies.
|
|
|
|
"""
|
|
|
|
|
2006-09-24 10:07:59 +05:30
|
|
|
if os.path.exists(filename):
|
|
|
|
if not os.access(filename, os.W_OK):
|
|
|
|
mode = "r"
|
2008-02-18 15:39:50 +05:30
|
|
|
WarningDialog(_('Read only database'),
|
2006-09-24 10:07:59 +05:30
|
|
|
_('You do not have write access '
|
|
|
|
'to the selected file.'))
|
|
|
|
else:
|
|
|
|
mode = "w"
|
2006-05-18 02:46:59 +05:30
|
|
|
else:
|
2006-09-24 10:07:59 +05:30
|
|
|
mode = 'w'
|
2006-05-18 02:46:59 +05:30
|
|
|
|
2007-12-28 Benny Malengier <benny.malengier@gramps-project.org>
* src/ViewManager.py: remove unused functions, add alt actions left/right
* src/GrampsDb: deleted with _GrampsDbWriteXML.py,
_GrampsDbFactories.py, _GrampsGEDDB.py, _GrampsXMLDB.py,
__init__.py, Makefile.am, _GrampsInMemDB.py, _GrampsBSDDB.py.
No more inmemory databases
* src/GrampsDbUtils: moved here _GrampsDbWriteXML.py and _GrampsBSDDB.py
* src/plugins/ReadGrdb.py:
* src/plugins/Checkpoint.py:
* src/ObjectSelector/_ObjectSelectorWindow.py:
* src/DbManager.py:
* src/GrampsDbUtils/_WriteGrdb.py:
* src/GrampsDbUtils/__init__.py:
* src/GrampsDbUtils/_GrampsDbWRFactories.py:
* src/GrampsDbUtils/_WriteXML.py:
* src/GrampsDbUtils/Makefile.am:
* src/gramps_main.py:
* src/RecentFiles.py: recent-files-gramps.xml, don't overwrite 2.2.x data
* src/ArgHandler.py:
* src/DbLoader.py: remove unused functions
* src/Makefile.am:
* po/POTFILES.in:
* src/GrampsDbUtils/importdbdir.py: allow import of new database via cli
Remove inMem Editing, move remaining to DbUtils, fix ArgHandler
svn: r9613
2007-12-28 20:39:01 +05:30
|
|
|
dbclass = gen.db.GrampsDBDir
|
2006-09-24 10:07:59 +05:30
|
|
|
|
|
|
|
self.dbstate.change_database(dbclass(Config.get(Config.TRANSACTIONS)))
|
2006-05-18 02:46:59 +05:30
|
|
|
self.dbstate.db.disable_signals()
|
|
|
|
|
2006-05-18 05:06:31 +05:30
|
|
|
self.uistate.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
|
|
|
self.uistate.progress.show()
|
|
|
|
|
2006-05-18 02:46:59 +05:30
|
|
|
try:
|
2007-05-20 10:05:46 +05:30
|
|
|
self.dbstate.db.load(filename, self.uistate.pulse_progressbar, mode)
|
2006-09-24 10:07:59 +05:30
|
|
|
self.dbstate.db.set_save_path(filename)
|
2007-05-15 09:47:12 +05:30
|
|
|
except OSError, msg:
|
2008-02-18 15:39:50 +05:30
|
|
|
ErrorDialog(
|
2007-05-20 10:05:46 +05:30
|
|
|
_("Could not open file: %s") % filename, str(msg))
|
2007-06-13 07:57:31 +05:30
|
|
|
except Errors.DbError, msg:
|
2008-02-18 15:39:50 +05:30
|
|
|
DBErrorDialog(str(msg.value))
|
2008-01-02 16:41:27 +05:30
|
|
|
self.dbstate.no_database()
|
2006-05-18 02:46:59 +05:30
|
|
|
except Exception:
|
2007-06-02 11:21:39 +05:30
|
|
|
_LOG.error("Failed to open database.", exc_info=True)
|
2006-09-24 10:07:59 +05:30
|
|
|
return True
|
2006-05-18 05:06:31 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def do_import(self, dialog, importer, filename):
|
|
|
|
dialog.destroy()
|
|
|
|
self.uistate.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
|
|
|
self.uistate.progress.show()
|
2006-05-18 06:32:52 +05:30
|
|
|
|
|
|
|
try:
|
|
|
|
importer(self.dbstate.db, filename, self.uistate.pulse_progressbar)
|
|
|
|
dirname = os.path.dirname(filename) + os.path.sep
|
2007-05-20 10:05:46 +05:30
|
|
|
Config.set(Config.RECENT_IMPORT_DIR, dirname)
|
2007-07-31 09:53:30 +05:30
|
|
|
except UnicodeError, msg:
|
2008-02-18 15:39:50 +05:30
|
|
|
ErrorDialog(
|
2007-07-31 09:53:30 +05:30
|
|
|
_("Could not import file: %s") % filename,
|
|
|
|
_("This GEDCOM file incorrectly identifies its character "
|
|
|
|
"set, so it cannot be accurately imported. Please fix the "
|
|
|
|
"encoding, and import again") + "\n\n %s" % msg)
|
2006-05-18 06:32:52 +05:30
|
|
|
except Exception:
|
2007-06-02 11:21:39 +05:30
|
|
|
_LOG.error("Failed to import database.", exc_info=True)
|
2006-05-18 06:32:52 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# default dir selection
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def get_default_dir():
|
|
|
|
# Suggested folder: try last open file, last import, last export,
|
|
|
|
# then home.
|
2006-11-20 08:59:16 +05:30
|
|
|
default_dir = os.path.dirname(Config.get(Config.RECENT_FILE))
|
|
|
|
if default_dir:
|
|
|
|
default_dir += os.path.sep
|
|
|
|
if len(default_dir)<=1:
|
|
|
|
default_dir = Config.get(Config.RECENT_IMPORT_DIR)
|
|
|
|
if len(default_dir)<=1:
|
|
|
|
default_dir = Config.get(Config.RECENT_EXPORT_DIR)
|
|
|
|
if len(default_dir)<=1:
|
|
|
|
default_dir = '~/'
|
|
|
|
else:
|
|
|
|
default_dir = "~/"
|
2006-05-18 06:32:52 +05:30
|
|
|
return default_dir
|
2006-05-18 05:06:31 +05:30
|
|
|
|
2006-05-18 02:46:59 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# FileChooser filters: what to show in the file chooser
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def add_all_files_filter(chooser):
|
|
|
|
"""
|
|
|
|
Add an all-permitting filter to the file chooser dialog.
|
|
|
|
"""
|
|
|
|
mime_filter = gtk.FileFilter()
|
|
|
|
mime_filter.set_name(_('All files'))
|
|
|
|
mime_filter.add_pattern('*')
|
|
|
|
chooser.add_filter(mime_filter)
|
|
|
|
|
|
|
|
def add_gramps_files_filter(chooser):
|
|
|
|
"""
|
|
|
|
Add an all-GRAMPS filter to the file chooser dialog.
|
|
|
|
"""
|
|
|
|
mime_filter = gtk.FileFilter()
|
|
|
|
mime_filter.set_name(_('All GRAMPS files'))
|
2007-06-04 08:19:31 +05:30
|
|
|
for fmt in OPEN_FORMATS:
|
2007-05-20 10:05:46 +05:30
|
|
|
mime_filter.add_mime_type(fmt)
|
2006-05-18 02:46:59 +05:30
|
|
|
chooser.add_filter(mime_filter)
|
|
|
|
|
|
|
|
def add_grdb_filter(chooser):
|
|
|
|
"""
|
|
|
|
Add a GRDB filter to the file chooser dialog.
|
|
|
|
"""
|
|
|
|
mime_filter = gtk.FileFilter()
|
|
|
|
mime_filter.set_name(_('GRAMPS databases'))
|
2007-09-08 11:24:02 +05:30
|
|
|
mime_filter.add_mime_type(const.APP_GRAMPS)
|
2006-05-18 02:46:59 +05:30
|
|
|
chooser.add_filter(mime_filter)
|
|
|
|
|
|
|
|
def add_xml_filter(chooser):
|
|
|
|
"""
|
|
|
|
Add a GRAMPS XML filter to the file chooser dialog.
|
|
|
|
"""
|
|
|
|
mime_filter = gtk.FileFilter()
|
|
|
|
mime_filter.set_name(_('GRAMPS XML databases'))
|
2007-09-08 11:24:02 +05:30
|
|
|
mime_filter.add_mime_type(const.APP_GRAMPS_XML)
|
2006-05-18 02:46:59 +05:30
|
|
|
chooser.add_filter(mime_filter)
|
|
|
|
|
|
|
|
def add_gedcom_filter(chooser):
|
|
|
|
"""
|
|
|
|
Add a GEDCOM filter to the file chooser dialog.
|
|
|
|
"""
|
|
|
|
mime_filter = gtk.FileFilter()
|
|
|
|
mime_filter.set_name(_('GEDCOM files'))
|
2007-09-08 11:24:02 +05:30
|
|
|
mime_filter.add_mime_type(const.APP_GEDCOM)
|
2006-05-18 02:46:59 +05:30
|
|
|
chooser.add_filter(mime_filter)
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Format selectors: explictly set the format of the file
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class GrampsFormatWidget(gtk.ComboBox):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
gtk.ComboBox.__init__(self, model=None)
|
|
|
|
|
|
|
|
def set(self, format_list):
|
2008-01-22 03:33:43 +05:30
|
|
|
self.store = gtk.ListStore(gobject.TYPE_STRING)
|
2006-05-18 02:46:59 +05:30
|
|
|
self.set_model(self.store)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
self.pack_start(cell, True)
|
|
|
|
self.add_attribute(cell, 'text', 0)
|
|
|
|
self.format_list = format_list
|
|
|
|
|
|
|
|
for format, label in format_list:
|
|
|
|
self.store.append(row=[label])
|
|
|
|
self.set_active(False)
|
|
|
|
|
|
|
|
def get_value(self):
|
|
|
|
active = self.get_active()
|
|
|
|
if active < 0:
|
|
|
|
return None
|
|
|
|
return self.format_list[active][0]
|
|
|
|
|
|
|
|
def format_maker(formats):
|
|
|
|
"""
|
|
|
|
A factory function making format selection widgets.
|
|
|
|
|
|
|
|
Accepts a list of formats to include into selector.
|
|
|
|
The auto selection is always added as the first one.
|
|
|
|
The returned box contains both the label and the selector.
|
|
|
|
"""
|
|
|
|
format_list = [ ('auto', _('Automatically detected')) ]
|
|
|
|
for format in formats:
|
|
|
|
if _KNOWN_FORMATS.has_key(format):
|
|
|
|
format_list.append( (format, _KNOWN_FORMATS[format]) )
|
|
|
|
|
|
|
|
type_selector = GrampsFormatWidget()
|
|
|
|
type_selector.set(format_list)
|
|
|
|
|
|
|
|
box = gtk.HBox()
|
|
|
|
label = gtk.Label(_('Select file _type:'))
|
|
|
|
label.set_use_underline(True)
|
|
|
|
label.set_mnemonic_widget(type_selector)
|
|
|
|
box.pack_start(label, expand=False, fill=False, padding=6)
|
|
|
|
box.add(type_selector)
|
|
|
|
box.show_all()
|
|
|
|
return (box, type_selector)
|