* src/plugins/WriteGedcom.py: Rewrite to enable passing the

options interface.
* src/Exporter.py: Use options if given by the plugin.


svn: r3262
This commit is contained in:
Alex Roitman 2004-07-11 06:03:07 +00:00
parent 0ce3d714e5
commit 53396a3d49
3 changed files with 200 additions and 156 deletions

View File

@ -3,6 +3,10 @@
* src/Exporter.py: Clean up, add doc strings. * src/Exporter.py: Clean up, add doc strings.
* src/plugins/WriteGedcom.py: Change registration. * src/plugins/WriteGedcom.py: Change registration.
* src/plugins/WriteGedcom.py: Rewrite to enable passing the
options interface.
* src/Exporter.py: Use options if given by the plugin.
2004-07-09 Don Allingham <dallingham@users.sourceforge.net> 2004-07-09 Don Allingham <dallingham@users.sourceforge.net>
* src/AddMedia.py: Handle the new file selector * src/AddMedia.py: Handle the new file selector
* src/MediaView.py: redraw list properly * src/MediaView.py: redraw list properly

View File

@ -76,9 +76,9 @@ class Exporter:
self.parent = parent self.parent = parent
self.parent_window = parent_window self.parent_window = parent_window
if self.parent.active_person: if self.parent.active_person:
self.active_person = self.parent.active_person self.person = self.parent.active_person
else: else:
self.active_person = self.parent.find_initial_person() self.person = self.parent.find_initial_person()
self.build_exports() self.build_exports()
self.confirm_label = gtk.Label() self.confirm_label = gtk.Label()
@ -90,18 +90,19 @@ class Exporter:
self.logo = gtk.gdk.pixbuf_new_from_file("%s/gramps.png" % const.rootDir) self.logo = gtk.gdk.pixbuf_new_from_file("%s/gramps.png" % const.rootDir)
self.splash = gtk.gdk.pixbuf_new_from_file("%s/splash.jpg" % const.rootDir) self.splash = gtk.gdk.pixbuf_new_from_file("%s/splash.jpg" % const.rootDir)
d = gnome.ui.Druid() self.d = gnome.ui.Druid()
self.w.add(d) self.w.add(self.d)
d.add(self.build_info_page()) self.d.add(self.build_info_page())
d.add(self.build_format_page()) self.d.add(self.build_format_page())
d.add(self.build_file_sel_page()) self.file_sel_page = self.build_file_sel_page()
d.add(self.build_confirm_page()) self.d.add(self.file_sel_page)
self.d.add(self.build_confirm_page())
self.last_page = self.build_last_page() self.last_page = self.build_last_page()
d.add(self.last_page) self.d.add(self.last_page)
d.set_show_help(gtk.TRUE) self.d.set_show_help(gtk.TRUE)
d.connect('cancel',self.close) self.d.connect('cancel',self.close)
d.connect('help',self.help) self.d.connect('help',self.help)
self.w.connect("destroy_event",self.close) self.w.connect("destroy_event",self.close)
self.w.set_transient_for(self.parent_window) self.w.set_transient_for(self.parent_window)
@ -202,7 +203,11 @@ class Exporter:
""" """
filename = self.chooser.get_filename() filename = self.chooser.get_filename()
ix = self.get_selected_format_index() ix = self.get_selected_format_index()
success = self.exports[ix][0](self.parent.db,filename) if self.exports[ix][3]:
success = self.exports[ix][0](self.parent.db,filename,self.person,
self.option_box_instance)
else:
success = self.exports[ix][0](self.parent.db,filename,self.person)
if success: if success:
self.last_page.set_title(_('Your data has been saved')) self.last_page.set_title(_('Your data has been saved'))
self.last_page.set_text(_('The copy of your data has been ' self.last_page.set_text(_('The copy of your data has been '
@ -256,8 +261,25 @@ class Exporter:
box.add(table) box.add(table)
box.show_all() box.show_all()
p.connect('next',self.build_options)
return p return p
def build_options(self,obj,obj2):
ix = self.get_selected_format_index()
if self.exports[ix][3]:
title = self.exports[ix][3][0]
option_box_class = self.exports[ix][3][1]
self.option_box_instance = option_box_class(self.person)
p = gnome.ui.DruidPageStandard()
p.set_title(title)
p.set_title_foreground(self.fg_color)
p.set_background(self.bg_color)
p.set_logo(self.logo)
p.append_item("",self.option_box_instance.get_option_box(),"")
self.d.insert_page(self.file_sel_page,p)
p.show_all()
def build_file_sel_page(self): def build_file_sel_page(self):
""" """
Build a druid page embedding the FileChooserWidget. Build a druid page embedding the FileChooserWidget.
@ -298,7 +320,7 @@ class Exporter:
else: else:
return 0 return 0
def native_export(self,database,filename): def native_export(self,database,filename,person):
""" """
Native database export. For now, just stupid copying of the present Native database export. For now, just stupid copying of the present
grdb file under another name. In the future, filter and other grdb file under another name. In the future, filter and other

View File

@ -343,90 +343,71 @@ def writeData(database,person):
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class GedcomWriter: class GedcomWriterOptionBox:
"""Writes a GEDCOM file from the passed database""" """
def __init__(self,db,person,cl=0,name=""): Create a VBox with the option widgets and define methods to retrieve
self.db = db the options.
"""
def __init__(self,person):
self.person = person self.person = person
def get_option_box(self):
self.restrict = 1 self.restrict = 1
self.private = 1 self.private = 1
self.cnvtxt = ansel_utf8.utf8_to_ansel self.cnvtxt = ansel_utf8.utf8_to_ansel
self.plist = {}
self.slist = {}
self.flist = {}
self.adopt = GedcomInfo.ADOPT_EVENT self.adopt = GedcomInfo.ADOPT_EVENT
self.fidval = 0
self.fidmap = {}
self.pidval = 0
self.pidmap = {}
self.sidval = 0
self.sidmap = {}
self.cl = cl
self.name = name
if self.cl: glade_file = "%s/gedcomexport.glade" % os.path.dirname(__file__)
self.cl_setup() self.topDialog = gtk.glade.XML(glade_file,"gedcomExport","gramps")
else: self.topDialog.signal_autoconnect({
glade_file = "%s/gedcomexport.glade" % os.path.dirname(__file__)
self.topDialog = gtk.glade.XML(glade_file,"gedcomExport","gramps")
self.topDialog.signal_autoconnect({
"destroy_passed_object" : Utils.destroy_passed_object,
"gnu_free" : self.gnu_free, "gnu_free" : self.gnu_free,
"standard_copyright" : self.standard_copyright, "standard_copyright" : self.standard_copyright,
"no_copyright" : self.no_copyright, "no_copyright" : self.no_copyright,
"on_restrict_toggled": self.on_restrict_toggled, "on_restrict_toggled": self.on_restrict_toggled,
"on_ok_clicked" : self.on_ok_clicked,
"on_help_clicked" : self.on_help_clicked
}) })
Utils.set_titles(self.topDialog.get_widget('gedcomExport'), filter_obj = self.topDialog.get_widget("filter")
self.topDialog.get_widget('title'), self.copy = 0
_('GEDCOM export'))
filter_obj = self.topDialog.get_widget("filter") all = GenericFilter.GenericFilter()
self.copy = 0 all.set_name(_("Entire Database"))
all.add_rule(GenericFilter.Everyone([]))
all = GenericFilter.GenericFilter() des = GenericFilter.GenericFilter()
all.set_name(_("Entire Database")) des.set_name(_("Descendants of %s") % self.person.get_primary_name().get_name())
all.add_rule(GenericFilter.Everyone([])) des.add_rule(GenericFilter.IsDescendantOf([self.person.get_id()]))
des = GenericFilter.GenericFilter() ans = GenericFilter.GenericFilter()
des.set_name(_("Descendants of %s") % person.get_primary_name().get_name()) ans.set_name(_("Ancestors of %s") % self.person.get_primary_name().get_name())
des.add_rule(GenericFilter.IsDescendantOf([person.get_id()])) ans.add_rule(GenericFilter.IsAncestorOf([self.person.get_id()]))
ans = GenericFilter.GenericFilter() com = GenericFilter.GenericFilter()
ans.set_name(_("Ancestors of %s") % person.get_primary_name().get_name()) com.set_name(_("People with common ancestor with %s") %
ans.add_rule(GenericFilter.IsAncestorOf([person.get_id()])) self.person.get_primary_name().get_name())
com.add_rule(GenericFilter.HasCommonAncestorWith([self.person.get_id()]))
com = GenericFilter.GenericFilter() self.filter_menu = GenericFilter.build_filter_menu([all,des,ans,com])
com.set_name(_("People with common ancestor with %s") % filter_obj.set_menu(self.filter_menu)
person.get_primary_name().get_name())
com.add_rule(GenericFilter.HasCommonAncestorWith([person.get_id()]))
self.filter_menu = GenericFilter.build_filter_menu([all,des,ans,com]) gedmap = GedcomInfo.GedcomInfoDB()
filter_obj.set_menu(self.filter_menu)
gedmap = GedcomInfo.GedcomInfoDB() target_obj = self.topDialog.get_widget("target")
myMenu = gtk.Menu()
for name in gedmap.get_name_list():
menuitem = gtk.MenuItem(name)
myMenu.append(menuitem)
data = gedmap.get_description(name)
menuitem.set_data("data",data)
menuitem.show()
target_obj = self.topDialog.get_widget("target") target_obj.set_menu(myMenu)
myMenu = gtk.Menu() self.target_menu = myMenu
for name in gedmap.get_name_list():
menuitem = gtk.MenuItem(name) the_box = self.topDialog.get_widget('vbox1')
myMenu.append(menuitem) the_parent = self.topDialog.get_widget('dialog-vbox1')
data = gedmap.get_description(name) the_parent.remove(the_box)
menuitem.set_data("data",data) self.topDialog.get_widget("gedcomExport").destroy()
menuitem.show() return the_box
target_obj.set_menu(myMenu)
self.target_menu = myMenu
pathname = os.path.join (os.path.dirname(db.get_save_path()),
"export.ged")
filetgt = self.topDialog.get_widget('fileentry1')
filetgt.set_filename(pathname)
self.topDialog.get_widget("gedcomExport").show()
def gnu_free(self,obj): def gnu_free(self,obj):
self.copy = 1 self.copy = 1
@ -444,7 +425,7 @@ class GedcomWriter:
self.topDialog.get_widget("notes"), self.topDialog.get_widget("notes"),
self.topDialog.get_widget("sources")]) self.topDialog.get_widget("sources")])
def on_ok_clicked(self,obj): def parse_options(self):
self.restrict = self.topDialog.get_widget("restrict").get_active() self.restrict = self.topDialog.get_widget("restrict").get_active()
self.living = (self.restrict and self.living = (self.restrict and
@ -455,7 +436,7 @@ class GedcomWriter:
self.topDialog.get_widget("sources").get_active()) self.topDialog.get_widget("sources").get_active())
self.private = self.topDialog.get_widget("private").get_active() self.private = self.topDialog.get_widget("private").get_active()
cfilter = self.filter_menu.get_active().get_data("filter") self.cfilter = self.filter_menu.get_active().get_data("filter")
act_tgt = self.target_menu.get_active() act_tgt = self.target_menu.get_active()
self.target_ged = act_tgt.get_data("data") self.target_ged = act_tgt.get_data("data")
@ -482,58 +463,94 @@ class GedcomWriter:
self.cnvtxt = keep_utf8 self.cnvtxt = keep_utf8
self.nl = self.cnvtxt(self.target_ged.get_endl()) self.nl = self.cnvtxt(self.target_ged.get_endl())
name = unicode(self.topDialog.get_widget("filename").get_text())
if cfilter == None: # glade_file = "%s/gedcomexport.glade" % os.path.dirname(__file__)
for p in self.db.get_person_keys(): #
self.plist[p] = 1 # self.exprogress = gtk.glade.XML(glade_file,"exportprogress","gramps")
else: # self.exprogress.signal_autoconnect({
try: # "on_close_clicked" : Utils.destroy_passed_object
for p in cfilter.apply(self.db, self.db.get_person_keys()): # })
self.plist[p] = 1 #
except Errors.FilterError, msg: # Utils.set_titles(self.exprogress.get_widget('exportprogress'),
(m1,m2) = msg.messages() # self.exprogress.get_widget('title'),
ErrorDialog(m1,m2) # _('GEDCOM export'))
return #
# self.fbar = self.exprogress.get_widget("fbar")
# self.pbar = self.exprogress.get_widget("pbar")
# self.sbar = self.exprogress.get_widget("sbar")
# self.progress = self.exprogress.get_widget('exportprogress')
#
# closebtn = self.exprogress.get_widget("close")
# closebtn.connect("clicked",Utils.destroy_passed_object)
# closebtn.set_sensitive(0)
#
# self.export_data(name)
# closebtn.set_sensitive(1)
self.flist = {} class GedcomWriter:
def __init__(self,database,person,cl=0,filename="",option_box=None):
self.db = database
self.person = person
self.option_box = option_box
self.cl = cl
self.filename = filename
self.plist = {}
self.slist = {} self.slist = {}
for key in self.plist.keys(): self.flist = {}
p = self.db.get_person(key) self.fidval = 0
add_persons_sources(self.db,p,self.slist,self.private) self.fidmap = {}
for family_id in p.get_family_id_list(): self.pidval = 0
add_familys_sources(self.db,family_id,self.slist,self.private) self.pidmap = {}
self.flist[family_id] = 1 self.sidval = 0
self.sidmap = {}
if not option_box:
self.cl_setup()
else:
self.option_box.parse_options()
Utils.destroy_passed_object(obj) self.restrict = self.option_box.restrict
self.living = self.option_box.living
glade_file = "%s/gedcomexport.glade" % os.path.dirname(__file__) self.exclnotes = self.option_box.exclnotes
self.exclsrcs = self.option_box.exclsrcs
self.exprogress = gtk.glade.XML(glade_file,"exportprogress","gramps") self.private = self.option_box.private
self.exprogress.signal_autoconnect({ self.copy = self.option_box.copy
"on_close_clicked" : Utils.destroy_passed_object self.images = self.option_box.images
}) self.target_ged = self.option_box.target_ged
self.dest = self.option_box.dest
Utils.set_titles(self.exprogress.get_widget('exportprogress'), self.adopt = self.option_box.adopt
self.exprogress.get_widget('title'), self.conc = self.option_box.conc
_('GEDCOM export')) self.altname = self.option_box.altname
self.cal = self.option_box.cal
self.fbar = self.exprogress.get_widget("fbar") self.obje = self.option_box.obje
self.pbar = self.exprogress.get_widget("pbar") self.resi = self.option_box.resi
self.sbar = self.exprogress.get_widget("sbar") self.prefix = self.option_box.prefix
self.progress = self.exprogress.get_widget('exportprogress') self.source_refs = self.option_box.source_refs
self.cnvtxt = self.option_box.cnvtxt
closebtn = self.exprogress.get_widget("close") self.nl = self.option_box.nl
closebtn.connect("clicked",Utils.destroy_passed_object)
closebtn.set_sensitive(0) if self.option_box.cfilter == None:
for p in self.db.get_person_keys():
self.export_data(name) self.plist[p] = 1
closebtn.set_sensitive(1) else:
try:
def on_help_clicked(self,obj): for p in self.option_box.cfilter.apply(self.db, self.db.get_person_keys()):
"""Display the relevant portion of GRAMPS manual""" self.plist[p] = 1
gnome.help_display('gramps-manual','export-data') except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
return
self.flist = {}
self.slist = {}
for key in self.plist.keys():
p = self.db.get_person(key)
add_persons_sources(self.db,p,self.slist,self.option_box.private)
for family_id in p.get_family_id_list():
add_familys_sources(self.db,family_id,self.slist,self.option_box.private)
self.flist[family_id] = 1
def cl_setup(self): def cl_setup(self):
self.restrict = 0 self.restrict = 0
self.private = 0 self.private = 0
@ -569,23 +586,22 @@ class GedcomWriter:
add_familys_sources(self.db,family_id,self.slist,self.private) add_familys_sources(self.db,family_id,self.slist,self.private)
self.flist[family_id] = 1 self.flist[family_id] = 1
self.export_data(self.name)
def writeln(self,text): def writeln(self,text):
self.g.write('%s%s' % (text,self.nl)) self.g.write('%s%s' % (text,self.nl))
def export_data(self,filename): def export_data(self,filename):
self.dirname = os.path.dirname (filename) self.dirname = os.path.dirname (filename)
try: try:
self.g = open(filename,"w") self.g = open(filename,"w")
except IOError,msg: except IOError,msg:
msg2 = _("Could not create %s") % filename msg2 = _("Could not create %s") % filename
ErrorDialog(msg2,str(msg)) ErrorDialog(msg2,str(msg))
self.progress.destroy() # self.progress.destroy()
return return
except: except:
ErrorDialog(_("Could not create %s") % filename) ErrorDialog(_("Could not create %s") % filename)
self.progress.destroy() # self.progress.destroy()
return return
date = time.ctime(time.time()).split() date = time.ctime(time.time()).split()
@ -647,19 +663,19 @@ class GedcomWriter:
for key in pkeys: for key in pkeys:
self.write_person(self.db.get_person(key)) self.write_person(self.db.get_person(key))
index = index + 1 index = index + 1
if index%100 == 0 and not self.cl: #if index%100 == 0 and not self.cl:
self.pbar.set_fraction(index/nump) # self.pbar.set_fraction(index/nump)
while(gtk.events_pending()): # while(gtk.events_pending()):
gtk.mainiteration() # gtk.mainiteration()
if not self.cl: # if not self.cl:
self.pbar.set_fraction(1.0) # self.pbar.set_fraction(1.0)
self.write_families() self.write_families()
if self.source_refs: if self.source_refs:
self.write_sources() self.write_sources()
else: #else:
if not self.cl: # if not self.cl:
self.sbar.set_fraction(1.0) # self.sbar.set_fraction(1.0)
self.writeln("0 TRLR") self.writeln("0 TRLR")
self.g.close() self.g.close()
@ -760,13 +776,13 @@ class GedcomWriter:
self.writeln('2 _STAT %s' % f[2]) self.writeln('2 _STAT %s' % f[2])
break break
index = index + 1 # index = index + 1
if index % 100 == 0 and not self.cl: # if index % 100 == 0 and not self.cl:
self.fbar.set_fraction(index/nump) # self.fbar.set_fraction(index/nump)
while(gtk.events_pending()): # while(gtk.events_pending()):
gtk.mainiteration() # gtk.mainiteration()
if not self.cl: #if not self.cl:
self.fbar.set_fraction(1.0) # self.fbar.set_fraction(1.0)
def write_sources(self): def write_sources(self):
nump = float(len(self.slist)) nump = float(len(self.slist))
@ -785,12 +801,12 @@ class GedcomWriter:
if source.get_note(): if source.get_note():
self.write_long_text("NOTE",1,self.cnvtxt(source.get_note())) self.write_long_text("NOTE",1,self.cnvtxt(source.get_note()))
index = index + 1 index = index + 1
if index % 100 == 0 and not self.cl: # if index % 100 == 0 and not self.cl:
self.sbar.set_fraction(index/nump) # self.sbar.set_fraction(index/nump)
while(gtk.events_pending()): # while(gtk.events_pending()):
gtk.mainiteration() # gtk.mainiteration()
if not self.cl: # if not self.cl:
self.sbar.set_fraction(1.0) # self.sbar.set_fraction(1.0)
def write_person(self,person): def write_person(self,person):
self.writeln("0 @%s@ INDI" % self.pid(person.get_id())) self.writeln("0 @%s@ INDI" % self.pid(person.get_id()))
@ -1231,10 +1247,11 @@ class GedcomWriter:
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def exportData(database,filename): def exportData(database,filename,person,option_box):
ret = 0 ret = 0
try: try:
GedcomWriter(database,None,1,filename) gw = GedcomWriter(database,person,0,filename,option_box)
gw.export_data(filename)
ret = 1 ret = 1
except: except:
import DisplayTrace import DisplayTrace
@ -1249,7 +1266,8 @@ def exportData(database,filename):
_title = _('GE_DCOM 5.5') _title = _('GE_DCOM 5.5')
_description = _('GEDCOM is used to transfer data between genealogy programs. ' _description = _('GEDCOM is used to transfer data between genealogy programs. '
'Nearly all genealogy software will accept a GEDCOM file as input. ') 'Nearly all genealogy software will accept a GEDCOM file as input. ')
_config = None #option_box = GedcomWriterOptionBox()
_config = (_('GEDCOM export options'),GedcomWriterOptionBox)
_filename = 'ged' _filename = 'ged'
from Plugins import register_export from Plugins import register_export