2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2005-01-09 03:22:57 +05:30
|
|
|
# Copyright (C) 2000-2005 Donald N. Allingham
|
2002-10-20 19:55:16 +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
|
|
|
|
#
|
|
|
|
|
2003-12-06 05:44:25 +05:30
|
|
|
# $Id$
|
|
|
|
|
2004-06-21 10:40:27 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
|
|
|
from gettext import gettext as _
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
2004-05-08 10:18:59 +05:30
|
|
|
import gobject
|
2004-06-21 10:40:27 +05:30
|
|
|
import gnome
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-27 08:48:21 +05:30
|
|
|
try:
|
|
|
|
from gnomevfs import get_mime_type
|
|
|
|
except:
|
|
|
|
from gnome.vfs import get_mime_type
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import Utils
|
|
|
|
import const
|
2004-05-08 10:18:59 +05:30
|
|
|
import QuestionDialog
|
2005-01-05 10:32:19 +05:30
|
|
|
import PluginMgr
|
2004-08-01 09:51:31 +05:30
|
|
|
import GrampsBSDDB
|
|
|
|
import GrampsXMLDB
|
|
|
|
import GrampsGEDDB
|
2005-01-06 22:58:31 +05:30
|
|
|
import GrampsKeys
|
2004-11-25 11:12:31 +05:30
|
|
|
import RecentFiles
|
2005-01-31 05:23:47 +05:30
|
|
|
import ReadGrdb
|
|
|
|
import WriteGrdb
|
|
|
|
import WriteXML
|
|
|
|
import WriteGedcom
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-02-25 21:35:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
_KNOWN_FORMATS = {
|
|
|
|
const.app_gramps : _('GRAMPS (grdb)'),
|
|
|
|
const.app_gramps_xml : _('GRAMPS XML'),
|
|
|
|
const.app_gedcom : _('GEDCOM'),
|
|
|
|
}
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# DbPrompter
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class DbPrompter:
|
|
|
|
"""Make sure a database is opened"""
|
|
|
|
|
2004-06-28 23:46:42 +05:30
|
|
|
def __init__(self,parent,want_new,parent_window=None):
|
2004-06-21 10:40:27 +05:30
|
|
|
self.parent = parent
|
2004-06-28 18:49:06 +05:30
|
|
|
self.parent_window = parent_window
|
2003-08-17 07:44:33 +05:30
|
|
|
opendb = gtk.glade.XML(const.gladeFile, "opendb","gramps")
|
2003-03-06 11:42:51 +05:30
|
|
|
top = opendb.get_widget('opendb')
|
2004-06-21 10:40:27 +05:30
|
|
|
if parent_window:
|
|
|
|
top.set_transient_for(parent_window)
|
2003-03-06 11:42:51 +05:30
|
|
|
title = opendb.get_widget('title')
|
2003-03-05 11:31:31 +05:30
|
|
|
|
2003-03-06 11:42:51 +05:30
|
|
|
Utils.set_titles(top,title,_('Open a database'))
|
2004-05-05 09:24:02 +05:30
|
|
|
|
2004-05-08 10:18:59 +05:30
|
|
|
new = opendb.get_widget("new")
|
|
|
|
new.set_active(want_new)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-05-08 10:18:59 +05:30
|
|
|
while 1:
|
2004-08-29 11:15:40 +05:30
|
|
|
top.show()
|
2004-05-08 10:18:59 +05:30
|
|
|
response = top.run()
|
2004-08-29 11:15:40 +05:30
|
|
|
top.hide()
|
2004-05-08 10:18:59 +05:30
|
|
|
if response == gtk.RESPONSE_OK:
|
2004-06-28 23:46:42 +05:30
|
|
|
if new.get_active():
|
2005-02-24 07:10:40 +05:30
|
|
|
prompter = NewNativeDbPrompter(self.parent,
|
|
|
|
self.parent_window)
|
2004-06-28 23:46:42 +05:30
|
|
|
else:
|
2005-02-24 07:10:40 +05:30
|
|
|
prompter = ExistingDbPrompter(self.parent,
|
|
|
|
self.parent_window)
|
2004-06-28 23:46:42 +05:30
|
|
|
if prompter.chooser():
|
2004-05-08 10:18:59 +05:30
|
|
|
break
|
|
|
|
elif response == gtk.RESPONSE_CANCEL:
|
|
|
|
break
|
|
|
|
elif response == gtk.RESPONSE_HELP:
|
|
|
|
try:
|
|
|
|
gnome.help_display('gramps-manual','choose-db-start')
|
|
|
|
except gobject.GError,msg:
|
|
|
|
QuestionDialog.ErrorDialog(_('Help not available'),msg)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-05-08 10:18:59 +05:30
|
|
|
top.destroy()
|
|
|
|
if response == gtk.RESPONSE_CANCEL:
|
|
|
|
gtk.main_quit()
|
2003-12-06 05:44:25 +05:30
|
|
|
|
2004-06-28 23:46:42 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# ExistingDbPrompter
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class ExistingDbPrompter:
|
|
|
|
"""
|
|
|
|
This class allows to open an existing database.
|
|
|
|
|
|
|
|
Any data format is allowed. The available formats are obtained
|
|
|
|
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'),
|
2004-06-28 18:49:06 +05:30
|
|
|
self.parent_window,
|
2004-05-08 10:18:59 +05:30
|
|
|
gtk.FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
(gtk.STOCK_CANCEL,
|
|
|
|
gtk.RESPONSE_CANCEL,
|
|
|
|
gtk.STOCK_OPEN,
|
|
|
|
gtk.RESPONSE_OK))
|
2005-02-24 05:55:34 +05:30
|
|
|
choose.set_local_only(False)
|
2005-02-26 08:04:11 +05:30
|
|
|
|
2004-06-28 18:49:06 +05:30
|
|
|
# Always add automatic (macth all files) filter
|
2005-02-26 08:04:11 +05:30
|
|
|
add_all_files_filter(choose)
|
|
|
|
add_grdb_filter(choose)
|
|
|
|
add_xml_filter(choose)
|
|
|
|
add_gedcom_filter(choose)
|
2004-06-28 18:49:06 +05:30
|
|
|
|
2005-02-26 08:04:11 +05:30
|
|
|
format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom]
|
2004-06-28 23:46:42 +05:30
|
|
|
# Add more data type selections if opening existing db
|
2005-02-28 07:21:21 +05:30
|
|
|
for (importData,mime_filter,mime_type,native_format,format_name) in PluginMgr.import_list:
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
if not native_format:
|
|
|
|
choose.add_filter(mime_filter)
|
2005-02-26 08:04:11 +05:30
|
|
|
format_list.append(mime_type)
|
2005-02-28 07:21:21 +05:30
|
|
|
_KNOWN_FORMATS[mime_type] = format_name
|
2004-06-28 18:49:06 +05:30
|
|
|
|
2005-02-26 08:04:11 +05:30
|
|
|
(box,type_selector) = format_maker(format_list)
|
|
|
|
choose.set_extra_widget(box)
|
|
|
|
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
# Suggested folder: try last open file, last import, last export,
|
|
|
|
# then home.
|
2005-01-06 22:58:31 +05:30
|
|
|
default_dir = os.path.split(GrampsKeys.get_lastfile())[0] + os.path.sep
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
if len(default_dir)<=1:
|
2005-01-06 22:58:31 +05:30
|
|
|
default_dir = GrampsKeys.get_last_import_dir()
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
if len(default_dir)<=1:
|
2005-01-06 22:58:31 +05:30
|
|
|
default_dir = GrampsKeys.get_last_export_dir()
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
if len(default_dir)<=1:
|
|
|
|
default_dir = '~/'
|
|
|
|
|
|
|
|
choose.set_current_folder(default_dir)
|
2004-06-28 18:49:06 +05:30
|
|
|
response = choose.run()
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
filename = choose.get_filename()
|
2005-02-24 07:10:40 +05:30
|
|
|
if len(filename) == 0:
|
|
|
|
return False
|
2005-02-26 08:04:11 +05:30
|
|
|
filetype = type_selector.get_value()
|
|
|
|
if filetype == 'auto':
|
|
|
|
filetype = get_mime_type(filename)
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
(the_path,the_file) = os.path.split(filename)
|
2004-11-30 07:46:30 +05:30
|
|
|
choose.destroy()
|
2005-02-24 07:10:40 +05:30
|
|
|
try:
|
|
|
|
if open_native(self.parent,filename,filetype):
|
|
|
|
return True
|
|
|
|
except:
|
|
|
|
QuestionDialog.ErrorDialog(
|
|
|
|
_("Could not open file: %s") % filename)
|
|
|
|
return False
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
|
|
|
|
# The above native formats did not work, so we need to
|
|
|
|
# look up the importer for this format
|
|
|
|
# and create an empty native database to import data in
|
2005-02-28 07:21:21 +05:30
|
|
|
for (importData,mime_filter,mime_type,native_format,format_name) in PluginMgr.import_list:
|
2004-06-28 23:46:42 +05:30
|
|
|
if filetype == mime_type or the_file == mime_type:
|
2004-12-05 09:45:48 +05:30
|
|
|
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_window)
|
2004-06-28 23:46:42 +05:30
|
|
|
prompter = NewNativeDbPrompter(self.parent,self.parent_window)
|
|
|
|
if prompter.chooser():
|
2004-06-28 18:49:06 +05:30
|
|
|
importData(self.parent.db,filename)
|
|
|
|
self.parent.import_tool_callback()
|
2004-10-08 09:29:55 +05:30
|
|
|
return True
|
2004-06-28 23:46:42 +05:30
|
|
|
else:
|
2004-10-08 09:29:55 +05:30
|
|
|
return False
|
2004-12-05 09:45:48 +05:30
|
|
|
QuestionDialog.ErrorDialog(
|
|
|
|
_("Could not open file: %s") % filename,
|
|
|
|
_('The type "%s" is not in the list of known file types') % filetype )
|
2004-12-09 04:24:26 +05:30
|
|
|
choose.destroy()
|
2004-10-08 09:29:55 +05:30
|
|
|
return False
|
2004-06-28 23:46:42 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# 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))
|
2005-02-24 05:55:34 +05:30
|
|
|
choose.set_local_only(False)
|
2004-06-28 23:46:42 +05:30
|
|
|
# Always add automatic (macth all files) filter
|
2005-02-26 08:04:11 +05:30
|
|
|
add_all_files_filter(choose)
|
|
|
|
add_grdb_filter(choose)
|
2005-02-28 07:21:21 +05:30
|
|
|
add_xml_filter(choose)
|
|
|
|
add_gedcom_filter(choose)
|
2005-02-26 08:04:11 +05:30
|
|
|
|
2005-02-28 07:21:21 +05:30
|
|
|
format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom]
|
2004-06-28 23:46:42 +05:30
|
|
|
|
|
|
|
# Add more data type selections if opening existing db
|
2005-02-28 07:21:21 +05:30
|
|
|
for (importData,mime_filter,mime_type,native_format,format_name) in PluginMgr.import_list:
|
|
|
|
if not native_format:
|
|
|
|
choose.add_filter(mime_filter)
|
|
|
|
format_list.append(mime_type)
|
|
|
|
_KNOWN_FORMATS[mime_type] = format_name
|
2005-02-26 08:04:11 +05:30
|
|
|
|
|
|
|
(box,type_selector) = format_maker(format_list)
|
|
|
|
choose.set_extra_widget(box)
|
|
|
|
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
# Suggested folder: try last open file, import, then last export,
|
|
|
|
# then home.
|
2005-01-06 22:58:31 +05:30
|
|
|
default_dir = GrampsKeys.get_last_import_dir()
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
if len(default_dir)<=1:
|
2005-01-06 22:58:31 +05:30
|
|
|
default_dir = os.path.split(GrampsKeys.get_lastfile())[0] + os.path.sep
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
if len(default_dir)<=1:
|
2005-01-06 22:58:31 +05:30
|
|
|
default_dir = GrampsKeys.get_last_export_dir()
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
if len(default_dir)<=1:
|
|
|
|
default_dir = '~/'
|
|
|
|
|
|
|
|
choose.set_current_folder(default_dir)
|
2004-06-28 23:46:42 +05:30
|
|
|
response = choose.run()
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
filename = choose.get_filename()
|
2005-02-26 08:04:11 +05:30
|
|
|
filetype = type_selector.get_value()
|
|
|
|
if filetype == 'auto':
|
|
|
|
filetype = get_mime_type(filename)
|
2005-01-29 10:43:29 +05:30
|
|
|
|
2005-03-02 19:30:51 +05:30
|
|
|
if filetype == const.app_gramps:
|
2005-01-29 10:43:29 +05:30
|
|
|
choose.destroy()
|
|
|
|
ReadGrdb.importData(self.parent.db,filename)
|
|
|
|
self.parent.import_tool_callback()
|
|
|
|
return True
|
2005-03-02 19:30:51 +05:30
|
|
|
elif filetype == const.app_gramps_xml:
|
|
|
|
choose.destroy()
|
|
|
|
import ReadXML
|
|
|
|
ReadXML.importData(self.parent.db,filename)
|
|
|
|
return True
|
2005-03-09 02:41:48 +05:30
|
|
|
elif filetype == const.app_gedcom:
|
2005-03-02 19:30:51 +05:30
|
|
|
choose.destroy()
|
|
|
|
import ReadGedcom
|
|
|
|
ReadGedcom.importData(self.parent.db,filename)
|
|
|
|
return True
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
|
|
|
|
(the_path,the_file) = os.path.split(filename)
|
2005-01-06 22:58:31 +05:30
|
|
|
GrampsKeys.save_last_import_dir(the_path)
|
2005-02-28 07:21:21 +05:30
|
|
|
for (importData,mime_filter,mime_type,native_format,format_name) in PluginMgr.import_list:
|
2004-06-28 23:46:42 +05:30
|
|
|
if filetype == mime_type or the_file == mime_type:
|
|
|
|
choose.destroy()
|
|
|
|
importData(self.parent.db,filename)
|
|
|
|
self.parent.import_tool_callback()
|
2004-10-08 09:29:55 +05:30
|
|
|
return True
|
2004-12-05 09:45:48 +05:30
|
|
|
QuestionDialog.ErrorDialog(
|
|
|
|
_("Could not open file: %s") % filename,
|
|
|
|
_('The type "%s" is not in the list of known file types') % filetype )
|
2004-08-24 04:20:35 +05:30
|
|
|
choose.destroy()
|
2004-10-08 09:29:55 +05:30
|
|
|
return False
|
2004-06-28 18:49:06 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# NewNativeDbPrompter
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class NewNativeDbPrompter:
|
2004-06-28 23:46:42 +05:30
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2004-06-28 18:49:06 +05:30
|
|
|
|
2004-06-28 23:46:42 +05:30
|
|
|
def __init__(self,parent,parent_window=None):
|
2004-06-28 18:49:06 +05:30
|
|
|
self.parent = parent
|
|
|
|
self.parent_window = parent_window
|
|
|
|
|
|
|
|
def chooser(self):
|
2004-06-28 23:46:42 +05:30
|
|
|
"""
|
|
|
|
Select the new file. Suggest the Untitled_X.grdb name.
|
|
|
|
Return 1 when selection is made and 0 otherwise.
|
|
|
|
"""
|
2004-06-28 18:49:06 +05:30
|
|
|
choose = gtk.FileChooserDialog(_('GRAMPS: Create GRAMPS database'),
|
|
|
|
self.parent_window,
|
|
|
|
gtk.FILE_CHOOSER_ACTION_SAVE,
|
|
|
|
(gtk.STOCK_CANCEL,
|
|
|
|
gtk.RESPONSE_CANCEL,
|
|
|
|
gtk.STOCK_OPEN,
|
|
|
|
gtk.RESPONSE_OK))
|
|
|
|
self.parent.clear_database()
|
|
|
|
|
|
|
|
# Always add automatic (macth all files) filter
|
2005-02-26 08:04:11 +05:30
|
|
|
add_all_files_filter(choose)
|
|
|
|
add_grdb_filter(choose)
|
2004-06-28 18:49:06 +05:30
|
|
|
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
# Suggested folder: try last open file, import, then last export,
|
|
|
|
# then home.
|
2005-01-06 22:58:31 +05:30
|
|
|
default_dir = os.path.split(GrampsKeys.get_lastfile())[0] + os.path.sep
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
if len(default_dir)<=1:
|
2005-01-06 22:58:31 +05:30
|
|
|
default_dir = GrampsKeys.get_last_import_dir()
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
if len(default_dir)<=1:
|
2005-01-06 22:58:31 +05:30
|
|
|
default_dir = GrampsKeys.get_last_export_dir()
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
if len(default_dir)<=1:
|
|
|
|
default_dir = '~/'
|
|
|
|
|
|
|
|
new_filename = Utils.get_new_filename('grdb',default_dir)
|
2004-06-28 23:46:42 +05:30
|
|
|
|
* src/Plugins.py: Add native_format flag to import plugin registration.
* src/ReadXML.py, src/ReadGedcom.py: Register as native formats
to prevent loading twice on File->Open.
* src/data/gramps.schemas: Add keys for last import and export dirs.
* src/GrampsCfg.py (get_last_import_dir, save_last_import_dir,
get_last_export_dir, save_last_export_dir): Add functions.
* src/Exportder.py (suggest_filename): Try last export and last
import folders before falling back to Home; (save): Save export folder.
* src/Utils.py (get_new_filename): Add optional folder argument.
* src/DbPrompter.py (ExistingDbPrompter.chooser): Only add
importers for non-native formats, the rest is already taken care of;
Try last file, last import, last export, then home folders;
(ImportDbPrompter.chooser): Save import folder; Try last import,
last file, last export, then home folders.
(NewNativeDbPrompter): Try last file, last import, last export folders,
then fall back to home.
svn: r3493
2004-08-24 03:35:55 +05:30
|
|
|
choose.set_current_folder(default_dir)
|
2004-06-28 23:46:42 +05:30
|
|
|
choose.set_current_name(os.path.split(new_filename)[1])
|
2004-05-08 10:18:59 +05:30
|
|
|
|
2004-08-27 03:24:14 +05:30
|
|
|
while (True):
|
|
|
|
response = choose.run()
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
filename = choose.get_filename()
|
|
|
|
if filename == None:
|
|
|
|
continue
|
|
|
|
if os.path.splitext(filename)[1] != ".grdb":
|
|
|
|
filename = filename + ".grdb"
|
|
|
|
choose.destroy()
|
2005-02-23 19:00:47 +05:30
|
|
|
try:
|
|
|
|
self.parent.db.close()
|
|
|
|
except:
|
|
|
|
pass
|
2005-01-09 03:22:57 +05:30
|
|
|
self.parent.db = GrampsBSDDB.GrampsBSDDB()
|
2004-08-27 03:24:14 +05:30
|
|
|
self.parent.read_file(filename)
|
2004-11-26 13:06:23 +05:30
|
|
|
# Add the file to the recent items
|
2004-11-29 10:45:41 +05:30
|
|
|
RecentFiles.recent_files(filename,const.app_gramps)
|
2005-02-25 21:35:02 +05:30
|
|
|
self.parent.build_recent_menu()
|
2004-10-08 09:29:55 +05:30
|
|
|
return True
|
2004-08-27 03:24:14 +05:30
|
|
|
else:
|
|
|
|
choose.destroy()
|
2004-10-08 09:29:55 +05:30
|
|
|
return False
|
2004-12-09 04:24:26 +05:30
|
|
|
choose.destroy()
|
2004-10-08 09:29:55 +05:30
|
|
|
return False
|
2004-11-30 07:46:30 +05:30
|
|
|
|
2005-01-31 05:23:47 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# NewSaveasDbPrompter
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class NewSaveasDbPrompter:
|
|
|
|
"""
|
|
|
|
This class allows to select a new empty InMemory database and then
|
|
|
|
to save current data into it and then continue editing it.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self,parent,parent_window=None):
|
|
|
|
self.parent = parent
|
|
|
|
self.parent_window = parent_window
|
|
|
|
|
|
|
|
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: Select filename for a new database'),
|
|
|
|
self.parent_window,
|
|
|
|
gtk.FILE_CHOOSER_ACTION_SAVE,
|
|
|
|
(gtk.STOCK_CANCEL,
|
|
|
|
gtk.RESPONSE_CANCEL,
|
|
|
|
gtk.STOCK_SAVE,
|
|
|
|
gtk.RESPONSE_OK))
|
2005-02-24 05:55:34 +05:30
|
|
|
choose.set_local_only(False)
|
2005-02-25 21:35:02 +05:30
|
|
|
(box,type_selector) = format_maker([const.app_gramps,
|
|
|
|
const.app_gramps_xml,
|
|
|
|
const.app_gedcom])
|
|
|
|
choose.set_extra_widget(box)
|
2005-01-31 05:23:47 +05:30
|
|
|
|
|
|
|
# Always add automatic (macth all files) filter
|
2005-02-26 08:04:11 +05:30
|
|
|
add_all_files_filter(choose)
|
|
|
|
add_gramps_files_filter(choose)
|
|
|
|
add_grdb_filter(choose)
|
|
|
|
add_xml_filter(choose)
|
|
|
|
add_gedcom_filter(choose)
|
2005-01-31 05:23:47 +05:30
|
|
|
|
|
|
|
# Suggested folder: try last open file, import, then last export,
|
|
|
|
# then home.
|
|
|
|
default_dir = os.path.split(GrampsKeys.get_lastfile())[0] + os.path.sep
|
|
|
|
if len(default_dir)<=1:
|
|
|
|
default_dir = GrampsKeys.get_last_import_dir()
|
|
|
|
if len(default_dir)<=1:
|
|
|
|
default_dir = GrampsKeys.get_last_export_dir()
|
|
|
|
if len(default_dir)<=1:
|
|
|
|
default_dir = '~/'
|
|
|
|
|
|
|
|
new_filename = Utils.get_new_filename('grdb',default_dir)
|
|
|
|
|
|
|
|
choose.set_current_folder(default_dir)
|
|
|
|
choose.set_current_name(os.path.split(new_filename)[1])
|
|
|
|
|
|
|
|
while (True):
|
|
|
|
response = choose.run()
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
filename = choose.get_filename()
|
|
|
|
if filename == None:
|
|
|
|
continue
|
2005-02-25 21:35:02 +05:30
|
|
|
filetype = type_selector.get_value()
|
|
|
|
if filetype == 'auto':
|
|
|
|
os.system('touch %s' % filename)
|
|
|
|
filetype = get_mime_type(filename)
|
2005-01-31 05:23:47 +05:30
|
|
|
(the_path,the_file) = os.path.split(filename)
|
|
|
|
choose.destroy()
|
2005-02-25 21:35:02 +05:30
|
|
|
if filetype not in [const.app_gramps,const.app_gramps_xml,
|
|
|
|
const.app_gedcom]:
|
|
|
|
QuestionDialog.ErrorDialog(_('Could not save file'),
|
|
|
|
_('Unknown file type: %(file_type)s') % {
|
|
|
|
'file_type' : filetype } )
|
|
|
|
return False
|
2005-01-31 05:23:47 +05:30
|
|
|
if filetype == const.app_gramps:
|
|
|
|
WriteGrdb.exportData(self.parent.db,filename,None,None)
|
|
|
|
self.parent.db.close()
|
|
|
|
self.parent.db = GrampsBSDDB.GrampsBSDDB()
|
|
|
|
elif filetype == const.app_gramps_xml:
|
|
|
|
WriteXML.exportData(self.parent.db,filename,None,None)
|
|
|
|
self.parent.db.close()
|
|
|
|
self.parent.db = GrampsXMLDB.GrampsXMLDB()
|
|
|
|
elif filetype == const.app_gedcom:
|
|
|
|
WriteGedcom.exportData(self.parent.db,filename,None,None)
|
|
|
|
self.parent.db.close()
|
|
|
|
self.parent.db = GrampsGEDDB.GrampsGEDDB()
|
|
|
|
self.parent.read_file(filename)
|
|
|
|
# Add the file to the recent items
|
|
|
|
RecentFiles.recent_files(filename,const.app_gramps)
|
2005-02-25 21:35:02 +05:30
|
|
|
self.parent.build_recent_menu()
|
2005-01-31 05:23:47 +05:30
|
|
|
return True
|
|
|
|
else:
|
|
|
|
choose.destroy()
|
|
|
|
return False
|
|
|
|
choose.destroy()
|
|
|
|
return False
|
|
|
|
|
2004-11-30 07:46:30 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Helper function
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def open_native(parent,filename,filetype):
|
|
|
|
"""
|
|
|
|
Open native database and return the status.
|
|
|
|
"""
|
|
|
|
|
|
|
|
(the_path,the_file) = os.path.split(filename)
|
2005-01-06 22:58:31 +05:30
|
|
|
GrampsKeys.save_last_import_dir(the_path)
|
2004-11-30 07:46:30 +05:30
|
|
|
|
|
|
|
success = False
|
|
|
|
if filetype == const.app_gramps:
|
|
|
|
parent.db = GrampsBSDDB.GrampsBSDDB()
|
|
|
|
msgxml = gtk.glade.XML(const.gladeFile, "load_message","gramps")
|
|
|
|
msg_top = msgxml.get_widget('load_message')
|
2004-12-20 05:07:40 +05:30
|
|
|
msg_label = msgxml.get_widget('message')
|
|
|
|
|
|
|
|
def update_msg(msg):
|
|
|
|
msg_label.set_text("<i>%s</i>" % msg)
|
|
|
|
msg_label.set_use_markup(True)
|
|
|
|
while gtk.events_pending():
|
|
|
|
gtk.main_iteration()
|
|
|
|
|
|
|
|
parent.read_file(filename,update_msg)
|
2004-11-30 07:46:30 +05:30
|
|
|
msg_top.destroy()
|
|
|
|
success = True
|
|
|
|
elif filetype == const.app_gramps_xml:
|
|
|
|
parent.db = GrampsXMLDB.GrampsXMLDB()
|
|
|
|
parent.read_file(filename)
|
|
|
|
success = True
|
|
|
|
elif filetype == const.app_gedcom:
|
|
|
|
parent.db = GrampsGEDDB.GrampsGEDDB()
|
|
|
|
parent.read_file(filename)
|
|
|
|
success = True
|
|
|
|
|
|
|
|
if success:
|
|
|
|
# Add the file to the recent items
|
|
|
|
RecentFiles.recent_files(filename,filetype)
|
|
|
|
parent.build_recent_menu()
|
|
|
|
|
|
|
|
return success
|
2005-02-25 21:35:02 +05:30
|
|
|
|
2005-02-28 07:21:21 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Format selectors and filters
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-02-25 21:35:02 +05:30
|
|
|
class GrampsFormatWidget(gtk.ComboBox):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
gtk.ComboBox.__init__(self,model=None)
|
|
|
|
|
|
|
|
def set(self,format_list):
|
|
|
|
self.store = gtk.ListStore(str)
|
|
|
|
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(0)
|
|
|
|
|
|
|
|
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()
|
2005-02-28 07:21:21 +05:30
|
|
|
label = gtk.Label(_('Select file _type:'))
|
|
|
|
label.set_use_underline(True)
|
|
|
|
label.set_mnemonic_widget(type_selector)
|
2005-02-25 21:35:02 +05:30
|
|
|
box.pack_start(label,expand=False,fill=False,padding=6)
|
|
|
|
box.add(type_selector)
|
2005-02-26 08:04:11 +05:30
|
|
|
box.show_all()
|
2005-02-25 21:35:02 +05:30
|
|
|
return (box,type_selector)
|
2005-02-26 08:04:11 +05:30
|
|
|
|
|
|
|
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'))
|
|
|
|
mime_filter.add_mime_type(const.app_gramps)
|
|
|
|
mime_filter.add_mime_type(const.app_gramps_xml)
|
|
|
|
mime_filter.add_mime_type(const.app_gedcom)
|
|
|
|
chooser.add_filter(mime_filter)
|
|
|
|
|
|
|
|
def add_grdb_filter(chooser):
|
|
|
|
"""
|
2005-02-28 07:21:21 +05:30
|
|
|
Add a GRDB filter to the file chooser dialog.
|
2005-02-26 08:04:11 +05:30
|
|
|
"""
|
|
|
|
mime_filter = gtk.FileFilter()
|
|
|
|
mime_filter.set_name(_('GRAMPS databases'))
|
|
|
|
mime_filter.add_mime_type(const.app_gramps)
|
|
|
|
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'))
|
|
|
|
mime_filter.add_mime_type(const.app_gramps_xml)
|
|
|
|
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'))
|
|
|
|
mime_filter.add_mime_type(const.app_gedcom)
|
|
|
|
chooser.add_filter(mime_filter)
|