* src/DbPrompter.py (format_maker): Add mnemonic activation target

to the format selector label; Use new import format; don't treat
native formats as plugins anymore.
* src/PluginMgr.py: Add format name to import registration.
* src/ReadGedcom.py: Cleanups; Don't register already native import.
* src/ReadXML.py: Don't register already native import.
* src/data/gramps.xml: Add magic patterns for XML, GEDCOM, and GW.
* src/plugins/ImportGeneWeb.py: Register with format name.
* src/plugins/ReadNative.py: Remove obsolete file.
* src/plugins/ReadPkg.py: Lots of cleanups; Register with format name.


svn: r4105
This commit is contained in:
Alex Roitman 2005-02-28 01:51:21 +00:00
parent b93465e70e
commit c36385735a
9 changed files with 116 additions and 340 deletions

View File

@ -1,3 +1,15 @@
2005-02-27 Alex Roitman <shura@alex.neuro.umn.edu>
* src/DbPrompter.py (format_maker): Add mnemonic activation target
to the format selector label; Use new import format; don't treat
native formats as plugins anymore.
* src/PluginMgr.py: Add format name to import registration.
* src/ReadGedcom.py: Cleanups; Don't register already native import.
* src/ReadXML.py: Don't register already native import.
* src/data/gramps.xml: Add magic patterns for XML, GEDCOM, and GW.
* src/plugins/ImportGeneWeb.py: Register with format name.
* src/plugins/ReadNative.py: Remove obsolete file.
* src/plugins/ReadPkg.py: Lots of cleanups; Register with format name.
2005-02-27 Don Allingham <dallingham@users.sourceforge.net>
* src/plugins/NavWebPage.py: add the ability to have notes
attached to the Introduction and Home pages

View File

@ -161,11 +161,11 @@ class ExistingDbPrompter:
format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom]
# Add more data type selections if opening existing db
for (importData,mime_filter,mime_type,native_format) in PluginMgr.import_list:
for (importData,mime_filter,mime_type,native_format,format_name) in PluginMgr.import_list:
if not native_format:
choose.add_filter(mime_filter)
format_list.append(mime_type)
_KNOWN_FORMATS[mime_type] = mime_filter.get_name()
_KNOWN_FORMATS[mime_type] = format_name
(box,type_selector) = format_maker(format_list)
choose.set_extra_widget(box)
@ -202,7 +202,7 @@ class ExistingDbPrompter:
# The above native formats did not work, so we need to
# look up the importer for this format
# and create an empty native database to import data in
for (importData,mime_filter,mime_type,native_format) in PluginMgr.import_list:
for (importData,mime_filter,mime_type,native_format,format_name) in PluginMgr.import_list:
if filetype == mime_type or the_file == mime_type:
QuestionDialog.OkDialog(
_("Opening non-native format"),
@ -260,14 +260,17 @@ class ImportDbPrompter:
# Always add automatic (macth all files) filter
add_all_files_filter(choose)
add_grdb_filter(choose)
add_xml_filter(choose)
add_gedcom_filter(choose)
format_list = [const.app_gramps]
format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom]
# Add more data type selections if opening existing db
for (importData,mime_filter,mime_type,native_format) in PluginMgr.import_list:
for (importData,mime_filter,mime_type,native_format,format_name) in PluginMgr.import_list:
if not native_format:
choose.add_filter(mime_filter)
format_list.append(mime_type)
_KNOWN_FORMATS[mime_type] = mime_filter.get_name()
_KNOWN_FORMATS[mime_type] = format_name
(box,type_selector) = format_maker(format_list)
choose.set_extra_widget(box)
@ -298,7 +301,7 @@ class ImportDbPrompter:
(the_path,the_file) = os.path.split(filename)
GrampsKeys.save_last_import_dir(the_path)
for (importData,mime_filter,mime_type,native_format) in PluginMgr.import_list:
for (importData,mime_filter,mime_type,native_format,format_name) in PluginMgr.import_list:
if filetype == mime_type or the_file == mime_type:
choose.destroy()
importData(self.parent.db,filename)
@ -525,7 +528,11 @@ def open_native(parent,filename,filetype):
return success
#-------------------------------------------------------------------------
#
# Format selectors and filters
#
#-------------------------------------------------------------------------
class GrampsFormatWidget(gtk.ComboBox):
def __init__(self):
@ -566,7 +573,9 @@ def format_maker(formats):
type_selector.set(format_list)
box = gtk.HBox()
label = gtk.Label(_('Select file type:'))
label = gtk.Label(_('Select file _type:'))
label.set_use_underline(True)
label.set_mnemonic_widget(type_selector)
box.pack_start(label,expand=False,fill=False,padding=6)
box.add(type_selector)
box.show_all()
@ -594,7 +603,7 @@ def add_gramps_files_filter(chooser):
def add_grdb_filter(chooser):
"""
Add an GRDB filter to the file chooser dialog.
Add a GRDB filter to the file chooser dialog.
"""
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('GRAMPS databases'))

View File

@ -148,10 +148,10 @@ def register_export(exportData,title,description='',config=None,filename=''):
if description and filename:
export_list.append((exportData,title,description,config,filename))
def register_import(task, ffilter, mime=None, native_format=0):
def register_import(task, ffilter, mime=None, native_format=0, format_name=""):
"""Register an import filter, taking the task and file filter"""
if mime:
import_list.append((task, ffilter, mime, native_format))
import_list.append((task, ffilter, mime, native_format, format_name))
def register_tool(

View File

@ -32,6 +32,7 @@ import re
import string
import const
import time
from gettext import gettext as _
#-------------------------------------------------------------------------
#
@ -57,7 +58,6 @@ import Utils
import GrampsMime
from GedcomInfo import *
from QuestionDialog import ErrorDialog
from gettext import gettext as _
#-------------------------------------------------------------------------
#
@ -1950,6 +1950,11 @@ class GedcomParser:
def invert_year(self,subdate):
return (subdate[0],subdate[1],-subdate[2],subdate[3])
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def extract_temple(matches):
try:
if const.lds_temple_to_abrev.has_key(matches[2]):
@ -1960,65 +1965,5 @@ def extract_temple(matches):
except:
return None
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def readData(database,active_person,cb):
global callback
global file_topa
callback = cb
choose = gtk.FileChooserDialog("%s - GRAMPS" % _title_string,
None,
gtk.FILE_CHOOSER_ACTION_OPEN,
(gtk.STOCK_CANCEL,
gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN,
gtk.RESPONSE_OK))
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('GEDCOM files'))
mime_filter.add_pattern('*.ged')
mime_filter.add_pattern('*.GED')
choose.add_filter(mime_filter)
mime_filter = gtk.FileFilter()
mime_filter.set_name(_('All files'))
mime_filter.add_pattern('*')
choose.add_filter(mime_filter)
response = choose.run()
if response == gtk.RESPONSE_OK:
filename = choose.get_filename()
choose.destroy()
try:
importData(database,filename)
except:
DisplayTrace.DisplayTrace()
else:
choose.destroy()
_mime_type = 'application/x-gedcom'
_filter = gtk.FileFilter()
_filter.set_name(_('GEDCOM files'))
_filter.add_mime_type(_mime_type)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def create_id():
return Utils.create_id()
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
from PluginMgr import register_import
register_import(importData,_filter,_mime_type,1)

View File

@ -25,7 +25,6 @@
# Standard Python Modules
#
#-------------------------------------------------------------------------
import string
import os
import gtk
import shutil
@ -261,10 +260,10 @@ def importData(database, filename, callback=None,cl=0,use_trans=True):
#-------------------------------------------------------------------------
def rs(text):
return string.join(string.split(text))
return ' '.join(text.split())
def fix_spaces(text_list):
return string.join(map(rs,text_list),'\n')
return '\n'.join(map(rs,text_list))
#-------------------------------------------------------------------------
#
@ -1394,7 +1393,7 @@ class GrampsParser:
def endElement(self,tag):
if self.func:
self.func(string.join(self.tlist,''))
self.func(''.join(self.tlist))
self.func_index = self.func_index - 1
self.func,self.tlist = self.func_list[self.func_index]
@ -1429,16 +1428,3 @@ def build_place_title(loc):
if country:
value = append_value(value,country)
return value
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
_mime_type = 'data.gramps'
_filter = gtk.FileFilter()
_filter.set_name(_('GRAMPS XML databases'))
_filter.add_pattern(_mime_type)
from PluginMgr import register_import
register_import(importData,_filter,_mime_type,1)

View File

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id$ -->
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-gramps">
<comment xml:lang="en">GRAMPS database</comment>
@ -7,6 +10,9 @@
<mime-type type="application/x-gedcom">
<comment xml:lang="en">GEDCOM</comment>
<glob pattern="*.ged"/>
<magic priority="80">
<match type="string" value="0 HEAD" offset="0:1"/>
</magic>
</mime-type>
<mime-type type="application/x-gramps-package">
<comment xml:lang="en">GRAMPS package</comment>
@ -15,9 +21,18 @@
<mime-type type="application/x-gramps-xml">
<comment xml:lang="en">GRAMPS XML database</comment>
<glob pattern="*.gramps"/>
<magic priority="80">
<match type="string" value="&lt;!DOCTYPE database" offset="0:256"/>
<match type="string" value="&lt;database" offset="0:64"/>
</magic>
</mime-type>
<mime-type type="application/x-geneweb">
<comment xml:lang="en">GeneWeb source file</comment>
<glob pattern="*.gw"/>
<magic priority="80">
<match type="string" value="fam" offset="0:64"/>
<match type="string" value="beg" offset="0:64"/>
<match type="string" value="end" offset="0:64"/>
</magic>
</mime-type>
</mime-info>

View File

@ -679,6 +679,7 @@ _mime_type = const.app_geneweb
_filter = gtk.FileFilter()
_filter.set_name(_('GeneWeb files'))
_filter.add_mime_type(_mime_type)
_format_name = _('GeneWeb')
from PluginMgr import register_import
register_import(importData,_filter,_mime_type,1)
register_import(importData,_filter,_mime_type,0,_format_name)

View File

@ -1,109 +0,0 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2004 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$
#
# Modified by Alex Roitman to handle media object files.
#
"Import from Gramps database"
from ReadXML import *
import Utils
from gettext import gettext as _
import gtk
import const
import os
_title_string = _("GRAMPS XML database")
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def readData(database,active_person,cb):
ReadNative(database,active_person,cb)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
class ReadNative:
def __init__(self,database,active_person,cb):
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):
imp_dbpath = self.top.get_filename()
if imp_dbpath == "":
return
Utils.destroy_passed_object(self.top)
self.show_display()
dbname = os.path.join(imp_dbpath,const.xmlFile)
try:
importData(self.db,dbname,self.progress)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()
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
#
#------------------------------------------------------------------------
from PluginMgr import register_import
register_import(readData,_title_string)

View File

@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2004 Donald N. Allingham
# Copyright (C) 2000-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
@ -17,32 +17,36 @@
# 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 ReadNative.py by Don Allingham
#
"Import from Gramps package"
from ReadXML import *
import Utils
from gettext import gettext as _
import gtk
import const
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
import os
from QuestionDialog import ErrorDialog, WarningDialog
import TarFile
from gettext import gettext as _
_title_string = _("GRAMPS package")
#-------------------------------------------------------------------------
#
#
# GNOME/GTK+ modules
#
#-------------------------------------------------------------------------
#def readData(database,active_person,cb):
# ReadPkg(database,active_person,cb)
import gtk
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
import const
import ReadXML
from QuestionDialog import ErrorDialog
import TarFile
#-------------------------------------------------------------------------
#
@ -72,15 +76,13 @@ def impData(database, name,cb=None,cl=0):
t.extract()
t.close()
except:
print "name3:", name
print tmpdir_path
ErrorDialog(_("Error extracting into %s") % tmpdir_path )
return
dbname = os.path.join(tmpdir_path,const.xmlFile)
try:
importData(database,dbname,cb)
ReadXML.importData(database,dbname,cb)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()
@ -92,91 +94,6 @@ def impData(database, name,cb=None,cl=0):
os.rmdir(tmpdir_path)
#class ReadPkg:
# def __init__(self,database,active_person,cb):
# 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
# 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
@ -186,7 +103,7 @@ _mime_type = 'application/x-gramps-package'
_filter = gtk.FileFilter()
_filter.set_name(_('GRAMPS packages'))
_filter.add_mime_type(_mime_type)
_format_name = _('GRAMPS package')
from PluginMgr import register_import
register_import(impData,_filter,_mime_type)
register_import(impData,_filter,_mime_type,0,_format_name)