* src/gramps_main.py (on_export_activate): Delegate work
to DbPrompter. * src/WriteXML.py: Register with the new scheme. * src/DbPrompter.py (SaveAsDbPrompter): Add class. svn: r3246
This commit is contained in:
parent
3421c1971a
commit
e27d4726ea
@ -1,3 +1,9 @@
|
||||
2004-06-30 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||
* src/gramps_main.py (on_export_activate): Delegate work
|
||||
to DbPrompter.
|
||||
* src/WriteXML.py: Register with the new scheme.
|
||||
* src/DbPrompter.py (SaveAsDbPrompter): Add class.
|
||||
|
||||
2004-06-29 Don Allingham <dallingham@users.sourceforge.net>
|
||||
* src/FamilyView.py: fix reordering of children
|
||||
* src/ChooseParents.py: get filters working again
|
||||
|
@ -26,6 +26,7 @@
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import os
|
||||
import shutil
|
||||
from gettext import gettext as _
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -314,3 +315,85 @@ class NewNativeDbPrompter:
|
||||
while os.path.isfile(os.path.expanduser('~/Untitled_%d.grdb' % ix ) ):
|
||||
ix = ix + 1
|
||||
return os.path.expanduser('~/Untitled_%d.grdb' % ix )
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# SaveAsDbPrompter
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class SaveAsDbPrompter:
|
||||
"""
|
||||
This class allows to save (export) 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 corresponding export routine is called. Native save as just
|
||||
copies file to another name.
|
||||
|
||||
"""
|
||||
|
||||
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: Export database'),
|
||||
self.parent_window,
|
||||
gtk.FILE_CHOOSER_ACTION_SAVE,
|
||||
(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(_('By extension'))
|
||||
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)
|
||||
|
||||
# Add more data type selections if opening existing db
|
||||
for (exportData,filter,pattern_list) in Plugins._exports:
|
||||
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))
|
||||
(junk,the_file) = os.path.split(filename)
|
||||
the_ext = os.path.splitext(filename)[1]
|
||||
|
||||
if the_ext in ('.grdb', '.GRDB'):
|
||||
choose.destroy()
|
||||
try:
|
||||
shutil.copyfile(self.parent.db.get_save_path(),filename)
|
||||
return 1
|
||||
except shutil.Error, msg:
|
||||
QuestionDialog.ErrorDialog( _("Could not write file: %s") % filename,
|
||||
_('System message was: %s') % msg )
|
||||
return 0
|
||||
|
||||
for (exportData,filter,pattern_list) in Plugins._exports:
|
||||
if the_ext in pattern_list:
|
||||
choose.destroy()
|
||||
exportData(self.parent.db,filename)
|
||||
return 1
|
||||
else:
|
||||
QuestionDialog.ErrorDialog( _("Could not write file: %s") % filename,
|
||||
_('The type is not in the list of known file types') )
|
||||
return 0
|
||||
else:
|
||||
choose.destroy()
|
||||
return 0
|
||||
|
@ -36,6 +36,13 @@ import shutil
|
||||
import os
|
||||
import codecs
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# load gtk libraries
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# load GRAMPS libraries
|
||||
@ -66,7 +73,7 @@ except:
|
||||
#
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def exportData(database, filename, callback):
|
||||
def exportData(database, filename, callback=None):
|
||||
if os.path.isfile(filename):
|
||||
try:
|
||||
shutil.copyfile(filename, filename + ".bak")
|
||||
@ -74,7 +81,7 @@ def exportData(database, filename, callback):
|
||||
except:
|
||||
pass
|
||||
|
||||
compress = GrampsCfg.uncompress == 0 and _gzip_ok == 1
|
||||
compress = _gzip_ok == 1
|
||||
|
||||
try:
|
||||
g = XmlWriter(database,callback,0,compress)
|
||||
@ -798,3 +805,17 @@ def conf_priv(obj):
|
||||
return ' priv="%d"' % obj.get_privacy()
|
||||
else:
|
||||
return ''
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
_mime_type = 'data.gramps'
|
||||
_filter = gtk.FileFilter()
|
||||
_filter.set_name(_('GRAMPS XML databases'))
|
||||
_filter.add_pattern(_mime_type)
|
||||
_ext_list = '.gramps'
|
||||
|
||||
from Plugins import register_export
|
||||
register_export(exportData,_filter,_ext_list)
|
||||
|
@ -1367,58 +1367,8 @@ class Gramps:
|
||||
prompter.chooser()
|
||||
|
||||
def on_export_activate(self,obj):
|
||||
choose = gtk.FileChooserDialog(_('GRAMPS: Export database'),
|
||||
self.topWindow,
|
||||
gtk.FILE_CHOOSER_ACTION_SAVE,
|
||||
(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(_('By extension'))
|
||||
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 (exportData,filter,pattern_list) in Plugins._exports:
|
||||
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))
|
||||
(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 (exportData,filter,pattern_list) in Plugins._exports:
|
||||
for pattern in pattern_list:
|
||||
if filter.filter((filename,None,None,None)):
|
||||
exportData(self.db,filename)
|
||||
opened = 1
|
||||
break
|
||||
if not opened:
|
||||
ErrorDialog( _("Could not write file: %s") % filename,
|
||||
_('The type is not in the list of known file types') )
|
||||
choose.destroy()
|
||||
prompter = DbPrompter.SaveAsDbPrompter(self,self.topWindow)
|
||||
prompter.chooser()
|
||||
|
||||
def on_revert_activate(self,obj):
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user