* 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
This commit is contained in:
Alex Roitman 2005-01-30 23:53:47 +00:00
parent 91b3c8beb3
commit a53baae751
5 changed files with 240 additions and 22 deletions

View File

@ -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 <eerot@sf>
* src/plugins/StatisticsChart.py:
- Added support for Don's Pie charts + color styles for it

View File

@ -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

82
src/WriteGrdb.py Normal file
View File

@ -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()

View File

@ -56,7 +56,7 @@
<accelerator key="N" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2381">
<widget class="GtkImage" id="image2454">
<property name="visible">True</property>
<property name="stock">gtk-new</property>
<property name="icon_size">1</property>
@ -78,7 +78,7 @@
<accelerator key="O" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2382">
<widget class="GtkImage" id="image2455">
<property name="visible">True</property>
<property name="stock">gtk-open</property>
<property name="icon_size">1</property>
@ -115,7 +115,7 @@
<accelerator key="I" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2383">
<widget class="GtkImage" id="image2456">
<property name="visible">True</property>
<property name="stock">gtk-convert</property>
<property name="icon_size">1</property>
@ -129,15 +129,37 @@
</child>
<child>
<widget class="GtkImageMenuItem" id="export1">
<widget class="GtkImageMenuItem" id="saveas">
<property name="visible">True</property>
<property name="label" translatable="yes">Save _As...</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_export_activate" last_modification_time="Thu, 24 Jun 2004 21:04:14 GMT"/>
<signal name="activate" handler="on_saveas_activate" last_modification_time="Sun, 30 Jan 2005 22:43:29 GMT"/>
<accelerator key="S" modifiers="GDK_CONTROL_MASK | GDK_SHIFT_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2384">
<widget class="GtkImage" id="image2457">
<property name="visible">True</property>
<property name="stock">gtk-save-as</property>
<property name="icon_size">1</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="export1">
<property name="visible">True</property>
<property name="label" translatable="yes">E_xport...</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_export_activate" last_modification_time="Sun, 30 Jan 2005 22:43:29 GMT"/>
<accelerator key="E" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2458">
<property name="visible">True</property>
<property name="stock">gtk-save-as</property>
<property name="icon_size">1</property>
@ -174,7 +196,7 @@
<accelerator key="Q" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2385">
<widget class="GtkImage" id="image2459">
<property name="visible">True</property>
<property name="stock">gtk-quit</property>
<property name="icon_size">1</property>
@ -209,7 +231,7 @@
<accelerator key="z" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2386">
<widget class="GtkImage" id="image2460">
<property name="visible">True</property>
<property name="stock">gtk-undo</property>
<property name="icon_size">1</property>
@ -246,7 +268,7 @@
<accelerator key="Insert" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2387">
<widget class="GtkImage" id="image2461">
<property name="visible">True</property>
<property name="stock">gtk-add</property>
<property name="icon_size">1</property>
@ -269,7 +291,7 @@
<accelerator key="Delete" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2388">
<widget class="GtkImage" id="image2462">
<property name="visible">True</property>
<property name="stock">gtk-remove</property>
<property name="icon_size">1</property>
@ -307,7 +329,7 @@
<accelerator key="M" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2389">
<widget class="GtkImage" id="image2463">
<property name="visible">True</property>
<property name="stock">gtk-convert</property>
<property name="icon_size">1</property>
@ -334,7 +356,7 @@
<signal name="activate" handler="on_preferences1_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2390">
<widget class="GtkImage" id="image2464">
<property name="visible">True</property>
<property name="stock">gtk-preferences</property>
<property name="icon_size">1</property>
@ -355,7 +377,7 @@
<signal name="activate" handler="on_column_order_activate" last_modification_time="Wed, 10 Mar 2004 04:36:07 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image2391">
<widget class="GtkImage" id="image2465">
<property name="visible">True</property>
<property name="stock">gtk-properties</property>
<property name="icon_size">1</property>
@ -376,7 +398,7 @@
<signal name="activate" handler="on_default_person_activate" last_modification_time="Sat, 16 Aug 2003 01:58:26 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image2392">
<widget class="GtkImage" id="image2466">
<property name="visible">True</property>
<property name="stock">gtk-home</property>
<property name="icon_size">1</property>
@ -462,7 +484,7 @@
<accelerator key="D" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2393">
<widget class="GtkImage" id="image2467">
<property name="visible">True</property>
<property name="stock">gtk-index</property>
<property name="icon_size">1</property>
@ -484,7 +506,7 @@
<accelerator key="B" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2394">
<widget class="GtkImage" id="image2468">
<property name="visible">True</property>
<property name="stock">gnome-stock-book-open</property>
<property name="icon_size">1</property>
@ -557,7 +579,7 @@
<accelerator key="F1" modifiers="0" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2395">
<widget class="GtkImage" id="image2469">
<property name="visible">True</property>
<property name="stock">gtk-help</property>
<property name="icon_size">1</property>
@ -578,7 +600,7 @@
<signal name="activate" handler="on_faq_activate" last_modification_time="Wed, 26 Nov 2003 17:59:23 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image2396">
<widget class="GtkImage" id="image2470">
<property name="visible">True</property>
<property name="stock">gnome-stock-book-open</property>
<property name="icon_size">1</property>
@ -605,7 +627,7 @@
<signal name="activate" handler="on_gramps_home_page_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2397">
<widget class="GtkImage" id="image2471">
<property name="visible">True</property>
<property name="stock">gtk-jump-to</property>
<property name="icon_size">1</property>
@ -626,7 +648,7 @@
<signal name="activate" handler="on_gramps_mailing_lists_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image2398">
<widget class="GtkImage" id="image2472">
<property name="visible">True</property>
<property name="stock">gnome-stock-mail</property>
<property name="icon_size">1</property>
@ -680,7 +702,7 @@
<signal name="activate" handler="on_about_activate" last_modification_time="Tue, 01 Apr 2003 03:44:24 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image2399">
<widget class="GtkImage" id="image2473">
<property name="visible">True</property>
<property name="stock">gnome-stock-about</property>
<property name="icon_size">1</property>

View File

@ -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)