From a53baae75125b12519c546bd781789f06a5d33c3 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Sun, 30 Jan 2005 23:53:47 +0000 Subject: [PATCH] * src/WriteGrdb.py: Add to CVS. * src/gramps.glade: Add Save as item, switch former one to Export. * src/gramps_main.py: Support for save as. * src/DbPrompter.py: Support for save as. svn: r4000 --- ChangeLog | 5 +++ src/DbPrompter.py | 106 ++++++++++++++++++++++++++++++++++++++++++++- src/WriteGrdb.py | 82 +++++++++++++++++++++++++++++++++++ src/gramps.glade | 64 ++++++++++++++++++--------- src/gramps_main.py | 5 +++ 5 files changed, 240 insertions(+), 22 deletions(-) create mode 100644 src/WriteGrdb.py diff --git a/ChangeLog b/ChangeLog index 1f4dcd08a..800dea87b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,11 @@ * src/ArgHandler.py: Support for opening in the command-line mode. * src/const.py.in: Add -O | --open option. + * src/WriteGrdb.py: Add to CVS. + * src/gramps.glade: Add Save as item, switch former one to Export. + * src/gramps_main.py: Support for save as. + * src/DbPrompter.py: Support for save as. + 2005-01-29 Eero Tamminen * src/plugins/StatisticsChart.py: - Added support for Don's Pie charts + color styles for it diff --git a/src/DbPrompter.py b/src/DbPrompter.py index b9d158e38..2c84f69d9 100644 --- a/src/DbPrompter.py +++ b/src/DbPrompter.py @@ -57,6 +57,10 @@ import GrampsXMLDB import GrampsGEDDB import GrampsKeys import RecentFiles +import ReadGrdb +import WriteGrdb +import WriteXML +import WriteGedcom #------------------------------------------------------------------------- # @@ -277,7 +281,6 @@ class ImportDbPrompter: if filetype == 'application/x-gramps': choose.destroy() - import ReadGrdb ReadGrdb.importData(self.parent.db,filename) self.parent.import_tool_callback() return True @@ -374,6 +377,107 @@ class NewNativeDbPrompter: choose.destroy() return False +#------------------------------------------------------------------------- +# +# 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)) + choose.set_local_only(gtk.FALSE) + + # Always add automatic (macth all files) filter + mime_filter = gtk.FileFilter() + mime_filter.set_name(_('Automatic')) + mime_filter.add_pattern('*') + choose.add_filter(mime_filter) + + # Always add native format filter + mime_filter = gtk.FileFilter() + mime_filter.set_name(_('GRAMPS databases')) + mime_filter.add_mime_type(const.app_gramps) + choose.add_filter(mime_filter) + + # Always add native format filter + mime_filter = gtk.FileFilter() + mime_filter.set_name(_('GRAMPS XML databases')) + mime_filter.add_mime_type(const.app_gramps_xml) + choose.add_filter(mime_filter) + + # Always add native format filter + mime_filter = gtk.FileFilter() + mime_filter.set_name(_('GEDCOM files')) + mime_filter.add_mime_type(const.app_gedcom) + choose.add_filter(mime_filter) + + # 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 + os.system('touch %s' % filename) + filetype = get_mime_type(filename) + (the_path,the_file) = os.path.split(filename) + choose.destroy() + 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) + self.parent.build_recent_menu() + return True + else: + choose.destroy() + return False + choose.destroy() + return False + #------------------------------------------------------------------------- # # Helper function diff --git a/src/WriteGrdb.py b/src/WriteGrdb.py new file mode 100644 index 000000000..95f60c0d5 --- /dev/null +++ b/src/WriteGrdb.py @@ -0,0 +1,82 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2005 Donald N. Allingham +# +# 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 +# + +# $Id$ + +# Written by Alex Roitman, +# largely based on WriteXML by Don Allingham + +#------------------------------------------------------------------------- +# +# Standard Python Modules +# +#------------------------------------------------------------------------- +import os +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# Gramps Modules +# +#------------------------------------------------------------------------- +import GrampsBSDDB +from QuestionDialog import ErrorDialog + +#------------------------------------------------------------------------- +# +# Importing data into the currently open database. +# +#------------------------------------------------------------------------- +def exportData(database, filename, person=None, callback=None): + + filename = os.path.normpath(filename) + + new_database = GrampsBSDDB.GrampsBSDDB() + try: + new_database.load(filename,callback) + except: + if cl: + print "Error: %s could not be opened. Exiting." % filename + else: + ErrorDialog(_("%s could not be opened") % filename) + return + + # copy all data from new_database to database, + + for handle in database.person_map.keys(): + new_database.person_map.put(str(handle), + database.person_map.get(str(handle))) + for handle in database.family_map.keys(): + new_database.family_map.put(str(handle), + database.family_map.get(str(handle))) + for handle in database.place_map.keys(): + new_database.place_map.put(str(handle), + database.place_map.get(str(handle))) + for handle in database.source_map.keys(): + new_database.source_map.put(str(handle), + database.source_map.get(str(handle))) + for handle in database.media_map.keys(): + new_database.media_map.put(str(handle), + database.media_map.get(str(handle))) + for handle in database.event_map.keys(): + new_database.event_map.put(str(handle), + database.event_map.get(str(handle))) + + new_database.close() diff --git a/src/gramps.glade b/src/gramps.glade index 6813e9ad5..9fbb8fed7 100644 --- a/src/gramps.glade +++ b/src/gramps.glade @@ -56,7 +56,7 @@ - + True gtk-new 1 @@ -78,7 +78,7 @@ - + True gtk-open 1 @@ -115,7 +115,7 @@ - + True gtk-convert 1 @@ -129,15 +129,37 @@ - + True Save _As... True - + - + + True + gtk-save-as + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + True + E_xport... + True + + + + + True gtk-save-as 1 @@ -174,7 +196,7 @@ - + True gtk-quit 1 @@ -209,7 +231,7 @@ - + True gtk-undo 1 @@ -246,7 +268,7 @@ - + True gtk-add 1 @@ -269,7 +291,7 @@ - + True gtk-remove 1 @@ -307,7 +329,7 @@ - + True gtk-convert 1 @@ -334,7 +356,7 @@ - + True gtk-preferences 1 @@ -355,7 +377,7 @@ - + True gtk-properties 1 @@ -376,7 +398,7 @@ - + True gtk-home 1 @@ -462,7 +484,7 @@ - + True gtk-index 1 @@ -484,7 +506,7 @@ - + True gnome-stock-book-open 1 @@ -557,7 +579,7 @@ - + True gtk-help 1 @@ -578,7 +600,7 @@ - + True gnome-stock-book-open 1 @@ -605,7 +627,7 @@ - + True gtk-jump-to 1 @@ -626,7 +648,7 @@ - + True gnome-stock-mail 1 @@ -680,7 +702,7 @@ - + True gnome-stock-about 1 diff --git a/src/gramps_main.py b/src/gramps_main.py index 4babb733b..8324006d9 100755 --- a/src/gramps_main.py +++ b/src/gramps_main.py @@ -372,6 +372,7 @@ class Gramps: "on_open_activate" : self.on_open_activate, "on_import_activate" : self.on_import_activate, "on_export_activate" : self.on_export_activate, + "on_saveas_activate" : self.on_saveas_activate, "on_pedigree1_activate" : self.on_pedigree1_activate, "on_person_list1_activate" : self.on_person_list1_activate, "on_media_activate" : self.on_media_activate, @@ -1428,6 +1429,10 @@ class Gramps: prompter = DbPrompter.ImportDbPrompter(self,self.topWindow) prompter.chooser() + def on_saveas_activate(self,obj): + prompter = DbPrompter.NewSaveasDbPrompter(self,self.topWindow) + prompter.chooser() + def on_export_activate(self,obj): Exporter.Exporter(self,self.topWindow)