* 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:
parent
bcbd65f783
commit
3c108b27b7
@ -4,6 +4,11 @@
|
||||
Connect handler to the filter change event; (get_new_filename): Make
|
||||
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>
|
||||
* src/gramps_main.py: disable find old "find" function
|
||||
* src/gramps.glade: enable TreeView find function
|
||||
|
@ -293,7 +293,7 @@ class NewNativeDbPrompter:
|
||||
filter.add_mime_type('application/x-gramps')
|
||||
choose.add_filter(filter)
|
||||
|
||||
new_filename = get_new_filename()
|
||||
new_filename = get_new_filename('grdb')
|
||||
|
||||
choose.set_filename(new_filename)
|
||||
choose.set_current_name(os.path.split(new_filename)[1])
|
||||
@ -344,25 +344,25 @@ class SaveAsDbPrompter:
|
||||
gtk.RESPONSE_OK))
|
||||
self.choose.set_local_only(gtk.FALSE)
|
||||
# Always add automatic (macth all files) filter
|
||||
filter = gtk.FileFilter()
|
||||
filter.set_name(_('By extension'))
|
||||
filter.add_pattern('*')
|
||||
self.choose.add_filter(filter)
|
||||
all_filter = gtk.FileFilter()
|
||||
all_filter.set_name(_('By extension'))
|
||||
all_filter.add_pattern('*')
|
||||
self.choose.add_filter(all_filter)
|
||||
|
||||
# Always add native format filter
|
||||
filter = gtk.FileFilter()
|
||||
filter.set_name(_('GRAMPS databases'))
|
||||
filter.add_mime_type('application/x-gramps')
|
||||
self.choose.add_filter(filter)
|
||||
native_filter = gtk.FileFilter()
|
||||
native_filter.set_name(_('GRAMPS databases'))
|
||||
native_filter.add_mime_type('application/x-gramps')
|
||||
self.choose.add_filter(native_filter)
|
||||
|
||||
chooser_default = self.choose.get_children()[0].get_children()[0].get_children()[0]
|
||||
chooser_default.connect('notify::filter',self.change_suggested_name)
|
||||
chooser_default = self.choose.get_children()[0].get_children()[0].get_children()[0]
|
||||
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:
|
||||
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_current_name(os.path.split(new_filename)[1])
|
||||
|
||||
@ -372,8 +372,13 @@ class SaveAsDbPrompter:
|
||||
filename = os.path.normpath(os.path.abspath(filename))
|
||||
(junk,the_file) = os.path.split(filename)
|
||||
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()
|
||||
try:
|
||||
shutil.copyfile(self.parent.db.get_save_path(),filename)
|
||||
@ -384,7 +389,11 @@ class SaveAsDbPrompter:
|
||||
return 0
|
||||
|
||||
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()
|
||||
exportData(self.parent.db,filename)
|
||||
return 1
|
||||
@ -403,20 +412,24 @@ class SaveAsDbPrompter:
|
||||
"""
|
||||
the_filter = self.choose.get_filter()
|
||||
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:
|
||||
new_filename = get_new_filename()
|
||||
self.choose.set_current_name(os.path.split(new_filename)[1])
|
||||
|
||||
new_filename = get_new_filename('grdb')
|
||||
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
|
||||
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
|
||||
return os.path.expanduser('~/Untitled_%d.grdb' % ix )
|
||||
|
||||
return os.path.expanduser(_NEW_NAME_PATTERN % (ix,ext))
|
||||
|
@ -815,7 +815,7 @@ _mime_type = 'data.gramps'
|
||||
_filter = gtk.FileFilter()
|
||||
_filter.set_name(_('GRAMPS XML databases'))
|
||||
_filter.add_pattern(_mime_type)
|
||||
_ext_list = '.gramps'
|
||||
_ext_list = ('.gramps',)
|
||||
|
||||
from Plugins import register_export
|
||||
register_export(exportData,_filter,_ext_list)
|
||||
|
@ -50,7 +50,6 @@ _title_string = _("GRAMPS package")
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def impData(database, name,cb=None,cl=0):
|
||||
print "name1:", name
|
||||
# Create tempdir, if it does not exist, then check for writability
|
||||
tmpdir_path = os.path.expanduser("~/.gramps/tmp" )
|
||||
if not os.path.isdir(tmpdir_path):
|
||||
@ -68,7 +67,6 @@ def impData(database, name,cb=None,cl=0):
|
||||
for filename in files:
|
||||
os.remove( os.path.join(tmpdir_path,filename) )
|
||||
|
||||
print "name2:", name
|
||||
try:
|
||||
t = TarFile.ReadTarFile(name,tmpdir_path)
|
||||
t.extract()
|
||||
@ -186,9 +184,8 @@ def impData(database, name,cb=None,cl=0):
|
||||
#------------------------------------------------------------------------
|
||||
_mime_type = 'application/x-gramps-package'
|
||||
_filter = gtk.FileFilter()
|
||||
_filter.set_name(_('GRAMPS package'))
|
||||
_filter.set_name(_('GRAMPS packages'))
|
||||
_filter.add_mime_type(_mime_type)
|
||||
|
||||
from Plugins import register_import
|
||||
register_import(impData,_filter,_mime_type)
|
||||
#register_import(readData,_title_string)
|
||||
|
@ -58,9 +58,9 @@ _title_string = _("Export to GRAMPS package")
|
||||
# writeData
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def writeData(database,person):
|
||||
def writeData(database,filename):
|
||||
try:
|
||||
PackageWriter(database)
|
||||
PackageWriter(database,filename)
|
||||
except:
|
||||
import DisplayTrace
|
||||
DisplayTrace.DisplayTrace()
|
||||
@ -72,37 +72,12 @@ def writeData(database,person):
|
||||
#-------------------------------------------------------------------------
|
||||
class PackageWriter:
|
||||
|
||||
def __init__(self,database):
|
||||
def __init__(self,database,filename):
|
||||
self.db = database
|
||||
|
||||
choose = gtk.FileChooserDialog(_('Save GRAMPS Package'),
|
||||
None,
|
||||
gtk.FILE_CHOOSER_ACTION_SAVE,
|
||||
(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')
|
||||
if os.path.splitext(filename)[1] != ".gpkg":
|
||||
filename = filename + ".gpkg"
|
||||
self.export(filename)
|
||||
|
||||
def export(self, filename):
|
||||
missmedia_action = 0
|
||||
@ -222,6 +197,11 @@ class PackageWriter:
|
||||
# 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)
|
||||
|
Loading…
Reference in New Issue
Block a user