* src/DbPrompter.py: Handle package export.

* src/plugins/WritePkg.py: Register with the new scheme.
* src/plugins/ReadPkg.py: Minor cleanups.
* src/WriteXML.py: Minor cleanups.


svn: r3249
This commit is contained in:
Alex Roitman 2004-07-03 04:46:51 +00:00
parent bcbd65f783
commit 3c108b27b7
5 changed files with 57 additions and 62 deletions

View File

@ -4,6 +4,11 @@
Connect handler to the filter change event; (get_new_filename): Make Connect handler to the filter change event; (get_new_filename): Make
a module function (outside any class). a module function (outside any class).
* src/DbPrompter.py: Handle package export.
* src/plugins/WritePkg.py: Register with the new scheme.
* src/plugins/ReadPkg.py: Minor cleanups.
* src/WriteXML.py: Minor cleanups.
2004-07-01 Don Allingham <dallingham@users.sourceforge.net> 2004-07-01 Don Allingham <dallingham@users.sourceforge.net>
* src/gramps_main.py: disable find old "find" function * src/gramps_main.py: disable find old "find" function
* src/gramps.glade: enable TreeView find function * src/gramps.glade: enable TreeView find function

View File

@ -293,7 +293,7 @@ class NewNativeDbPrompter:
filter.add_mime_type('application/x-gramps') filter.add_mime_type('application/x-gramps')
choose.add_filter(filter) choose.add_filter(filter)
new_filename = get_new_filename() new_filename = get_new_filename('grdb')
choose.set_filename(new_filename) choose.set_filename(new_filename)
choose.set_current_name(os.path.split(new_filename)[1]) choose.set_current_name(os.path.split(new_filename)[1])
@ -344,25 +344,25 @@ class SaveAsDbPrompter:
gtk.RESPONSE_OK)) gtk.RESPONSE_OK))
self.choose.set_local_only(gtk.FALSE) self.choose.set_local_only(gtk.FALSE)
# Always add automatic (macth all files) filter # Always add automatic (macth all files) filter
filter = gtk.FileFilter() all_filter = gtk.FileFilter()
filter.set_name(_('By extension')) all_filter.set_name(_('By extension'))
filter.add_pattern('*') all_filter.add_pattern('*')
self.choose.add_filter(filter) self.choose.add_filter(all_filter)
# Always add native format filter # Always add native format filter
filter = gtk.FileFilter() native_filter = gtk.FileFilter()
filter.set_name(_('GRAMPS databases')) native_filter.set_name(_('GRAMPS databases'))
filter.add_mime_type('application/x-gramps') native_filter.add_mime_type('application/x-gramps')
self.choose.add_filter(filter) self.choose.add_filter(native_filter)
chooser_default = self.choose.get_children()[0].get_children()[0].get_children()[0] chooser_default = self.choose.get_children()[0].get_children()[0].get_children()[0]
chooser_default.connect('notify::filter',self.change_suggested_name) chooser_default.connect('notify::filter',self.change_suggested_name)
# Add more data type selections if opening existing db # Add more data type selections from export plugins
for (exportData,filter,pattern_list) in Plugins._exports: for (exportData,filter,pattern_list) in Plugins._exports:
self.choose.add_filter(filter) self.choose.add_filter(filter)
new_filename = get_new_filename() new_filename = get_new_filename('grdb')
self.choose.set_filename(new_filename) self.choose.set_filename(new_filename)
self.choose.set_current_name(os.path.split(new_filename)[1]) self.choose.set_current_name(os.path.split(new_filename)[1])
@ -372,8 +372,13 @@ class SaveAsDbPrompter:
filename = os.path.normpath(os.path.abspath(filename)) filename = os.path.normpath(os.path.abspath(filename))
(junk,the_file) = os.path.split(filename) (junk,the_file) = os.path.split(filename)
the_ext = os.path.splitext(filename)[1] the_ext = os.path.splitext(filename)[1]
the_filter = self.choose.get_filter()
if the_ext in ('.grdb', '.GRDB'): # Save as grdb if either explictly selected by the filter
# or the filter is ALL and the extension is grdb
if the_filter.get_name() == native_filter.get_name() \
or (the_filter.get_name() == all_filter.get_name()
and the_ext in ('.grdb', '.GRDB')):
self.choose.destroy() self.choose.destroy()
try: try:
shutil.copyfile(self.parent.db.get_save_path(),filename) shutil.copyfile(self.parent.db.get_save_path(),filename)
@ -384,7 +389,11 @@ class SaveAsDbPrompter:
return 0 return 0
for (exportData,filter,pattern_list) in Plugins._exports: for (exportData,filter,pattern_list) in Plugins._exports:
if the_ext in pattern_list: # Save as this type if either explictly selected by the filter
# or the filter is ALL and the extension is in this type's list
if the_filter.get_name() == filter.get_name() \
or (the_filter.get_name() == all_filter.get_name()
and the_ext in pattern_list):
self.choose.destroy() self.choose.destroy()
exportData(self.parent.db,filename) exportData(self.parent.db,filename)
return 1 return 1
@ -403,20 +412,24 @@ class SaveAsDbPrompter:
""" """
the_filter = self.choose.get_filter() the_filter = self.choose.get_filter()
if the_filter.get_name().find('XML') + 1: if the_filter.get_name().find('XML') + 1:
self.choose.set_current_name('data.gramps') new_filename = 'data.gramps'
elif the_filter.get_name() == _('GRAMPS packages'):
new_filename = get_new_filename('gpkg')
new_filename = os.path.split(new_filename)[1]
else: else:
new_filename = get_new_filename() new_filename = get_new_filename('grdb')
self.choose.set_current_name(os.path.split(new_filename)[1]) new_filename = os.path.split(new_filename)[1]
self.choose.set_current_name()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def get_new_filename(): _NEW_NAME_PATTERN = '~/Untitled_%d.%s'
def get_new_filename(ext):
ix = 1 ix = 1
while os.path.isfile(os.path.expanduser('~/Untitled_%d.grdb' % ix ) ): while os.path.isfile(os.path.expanduser(_NEW_NAME_PATTERN % (ix,ext) )):
ix = ix + 1 ix = ix + 1
return os.path.expanduser('~/Untitled_%d.grdb' % ix ) return os.path.expanduser(_NEW_NAME_PATTERN % (ix,ext))

View File

@ -815,7 +815,7 @@ _mime_type = 'data.gramps'
_filter = gtk.FileFilter() _filter = gtk.FileFilter()
_filter.set_name(_('GRAMPS XML databases')) _filter.set_name(_('GRAMPS XML databases'))
_filter.add_pattern(_mime_type) _filter.add_pattern(_mime_type)
_ext_list = '.gramps' _ext_list = ('.gramps',)
from Plugins import register_export from Plugins import register_export
register_export(exportData,_filter,_ext_list) register_export(exportData,_filter,_ext_list)

View File

@ -50,7 +50,6 @@ _title_string = _("GRAMPS package")
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def impData(database, name,cb=None,cl=0): def impData(database, name,cb=None,cl=0):
print "name1:", name
# Create tempdir, if it does not exist, then check for writability # Create tempdir, if it does not exist, then check for writability
tmpdir_path = os.path.expanduser("~/.gramps/tmp" ) tmpdir_path = os.path.expanduser("~/.gramps/tmp" )
if not os.path.isdir(tmpdir_path): if not os.path.isdir(tmpdir_path):
@ -68,7 +67,6 @@ def impData(database, name,cb=None,cl=0):
for filename in files: for filename in files:
os.remove( os.path.join(tmpdir_path,filename) ) os.remove( os.path.join(tmpdir_path,filename) )
print "name2:", name
try: try:
t = TarFile.ReadTarFile(name,tmpdir_path) t = TarFile.ReadTarFile(name,tmpdir_path)
t.extract() t.extract()
@ -186,9 +184,8 @@ def impData(database, name,cb=None,cl=0):
#------------------------------------------------------------------------ #------------------------------------------------------------------------
_mime_type = 'application/x-gramps-package' _mime_type = 'application/x-gramps-package'
_filter = gtk.FileFilter() _filter = gtk.FileFilter()
_filter.set_name(_('GRAMPS package')) _filter.set_name(_('GRAMPS packages'))
_filter.add_mime_type(_mime_type) _filter.add_mime_type(_mime_type)
from Plugins import register_import from Plugins import register_import
register_import(impData,_filter,_mime_type) register_import(impData,_filter,_mime_type)
#register_import(readData,_title_string)

View File

@ -58,9 +58,9 @@ _title_string = _("Export to GRAMPS package")
# writeData # writeData
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def writeData(database,person): def writeData(database,filename):
try: try:
PackageWriter(database) PackageWriter(database,filename)
except: except:
import DisplayTrace import DisplayTrace
DisplayTrace.DisplayTrace() DisplayTrace.DisplayTrace()
@ -72,37 +72,12 @@ def writeData(database,person):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class PackageWriter: class PackageWriter:
def __init__(self,database): def __init__(self,database,filename):
self.db = database self.db = database
choose = gtk.FileChooserDialog(_('Save GRAMPS Package'), if os.path.splitext(filename)[1] != ".gpkg":
None, filename = filename + ".gpkg"
gtk.FILE_CHOOSER_ACTION_SAVE, self.export(filename)
(gtk.STOCK_CANCEL,
gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN,
gtk.RESPONSE_OK))
choose.set_local_only(gtk.FALSE)
filter = gtk.FileFilter()
filter.set_name(_('GRAMPS package'))
filter.add_pattern('*.gpkg')
choose.add_filter(filter)
response = choose.run()
if response == gtk.RESPONSE_OK:
name = choose.get_filename()
if os.path.splitext(name)[1] != ".gpkg":
name = name + ".gpkg"
choose.destroy()
self.export(name)
else:
choose.destroy()
def on_help_clicked(self,obj):
"""Display the relevant portion of GRAMPS manual"""
gnome.help_display('gramps-manual','export-data')
def export(self, filename): def export(self, filename):
missmedia_action = 0 missmedia_action = 0
@ -222,6 +197,11 @@ class PackageWriter:
# Register the plugin # Register the plugin
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Plugins import register_export _mime_type = 'application/x-gramps-package'
_filter = gtk.FileFilter()
_filter.set_name(_('GRAMPS packages'))
_filter.add_mime_type(_mime_type)
_ext_list = ('.gpkg',)
register_export(writeData,_title_string) from Plugins import register_export
register_export(writeData,_filter,_ext_list)