* src/ArgHandler.py (handle_args): Add import callback call.
* src/gramps_main.py: Use open filters, mime types, and handlers from import plugins. * src/Plugins.py: Change import plugin registration. * src/ReadXML.py: Change registration. * src/plugins/ReadGedcom.py: Change registration. * src/plugins/ReadPkg.py: Rewrite and change registration. svn: r3231
This commit is contained in:
parent
e8dd8dde0b
commit
2137e803e4
@ -1,3 +1,12 @@
|
|||||||
|
2004-06-23 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||||
|
* src/ArgHandler.py (handle_args): Add import callback call.
|
||||||
|
* src/gramps_main.py: Use open filters, mime types, and handlers
|
||||||
|
from import plugins.
|
||||||
|
* src/Plugins.py: Change import plugin registration.
|
||||||
|
* src/ReadXML.py: Change registration.
|
||||||
|
* src/plugins/ReadGedcom.py: Change registration.
|
||||||
|
* src/plugins/ReadPkg.py: Rewrite and change registration.
|
||||||
|
|
||||||
2004-06-22 Don Allingham <dallingham@users.sourceforge.net>
|
2004-06-22 Don Allingham <dallingham@users.sourceforge.net>
|
||||||
* src/EditPerson,py: allow reordering of event columns
|
* src/EditPerson,py: allow reordering of event columns
|
||||||
* src/TransTable.py: allow to be initialized with a list instead of a map
|
* src/TransTable.py: allow to be initialized with a list instead of a map
|
||||||
|
@ -282,6 +282,9 @@ class ArgHandler:
|
|||||||
os.remove(self.imp_db_path)
|
os.remove(self.imp_db_path)
|
||||||
print "Exiting."
|
print "Exiting."
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
|
if self.imports:
|
||||||
|
self.parent.import_tool_callback()
|
||||||
elif GrampsCfg.lastfile and GrampsCfg.autoload:
|
elif GrampsCfg.lastfile and GrampsCfg.autoload:
|
||||||
if self.parent.auto_save_load(GrampsCfg.lastfile) == 0:
|
if self.parent.auto_save_load(GrampsCfg.lastfile) == 0:
|
||||||
DbPrompter.DbPrompter(self.parent,0,self.parent.topWindow)
|
DbPrompter.DbPrompter(self.parent,0,self.parent.topWindow)
|
||||||
|
@ -464,9 +464,14 @@ def register_export(task, name):
|
|||||||
"""Register an export filter, taking the task and name"""
|
"""Register an export filter, taking the task and name"""
|
||||||
_exports.append((task, name))
|
_exports.append((task, name))
|
||||||
|
|
||||||
def register_import(task, name):
|
#def register_import(task, name):
|
||||||
"""Register an import filter, taking the task and name"""
|
# """Register an import filter, taking the task and name"""
|
||||||
_imports.append((task, name))
|
# _imports.append((task, name))
|
||||||
|
|
||||||
|
def register_import(task, ffilter, mime=None):
|
||||||
|
"""Register an import filter, taking the task and file filter"""
|
||||||
|
if mime:
|
||||||
|
_imports.append((task, ffilter, mime))
|
||||||
|
|
||||||
def register_report(task, name,
|
def register_report(task, name,
|
||||||
category=_("Uncategorized"),
|
category=_("Uncategorized"),
|
||||||
|
@ -30,6 +30,7 @@ import os
|
|||||||
import gtk
|
import gtk
|
||||||
import shutil
|
import shutil
|
||||||
import xml.parsers.expat
|
import xml.parsers.expat
|
||||||
|
from gettext import gettext as _
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -37,7 +38,6 @@ import xml.parsers.expat
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from QuestionDialog import ErrorDialog, WarningDialog, MissingMediaDialog
|
from QuestionDialog import ErrorDialog, WarningDialog, MissingMediaDialog
|
||||||
from gettext import gettext as _
|
|
||||||
import Calendar
|
import Calendar
|
||||||
import Date
|
import Date
|
||||||
import GrampsMime
|
import GrampsMime
|
||||||
@ -61,7 +61,7 @@ except:
|
|||||||
# Must takes care of renaming media files according to their new IDs.
|
# Must takes care of renaming media files according to their new IDs.
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def importData(database, filename, callback,cl=0):
|
def importData(database, filename, callback=None,cl=0):
|
||||||
|
|
||||||
filename = os.path.normpath(filename)
|
filename = os.path.normpath(filename)
|
||||||
basefile = os.path.dirname(filename)
|
basefile = os.path.dirname(filename)
|
||||||
@ -1159,3 +1159,15 @@ def build_place_title(loc):
|
|||||||
value = append_value(value,country)
|
value = append_value(value,country)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
_mime_type = 'data.gramps'
|
||||||
|
_filter = gtk.FileFilter()
|
||||||
|
_filter.set_name(_('GRAMPS XML databases'))
|
||||||
|
_filter.add_pattern(_mime_type)
|
||||||
|
|
||||||
|
from Plugins import register_import
|
||||||
|
register_import(importData,_filter,_mime_type)
|
||||||
|
@ -1466,23 +1466,28 @@ class Gramps:
|
|||||||
def on_open_activate(self,obj):
|
def on_open_activate(self,obj):
|
||||||
|
|
||||||
choose = gtk.FileChooserDialog('Open GRAMPS database',
|
choose = gtk.FileChooserDialog('Open GRAMPS database',
|
||||||
None,
|
self.topWindow,
|
||||||
gtk.FILE_CHOOSER_ACTION_OPEN,
|
gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||||
(gtk.STOCK_CANCEL,
|
(gtk.STOCK_CANCEL,
|
||||||
gtk.RESPONSE_CANCEL,
|
gtk.RESPONSE_CANCEL,
|
||||||
gtk.STOCK_OPEN,
|
gtk.STOCK_OPEN,
|
||||||
gtk.RESPONSE_OK))
|
gtk.RESPONSE_OK))
|
||||||
|
|
||||||
|
# Always add automatic (macth all files) filter
|
||||||
filter = gtk.FileFilter()
|
filter = gtk.FileFilter()
|
||||||
filter.set_name(_('GRAMPS databases'))
|
filter.set_name(_('Automatic'))
|
||||||
filter.add_pattern('*.grdb')
|
|
||||||
choose.add_filter(filter)
|
|
||||||
|
|
||||||
filter = gtk.FileFilter()
|
|
||||||
filter.set_name(_('All files'))
|
|
||||||
filter.add_pattern('*')
|
filter.add_pattern('*')
|
||||||
choose.add_filter(filter)
|
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)
|
||||||
|
|
||||||
|
for (importData,filter,mime_type) in Plugins._imports:
|
||||||
|
choose.add_filter(filter)
|
||||||
|
|
||||||
if GrampsCfg.lastfile:
|
if GrampsCfg.lastfile:
|
||||||
choose.set_filename(GrampsCfg.lastfile)
|
choose.set_filename(GrampsCfg.lastfile)
|
||||||
|
|
||||||
@ -1491,8 +1496,28 @@ class Gramps:
|
|||||||
filename = choose.get_filename()
|
filename = choose.get_filename()
|
||||||
filename = os.path.normpath(os.path.abspath(filename))
|
filename = os.path.normpath(os.path.abspath(filename))
|
||||||
self.clear_database()
|
self.clear_database()
|
||||||
if self.auto_save_load(filename) == 0:
|
filetype = gnome.vfs.get_mime_type(filename)
|
||||||
DbPrompter.DbPrompter(self,0,self.topWindow)
|
(junk,the_file) = os.path.split(filename)
|
||||||
|
|
||||||
|
if filetype == 'application/x-gramps':
|
||||||
|
if self.auto_save_load(filename) == 0:
|
||||||
|
DbPrompter.DbPrompter(self,0,self.topWindow)
|
||||||
|
else:
|
||||||
|
opened = 0
|
||||||
|
for (importData,filter,mime_type) in Plugins._imports:
|
||||||
|
if filetype == mime_type or the_file == mime_type:
|
||||||
|
OkDialog( _("Opening non-native format"),
|
||||||
|
_("New gramps database has to be set up when opening non-native formats. The following dialog will let you select the new database."),
|
||||||
|
self.topWindow)
|
||||||
|
DbPrompter.DbPrompter(self,1,self.topWindow,filename)
|
||||||
|
print "filename:", filename
|
||||||
|
importData(self.db,filename)
|
||||||
|
self.import_tool_callback()
|
||||||
|
opened = 1
|
||||||
|
break
|
||||||
|
if not opened:
|
||||||
|
ErrorDialog( _("Could not open file: %s") % filename,
|
||||||
|
_('The type "%s" is not in the list of known file types') % filetype )
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
|
|
||||||
def on_revert_activate(self,obj):
|
def on_revert_activate(self,obj):
|
||||||
|
@ -1802,10 +1802,16 @@ def readData(database,active_person,cb):
|
|||||||
else:
|
else:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
|
|
||||||
|
|
||||||
|
_mime_type = 'application/x-gedcom'
|
||||||
|
_filter = gtk.FileFilter()
|
||||||
|
_filter.set_name(_('GEDCOM files'))
|
||||||
|
_filter.add_mime_type(_mime_type)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from Plugins import register_import
|
from Plugins import register_import
|
||||||
register_import(readData,_title_string)
|
register_import(importData,_filter,_mime_type)
|
||||||
|
@ -41,49 +41,16 @@ _title_string = _("GRAMPS package")
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def readData(database,active_person,cb):
|
#def readData(database,active_person,cb):
|
||||||
ReadPkg(database,active_person,cb)
|
# ReadPkg(database,active_person,cb)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class ReadPkg:
|
def impData(database, name,cb=None,cl=0):
|
||||||
def __init__(self,database,active_person,cb):
|
print "name1:", name
|
||||||
self.db = database
|
|
||||||
self.callback = cb
|
|
||||||
|
|
||||||
self.top = gtk.FileSelection("%s - GRAMPS" % _title_string)
|
|
||||||
self.top.hide_fileop_buttons()
|
|
||||||
self.top.ok_button.connect('clicked', self.on_ok_clicked)
|
|
||||||
self.top.cancel_button.connect('clicked', self.close_window)
|
|
||||||
self.top.show()
|
|
||||||
|
|
||||||
def close_window(self,obj):
|
|
||||||
self.top.destroy()
|
|
||||||
|
|
||||||
def show_display(self):
|
|
||||||
self.window = gtk.Window()
|
|
||||||
self.window.set_title(_title_string)
|
|
||||||
vbox = gtk.VBox()
|
|
||||||
self.window.add(vbox)
|
|
||||||
label = gtk.Label(_title_string)
|
|
||||||
vbox.add(label)
|
|
||||||
adj = gtk.Adjustment(lower=0,upper=100)
|
|
||||||
self.progress_bar = gtk.ProgressBar(adj)
|
|
||||||
vbox.add(self.progress_bar)
|
|
||||||
self.window.show_all()
|
|
||||||
|
|
||||||
def on_ok_clicked(self,obj):
|
|
||||||
|
|
||||||
name = self.top.get_filename()
|
|
||||||
if name == "":
|
|
||||||
return
|
|
||||||
|
|
||||||
Utils.destroy_passed_object(self.top)
|
|
||||||
self.show_display()
|
|
||||||
|
|
||||||
# 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):
|
||||||
@ -101,18 +68,21 @@ class ReadPkg:
|
|||||||
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()
|
||||||
t.close()
|
t.close()
|
||||||
except:
|
except:
|
||||||
|
print "name3:", name
|
||||||
|
print tmpdir_path
|
||||||
ErrorDialog(_("Error extracting into %s") % tmpdir_path )
|
ErrorDialog(_("Error extracting into %s") % tmpdir_path )
|
||||||
return
|
return
|
||||||
|
|
||||||
dbname = os.path.join(tmpdir_path,const.xmlFile)
|
dbname = os.path.join(tmpdir_path,const.xmlFile)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
importData(self.db,dbname,self.progress)
|
importData(database,dbname,cb)
|
||||||
except:
|
except:
|
||||||
import DisplayTrace
|
import DisplayTrace
|
||||||
DisplayTrace.DisplayTrace()
|
DisplayTrace.DisplayTrace()
|
||||||
@ -124,19 +94,101 @@ class ReadPkg:
|
|||||||
|
|
||||||
os.rmdir(tmpdir_path)
|
os.rmdir(tmpdir_path)
|
||||||
|
|
||||||
self.window.destroy()
|
#class ReadPkg:
|
||||||
self.callback()
|
# def __init__(self,database,active_person,cb):
|
||||||
|
# self.db = database
|
||||||
def progress(self,val):
|
# self.callback = cb
|
||||||
self.progress_bar.set_fraction(val)
|
#
|
||||||
while gtk.events_pending():
|
# self.top = gtk.FileSelection("%s - GRAMPS" % _title_string)
|
||||||
gtk.mainiteration()
|
# self.top.hide_fileop_buttons()
|
||||||
|
# self.top.ok_button.connect('clicked', self.on_ok_clicked)
|
||||||
|
# self.top.cancel_button.connect('clicked', self.close_window)
|
||||||
|
# self.top.show()
|
||||||
|
#
|
||||||
|
# def close_window(self,obj):
|
||||||
|
# self.top.destroy()
|
||||||
|
#
|
||||||
|
# def show_display(self):
|
||||||
|
# self.window = gtk.Window()
|
||||||
|
# self.window.set_title(_title_string)
|
||||||
|
# vbox = gtk.VBox()
|
||||||
|
# self.window.add(vbox)
|
||||||
|
# label = gtk.Label(_title_string)
|
||||||
|
# vbox.add(label)
|
||||||
|
# adj = gtk.Adjustment(lower=0,upper=100)
|
||||||
|
# self.progress_bar = gtk.ProgressBar(adj)
|
||||||
|
# vbox.add(self.progress_bar)
|
||||||
|
# self.window.show_all()
|
||||||
|
#
|
||||||
|
# def on_ok_clicked(self,obj):
|
||||||
|
#
|
||||||
|
# name = self.top.get_filename()
|
||||||
|
# if name == "":
|
||||||
|
# return
|
||||||
|
#
|
||||||
|
# Utils.destroy_passed_object(self.top)
|
||||||
|
# self.show_display()
|
||||||
|
#
|
||||||
|
# # 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):
|
||||||
|
# try:
|
||||||
|
# os.mkdir(tmpdir_path,0700)
|
||||||
|
# except:
|
||||||
|
# ErrorDialog( _("Could not create temporary directory %s") %
|
||||||
|
# tmpdir_path )
|
||||||
|
# return
|
||||||
|
# elif not os.access(tmpdir_path,os.W_OK):
|
||||||
|
# ErrorDialog( _("Temporary directory %s is not writable") % tmpdir_path )
|
||||||
|
# return
|
||||||
|
# else: # tempdir exists and writable -- clean it up if not empty
|
||||||
|
# files = os.listdir(tmpdir_path) ;
|
||||||
|
# for filename in files:
|
||||||
|
# os.remove( os.path.join(tmpdir_path,filename) )
|
||||||
|
#
|
||||||
|
# try:
|
||||||
|
# t = TarFile.ReadTarFile(name,tmpdir_path)
|
||||||
|
# t.extract()
|
||||||
|
# except:
|
||||||
|
# ErrorDialog(_("Error extracting into %s") % tmpdir_path )
|
||||||
|
# return
|
||||||
|
#
|
||||||
|
# dbname = os.path.join(tmpdir_path,const.xmlFile)
|
||||||
|
#
|
||||||
|
# try:
|
||||||
|
# importData(self.db,dbname,self.progress)
|
||||||
|
# except:
|
||||||
|
# import DisplayTrace
|
||||||
|
# DisplayTrace.DisplayTrace()
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# # Clean up tempdir after ourselves
|
||||||
|
# files = os.listdir(tmpdir_path)
|
||||||
|
# for filename in files:
|
||||||
|
# os.remove(os.path.join(tmpdir_path,filename))
|
||||||
|
#
|
||||||
|
# os.rmdir(tmpdir_path)
|
||||||
|
#
|
||||||
|
# self.window.destroy()
|
||||||
|
# self.callback()
|
||||||
|
#
|
||||||
|
# def progress(self,val):
|
||||||
|
# self.progress_bar.set_fraction(val)
|
||||||
|
# while gtk.events_pending():
|
||||||
|
# gtk.mainiteration()
|
||||||
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Register with the plugin system
|
# Register with the plugin system
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
from Plugins import register_import
|
_mime_type = 'application/x-gramps-package'
|
||||||
|
_filter = gtk.FileFilter()
|
||||||
|
_filter.set_name(_('GRAMPS package'))
|
||||||
|
_filter.add_mime_type(_mime_type)
|
||||||
|
|
||||||
register_import(readData,_title_string)
|
from Plugins import register_import
|
||||||
|
register_import(impData,_filter,_mime_type)
|
||||||
|
#register_import(readData,_title_string)
|
||||||
|
Loading…
Reference in New Issue
Block a user