Enhanced support for GEDCOM writing.

svn: r591
This commit is contained in:
Don Allingham 2001-11-28 01:09:27 +00:00
parent 63848c4c70
commit 492d2cc56a
9 changed files with 390 additions and 224 deletions

View File

@ -459,10 +459,8 @@ class SingleDate:
return "%s%s%s" % (y,m,d)
def getSaveDate(self):
retval = ""
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
pass
return ""
elif self.day == UNDEF:
if self.month == UNDEF:
retval = str(self.year)
@ -485,11 +483,9 @@ class SingleDate:
retval = "BEFORE" + " " + retval
elif self.mode == SingleDate.after:
retval = "AFTER" + " " + retval
return retval
def getFmt1(self):
def get_fmt1(self):
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
return ""
elif self.day == UNDEF:
@ -514,10 +510,9 @@ class SingleDate:
retval = _("before") + ' ' + retval
elif self.mode == SingleDate.after:
retval = _("after") + ' ' + retval
return retval
def getFmt2(self):
def get_fmt2(self):
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
return ""
elif self.month != UNDEF and self.month != UNDEF:
@ -547,7 +542,7 @@ class SingleDate:
return retval
def getFmt3(self):
def get_fmt3(self):
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
return ""
elif self.day == UNDEF:
@ -574,10 +569,9 @@ class SingleDate:
retval = "%s %s" % (_("BEFORE"),retval)
elif self.mode == SingleDate.after:
retval = "%s %s" % (_("AFTER"),retval)
return retval
def getFmt10(self):
def get_fmt10(self):
if self.month == UNDEF and self.day == UNDEF and self.year == UNDEF :
return ""
elif self.day == UNDEF:
@ -663,13 +657,13 @@ class SingleDate:
return retval
def getFmt4(self):
def get_fmt4(self):
return self.get_mmddyyyy("/")
def getFmt5(self):
def get_fmt5(self):
return self.get_mmddyyyy("-")
def getFmt8(self):
def get_fmt8(self):
return self.get_mmddyyyy(".")
def get_ddmmyyyy(self,sep):
@ -701,22 +695,22 @@ class SingleDate:
return retval
def getFmt6(self):
def get_fmt6(self):
return self.get_ddmmyyyy("/")
def getFmt7(self):
def get_fmt7(self):
return self.get_ddmmyyyy("-")
def getFmt9(self):
def get_fmt9(self):
return self.get_ddmmyyyy(".")
def getFmt11(self):
def get_fmt11(self):
return self.get_yyyymmdd("/")
def getFmt12(self):
def get_fmt12(self):
return self.get_yyyymmdd("-")
def getFmt13(self):
def get_fmt13(self):
return self.get_yyyymmdd(".")
#--------------------------------------------------------------------
@ -724,9 +718,9 @@ class SingleDate:
#
#
#--------------------------------------------------------------------
fmtFunc = [ getFmt1, getFmt2, getFmt3, getFmt4, getFmt5, getFmt6,
getFmt7, getFmt8, getFmt9, getFmt10, getFmt11, getFmt12,
getFmt13]
fmtFunc = [ get_fmt1, get_fmt2, get_fmt3, get_fmt4, get_fmt5, get_fmt6,
get_fmt7, get_fmt8, get_fmt9, get_fmt10, get_fmt11, get_fmt12,
get_fmt13]
def display_calendar(self,month_map):
if self.year==UNDEF:
@ -735,7 +729,7 @@ class SingleDate:
elif self.day == UNDEF:
return month_map[self.month]
else:
return "%02 %s" % (self.day,month_map[self.month])
return "%02d %s" % (self.day,month_map[self.month])
elif self.month == UNDEF:
return str(self.year)
elif self.day == UNDEF:

View File

@ -871,7 +871,7 @@ def birth_dates_in_order(list):
for i in range(len(list)):
child = list[i]
bday = child.getBirth().getDateObj()
child_date = sort.build_sort_birth(bday)
child_date = sort.build_sort_event(bday)
if (child_date == "99999999"):
continue
if (prev_date <= child_date): # <= allows for twins
@ -895,13 +895,13 @@ def reorder_child_list(person, list):
return(list)
# Build the person's date string once
person_bday = sort.build_sort_birth(person.getBirth().getDateObj())
person_bday = sort.build_sort_event(person.getBirth().getDateObj())
# First, see if the person needs to be moved forward in the list
index = list.index(person)
target = index
for i in range(index-1, -1, -1):
other_bday = sort.build_sort_birth(list[i].getBirth().getDateObj())
other_bday = sort.build_sort_event(list[i].getBirth().getDateObj())
if (other_bday == "99999999"):
continue;
if (person_bday < other_bday):
@ -910,7 +910,7 @@ def reorder_child_list(person, list):
# Now try moving to a later position in the list
if (target == index):
for i in range(index, len(list)):
other_bday = sort.build_sort_birth(list[i].getBirth().getDateObj())
other_bday = sort.build_sort_event(list[i].getBirth().getDateObj())
if (other_bday == "99999999"):
continue;
if (person_bday > other_bday):

View File

@ -434,7 +434,7 @@ class Photo(SourceNote):
self.attrlist = list
class ObjectRef:
"""Object reference class"""
def __init__(self,source=None):
self.attrlist = []
if source:

View File

@ -90,7 +90,7 @@ gtkrcFile = "%s/gtkrc" % rootDir
#
#-------------------------------------------------------------------------
progName = "gramps"
version = "0.6.2"
version = "0.7.0pre"
copyright = "© 2001 Donald N. Allingham"
authors = ["Donald N. Allingham", "David Hampton"]
comments = _("Gramps (Genealogical Research and Analysis Management Programming System) is a personal genealogy program.")

View File

@ -43,10 +43,8 @@ else:
for c in s:
try:
cv = code_to_utf8(1,c)
except Exception,e:
from traceback import print_exc
print_exc()
cv = ''
except Exception:
cv = '?'
buff.write(cv)
ans = buff.getvalue()
buff.close()

View File

@ -33,9 +33,9 @@ import string
import const
import utils
from gtk import *
from gnome.ui import *
from libglade import *
import gtk
import gnome.ui
import libglade
import gnome.mime
ANSEL = 1
@ -104,14 +104,13 @@ def importData(database, filename):
global callback
global topDialog
global glade_file
global statusWindow
# add some checking here
if clear_data == 1:
database.new()
statusTop = GladeXML(glade_file,"status")
statusTop = libglade.GladeXML(glade_file,"status")
statusWindow = statusTop.get_widget("status")
statusTop.get_widget("close").set_sensitive(0)
statusTop.signal_autoconnect({
@ -122,11 +121,11 @@ def importData(database, filename):
g = GedcomParser(database,filename,statusTop)
except IOError,msg:
utils.destroy_passed_object(statusWindow)
GnomeErrorDialog(_("%s could not be opened\n") % filename + str(msg))
gnome.ui.GnomeErrorDialog(_("%s could not be opened\n") % filename + str(msg))
return
except:
utils.destroy_passed_object(statusWindow)
GnomeErrorDialog(_("%s could not be opened\n") % filename)
gnome.ui.GnomeErrorDialog(_("%s could not be opened\n") % filename)
return
g.parse_gedcom_file()
@ -199,8 +198,8 @@ class GedcomParser:
def update(self,field,text):
field.set_text(text)
while events_pending():
mainiteration()
while gtk.events_pending():
gtk.mainiteration()
def get_next(self):
if self.backoff == 0:
@ -283,18 +282,18 @@ class GedcomParser:
elif matches[1] == "DATA" or matches[1] == "TEXT":
self.ignore_sub_junk(2)
elif matches[1] == "TITL":
title = matches[2] + self.parse_continue_data(2)
title = matches[2] + self.parse_continue_data()
title = string.replace(title,'\n',' ')
self.source.setTitle(title)
elif matches[1] == "AUTH":
self.source.setAuthor(matches[2] + self.parse_continue_data(2))
self.source.setAuthor(matches[2] + self.parse_continue_data())
elif matches[1] == "PUBL":
self.source.setPubInfo(matches[2] + self.parse_continue_data(2))
self.source.setPubInfo(matches[2] + self.parse_continue_data())
elif matches[1] == "OBJE":
self.ignore_sub_junk(2)
elif matches[1] == "NOTE":
if matches[2] and matches[2][0] != "@":
note = matches[1] + self.parse_continue_data(1)
note = matches[1] + self.parse_continue_data()
self.source.setNote(note)
self.ignore_sub_junk(2)
else:
@ -346,9 +345,9 @@ class GedcomParser:
self.nmap[matches[1]] = noteobj
text = matches[2][4:]
if text == "":
noteobj.set(self.parse_continue_data(1))
noteobj.set(self.parse_continue_data())
else:
noteobj.set(text + self.parse_continue_data(1))
noteobj.set(text + self.parse_continue_data())
self.parse_note_data(1)
elif matches[2] == "OBJE":
self.ignore_sub_junk(2)
@ -417,7 +416,7 @@ class GedcomParser:
self.ignore_sub_junk(2)
elif matches[1] == "ADDR":
self.addr = Address()
self.addr.setStreet(matches[2] + self.parse_continue_data(2))
self.addr.setStreet(matches[2] + self.parse_continue_data())
self.parse_address(self.addr,2)
elif matches[1] == "CHIL":
mrel,frel = self.parse_ftw_relations(2)
@ -448,7 +447,7 @@ class GedcomParser:
self.parse_family_object(2)
elif matches[1] == "NOTE":
if matches[2] and matches[2][0] != "@":
note = matches[1] + self.parse_continue_data(1)
note = matches[1] + self.parse_continue_data()
self.family.setNote(note)
self.ignore_sub_junk(2)
else:
@ -514,7 +513,7 @@ class GedcomParser:
self.parse_person_object(2)
elif matches[1] == "NOTE":
if not string.strip(matches[2]) or matches[2] and matches[2][0] != "@":
note = matches[2] + self.parse_continue_data(1)
note = matches[2] + self.parse_continue_data()
self.person.setNote(note)
self.ignore_sub_junk(2)
else:
@ -558,7 +557,7 @@ class GedcomParser:
self.parse_residence(addr,2)
elif matches[1] == "ADDR":
addr = Address()
addr.setStreet(matches[2] + self.parse_continue_data(2))
addr.setStreet(matches[2] + self.parse_continue_data())
self.parse_address(addr,2)
self.person.addAddress(addr)
elif matches[1] == "BIRT":
@ -631,7 +630,7 @@ class GedcomParser:
return note
elif matches[1] == "NOTE":
if not string.strip(matches[2]) or matches[2] and matches[2][0] != "@":
note = matches[2] + self.parse_continue_data(level+1)
note = matches[2] + self.parse_continue_data()
self.parse_note_data(level+1)
else:
self.ignore_sub_junk(level+1)
@ -653,7 +652,7 @@ class GedcomParser:
type = matches[1]
elif matches[1] == "NOTE":
if not string.strip(matches[2]) or matches[2] and matches[2][0] != "@":
note = matches[2] + self.parse_continue_data(level+1)
note = matches[2] + self.parse_continue_data()
self.parse_note_data(level+1)
else:
self.ignore_sub_junk(level+1)
@ -674,7 +673,7 @@ class GedcomParser:
elif matches[1] == "FILE":
file = matches[2]
elif matches[1] == "NOTE":
note = matches[2] + self.parse_continue_data(level+1)
note = matches[2] + self.parse_continue_data()
elif matches[1][0] == "_":
self.ignore_sub_junk(level+1)
elif int(matches[0]) < level:
@ -720,7 +719,7 @@ class GedcomParser:
elif matches[1] == "FILE":
file = matches[2]
elif matches[1] == "NOTE":
note = matches[2] + self.parse_continue_data(level+1)
note = matches[2] + self.parse_continue_data()
elif int(matches[0]) < level:
self.backup()
break
@ -759,7 +758,7 @@ class GedcomParser:
elif matches[1] == "FILE":
file = matches[2]
elif matches[1] == "NOTE":
note = matches[2] + self.parse_continue_data(level+1)
note = matches[2] + self.parse_continue_data()
elif int(matches[0]) < level:
self.backup()
break
@ -792,7 +791,7 @@ class GedcomParser:
elif matches[1] == "DATE":
address.setDateObj(self.extract_date(matches[2]))
elif matches[1] == "ADDR":
address.setStreet(matches[2] + self.parse_continue_data(2))
address.setStreet(matches[2] + self.parse_continue_data())
self.parse_address(address,level+1)
elif matches[1] in ["AGE","AGNC","CAUS","STAT","TEMP","OBJE","TYPE"]:
self.ignore_sub_junk(level+1)
@ -808,7 +807,7 @@ class GedcomParser:
pass
elif matches[1] == "NOTE":
if not string.strip(matches[2]) or matches[2] and matches[2][0] != "@":
note = matches[1] + self.parse_continue_data(1)
note = matches[1] + self.parse_continue_data()
address.setNote(note)
self.ignore_sub_junk(2)
else:
@ -830,7 +829,7 @@ class GedcomParser:
return
elif matches[1] in [ "ADDR", "ADR1", "ADR2" ]:
val = address.getStreet()
data = self.parse_continue_data(level+1)
data = self.parse_continue_data()
if first == 0:
val = "%s %s" % (matches[2],data)
first = 1
@ -877,7 +876,7 @@ class GedcomParser:
s = self.db.findSource(ref,self.smap)
source_ref.setBase(s)
s.setTitle('Imported Source #%d' % self.localref)
s.setNote(matches[2] + self.parse_continue_data(1))
s.setNote(matches[2] + self.parse_continue_data())
self.ignore_sub_junk(2)
else:
source_ref.setBase(self.db.findSource(matches[2],self.smap))
@ -900,10 +899,10 @@ class GedcomParser:
event.setPlace(place)
self.ignore_sub_junk(level+1)
elif matches[1] == "CAUS":
info = matches[2] + self.parse_continue_data(level+1)
info = matches[2] + self.parse_continue_data()
event.setCause(info)
elif matches[1] == "NOTE":
info = matches[2] + self.parse_continue_data(level+1)
info = matches[2] + self.parse_continue_data()
if note == "":
note = info
else:
@ -940,7 +939,7 @@ class GedcomParser:
s = self.db.findSource(ref,self.smap)
source_ref.setBase(s)
s.setTitle('Imported Source #%d' % self.localref)
s.setNote(matches[2] + self.parse_continue_data(1))
s.setNote(matches[2] + self.parse_continue_data())
self.ignore_sub_junk(2)
else:
source_ref.setBase(self.db.findSource(matches[2],self.smap))
@ -969,10 +968,10 @@ class GedcomParser:
event.setPlace(place)
self.ignore_sub_junk(level+1)
elif matches[1] == "CAUS":
info = matches[2] + self.parse_continue_data(level+1)
info = matches[2] + self.parse_continue_data()
event.setCause(info)
elif matches[1] == "NOTE":
info = matches[2] + self.parse_continue_data(level+1)
info = matches[2] + self.parse_continue_data()
if note == "":
note = info
else:
@ -1029,7 +1028,7 @@ class GedcomParser:
s = self.db.findSource(ref,self.smap)
source_ref.setBase(s)
s.setTitle('Imported Source #%d' % self.localref)
s.setNote(matches[2] + self.parse_continue_data(1))
s.setNote(matches[2] + self.parse_continue_data())
self.ignore_sub_junk(2)
else:
source_ref.setBase(self.db.findSource(matches[2],self.smap))
@ -1041,7 +1040,7 @@ class GedcomParser:
attr.setValue(val)
self.ignore_sub_junk(level+1)
elif matches[1] == "NOTE":
info = matches[2] + self.parse_continue_data(level+1)
info = matches[2] + self.parse_continue_data()
if note == "":
note = info
else:
@ -1082,7 +1081,7 @@ class GedcomParser:
ref = "gsr%d" % self.localref
s = self.db.findSource(ref,self.smap)
source_ref.setBase(s)
note = matches[2] + self.parse_continue_data(1)
note = matches[2] + self.parse_continue_data()
s.setTitle('Imported Source #%d' % self.localref)
s.setNote(note)
self.ignore_sub_junk(2)
@ -1103,7 +1102,7 @@ class GedcomParser:
self.ignore_sub_junk(level+1)
elif matches[1] == "NOTE":
if not string.strip(matches[2]) or matches[2] and matches[2][0] != "@":
note = matches[1] + self.parse_continue_data(1)
note = matches[1] + self.parse_continue_data()
event.setNote(note)
self.ignore_sub_junk(2)
else:
@ -1125,7 +1124,7 @@ class GedcomParser:
self.backup()
return
elif matches[1] == "PAGE":
source.setPage(matches[2] + self.parse_continue_data(level+1))
source.setPage(matches[2] + self.parse_continue_data())
elif matches[1] == "DATA":
date,text = self.parse_source_data(level+1)
d = Date.Date()
@ -1142,7 +1141,7 @@ class GedcomParser:
source.setConfidence(val)
elif matches[1] == "NOTE":
if not string.strip(matches[2]) or matches[2] and matches[2][0] != "@":
note = matches[1] + self.parse_continue_data(1)
note = matches[1] + self.parse_continue_data()
source.setComments(note)
self.ignore_sub_junk(2)
else:
@ -1169,7 +1168,7 @@ class GedcomParser:
date = matches[2]
elif matches[1] == "TEXT":
note = matches[2] + self.parse_continue_data(level+1)
note = matches[2] + self.parse_continue_data()
else:
self.barf(level+1)
@ -1223,7 +1222,7 @@ class GedcomParser:
self.parse_source_reference(source_ref,level+1)
elif matches[1][0:4] == "NOTE":
if matches[2] and matches[2][0] != "@":
note = matches[2] + self.parse_continue_data(1)
note = matches[2] + self.parse_continue_data()
name.setNote(note)
self.ignore_sub_junk(2)
else:
@ -1301,7 +1300,7 @@ class GedcomParser:
date = self.parse_date(2)
date.date = matches[2]
elif matches[1] == "NOTE":
note = matches[2] + self.parse_continue_data(2)
note = matches[2] + self.parse_continue_data()
elif matches[1][0] == "_":
self.ignore_sub_junk(2)
else:
@ -1381,7 +1380,7 @@ class GedcomParser:
elif matches[1] != "FORM":
self.barf(level+1)
def parse_continue_data(self,level):
def parse_continue_data(self):
data = ""
while 1:
matches = self.get_next()
@ -1484,7 +1483,7 @@ def readData(database,active_person,cb):
"on_ok_clicked" : on_ok_clicked
}
topDialog = GladeXML(glade_file,"gedcomImport")
topDialog = libglade.GladeXML(glade_file,"gedcomImport")
topDialog.signal_autoconnect(dic)
topDialog.get_widget("gedcomImport").show()

View File

@ -89,5 +89,5 @@ def on_ok_clicked(obj):
#------------------------------------------------------------------------
from Plugins import register_import
register_import(readData,_("Import from Gramps"))
register_import(readData,_("Import from GRAMPS"))

View File

@ -30,15 +30,58 @@ import intl
import Date
_ = intl.gettext
from gtk import *
from gnome.ui import *
from libglade import *
import gtk
import gnome.ui
import libglade
import const
from latin_ansel import latin_to_ansel
from latin_utf8 import latin_to_utf8
_hmonth = [ "", "ELUL", "TSH", "CSH", "KSL", "TVT", "SHV", "ADR",
#-------------------------------------------------------------------------
#
# GEDCOM feature support
#
#-------------------------------------------------------------------------
_ADOPT_NONE = 0
_ADOPT_EVENT = 1
_ADOPT_FTW = 2
_ADOPT_LEGACY = 3
_ADOPT_PEDI = 4
_ADOPT_EVENT_EXT = 5
_CONC_OK = 0
_CONC_BROKEN = 1
_ALT_NONE = 0
_ALT_STD = 1
_ALT_ALIAS = 2
_ALT_AKA = 3
_ALT_EVENT_AKA = 4
_CAL_NO = 0
_CAL_YES = 1
targets = [
("Standard GEDCOM 5.5", "GEDCOM 5.5", _ADOPT_EVENT_EXT, _CONC_OK, _ALT_STD, _CAL_YES),
("Brother's Keeper", "BROSKEEP", _ADOPT_NONE, _CONC_BROKEN, _ALT_NONE, _CAL_NO),
("Family Origins", "FamilyOrigins", _ADOPT_EVENT, _CONC_BROKEN, _ALT_EVENT_AKA, _CAL_NO),
("Family Tree Maker", "FTW", _ADOPT_FTW, _CONC_BROKEN, _ALT_ALIAS, _CAL_NO),
("Ftree", "", _ADOPT_NONE, _CONC_BROKEN, _ALT_NONE, _CAL_NO),
("GeneWeb", "", _ADOPT_NONE, _CONC_OK, _ALT_NONE, _CAL_YES),
("Legacy", "Legacy", _ADOPT_LEGACY, _CONC_BROKEN, _ALT_STD, _CAL_NO),
("Personal Ancestral File", "PAF", _ADOPT_PEDI, _CONC_OK, _ALT_AKA, _CAL_NO),
("Reunion", "REUNION", _ADOPT_NONE, _CONC_BROKEN, _ALT_NONE, _CAL_NO),
("Visual Genealogie", "", _ADOPT_NONE, _CONC_BROKEN, _ALT_NONE, _CAL_NO),
]
#-------------------------------------------------------------------------
#
# Calendar month names
#
#-------------------------------------------------------------------------
_hmonth = [
"", "ELUL", "TSH", "CSH", "KSL", "TVT", "SHV", "ADR",
"ADS", "NSN", "IYR", "SVN", "TMZ", "AAV", "ELL" ]
_fmonth = [
@ -49,86 +92,93 @@ _month = [
"", "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ]
_calmap = {
Date.HEBREW : (_hmonth, '@#HEBREW@'),
Date.FRENCH : (_fmonth, '@#FRENCH R@'),
Date.JULIAN : (_month, '@#JULIAN@'),
}
#-------------------------------------------------------------------------
#
# Filters
#
#-------------------------------------------------------------------------
def entire_database(database,person):
def entire_database(database,person,private):
plist = database.getPersonMap().values()
flist = database.getFamilyMap().values()
slist = database.getSourceMap().values()
return (plist,flist,slist)
def active_person_descendants(database,person):
def active_person_descendants(database,person,private):
plist = []
flist = []
slist = []
descend(person,plist,flist,slist)
descend(person,plist,flist,slist,private)
return (plist,flist,slist)
def active_person_ancestors_and_descendants(database,person):
def active_person_ancestors_and_descendants(database,person,private):
plist = []
flist = []
slist = []
descend(person,plist,flist,slist)
ancestors(person,plist,flist,slist)
descend(person,plist,flist,slist,private)
ancestors(person,plist,flist,slist,private)
return (plist,flist,slist)
def active_person_ancestors(database,person):
def active_person_ancestors(database,person,private):
plist = []
flist = []
slist = []
ancestors(person,plist,flist,slist)
ancestors(person,plist,flist,slist,private)
return (plist,flist,slist)
def interconnected(database,person):
def interconnected(database,person,private):
plist = []
flist = []
slist = []
walk(person,plist,flist,slist)
walk(person,plist,flist,slist,private)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def descend(person,plist,flist,slist):
def descend(person,plist,flist,slist,private):
if person == None or person in plist:
return
plist.append(person)
add_persons_sources(person)
add_persons_sources(person,slist,private)
for family in person.getFamilyList():
add_familys_sources(family,slist)
add_familys_sources(family,slist,private)
flist.append(family)
father = family.getFather()
mother = family.getMother()
if father != None and father not in plist:
plist.append(father)
add_persons_sources(father,slist)
add_persons_sources(father,slist,private)
if mother != None and mother not in plist:
plist.append(mother)
add_persons_sources(mother,slist)
add_persons_sources(mother,slist,private)
for child in family.getChildList():
descend(child,plist,flist,slist)
descend(child,plist,flist,slist,private)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def ancestors(person,plist,flist,slist):
def ancestors(person,plist,flist,slist,private):
if person == None or person in plist:
return
plist.append(person)
add_persons_sources(person,slist)
add_persons_sources(person,slist,private)
family = person.getMainFamily()
if family == None or family in flist:
return
add_familys_sources(family,slist)
family_list.append(family,flist)
ancestors(family.getMother(),plist,flist,slist)
ancestors(family.getFather(),plist,flist,slist)
add_familys_sources(family,slist,private)
flist.append(family)
ancestors(family.getMother(),plist,flist,slist,private)
ancestors(family.getFather(),plist,flist,slist,private)
#-------------------------------------------------------------------------
@ -136,11 +186,11 @@ def ancestors(person,plist,flist,slist):
#
#
#-------------------------------------------------------------------------
def walk(person,plist,flist,slist):
def walk(person,plist,flist,slist,private):
if person == None or person in plist:
return
plist.append(person)
add_persons_sources(person,slist)
add_persons_sources(person,slist,private)
families = person.getFamilyList()
families.append(person.getMainFamily())
for f in person.getAltFamilyList():
@ -148,19 +198,40 @@ def walk(person,plist,flist,slist):
for family in families:
if family == None or family in flist:
continue
add_familys_sources(family,slist)
add_familys_sources(family,slist,private)
flist.append(family)
walk(family.getFather(),plist,flist,slist)
walk(family.getMother(),plist,flist,slist)
walk(family.getFather(),plist,flist,slist,private)
walk(family.getMother(),plist,flist,slist,private)
for child in family.getChildList():
walk(child,plist,flist,slist)
walk(child,plist,flist,slist,private)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def add_persons_sources(person,slist):
def add_familys_sources(family,slist,private):
for event in family.getEventList():
if private and event.getPrivacy():
continue
for source_ref in event.getSourceRefList():
sbase = source_ref.getBase()
if sbase != None and sbase not in slist:
slist.append(sbase)
for attr in family.getAttributeList():
if private and attr.getPrivacy():
continue
for source_ref in attr.getSourceRefList():
sbase = source_ref.getBase()
if sbase != None and sbase not in slist:
slist.append(sbase)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def add_persons_sources(person,slist,private):
elist = person.getEventList()[:]
elist.append(person.getBirth())
@ -194,27 +265,6 @@ def add_persons_sources(person,slist):
if sbase != None and sbase not in slist:
slist.append(sbase)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def add_familys_sources(family,slist):
for event in family.getEventList():
if private and event.getPrivacy():
continue
for source_ref in event.getSourceRefList():
sbase = source_ref.getBase()
if sbase != None and sbase not in slist:
slist.append(sbase)
for attr in family.getAttributeList():
if private and attr.getPrivacy():
continue
for source_ref in attr.getSourceRefList():
sbase = source_ref.getBase()
if sbase != None and sbase not in slist:
slist.append(sbase)
#-------------------------------------------------------------------------
#
#
@ -306,24 +356,24 @@ def ged_subdate(date):
if date.month == -1:
retval = str(date.year)
elif date.year == -1:
retval = "(%s)" % SingleDate.emname[date.month]
retval = "(%s)" % Date.SingleDate.emname[date.month]
else:
retval = "%s %d" % (SingleDate.emname[date.month],date.year)
retval = "%s %d" % (Date.SingleDate.emname[date.month],date.year)
elif date.month == -1:
retval = str(date.year)
else:
month = SingleDate.emname[date.month]
month = Date.SingleDate.emname[date.month]
if date.year == -1:
retval = "(%d %s)" % (date.day,month)
else:
retval = "%d %s %d" % (date.day,month,date.year)
if date.mode == SingleDate.about:
if date.mode == Date.SingleDate.about:
retval = "ABT %s" % retval
if date.mode == SingleDate.before:
if date.mode == Date.SingleDate.before:
retval = "BEF %s" % retval
elif date.mode == SingleDate.after:
elif date.mode == Date.SingleDate.after:
retval = "AFT %s" % retval
return retval
@ -342,49 +392,69 @@ def writeData(database,person):
#
#-------------------------------------------------------------------------
class GedcomWriter:
"""Writes a GEDCOM file from the passed database"""
def __init__(self,db,person):
self.db = db
self.person = person
self.restrict = 1
self.private = 1
self.cnvtxt = latin_to_ansel
self.people_list = []
self.source_list = []
self.family_list = []
self.adopt_mode = 0
self.plist = []
self.slist = []
self.flist = []
self.adopt = _ADOPT_EVENT
self.fidval = 0
self.fidmap = {}
self.pidval = 0
self.pidmap = {}
self.sidval = 0
self.sidmap = {}
glade_file = "%s/gedcomexport.glade" % os.path.dirname(__file__)
self.topDialog = GladeXML(glade_file,"gedcomExport")
self.topDialog = libglade.GladeXML(glade_file,"gedcomExport")
self.topDialog.signal_autoconnect({
"destroy_passed_object" : utils.destroy_passed_object,
"on_ok_clicked" : self.on_ok_clicked
})
filter_obj = self.topDialog.get_widget("filter")
myMenu = GtkMenu()
menuitem = GtkMenuItem(_("Entire Database"))
myMenu = gtk.GtkMenu()
menuitem = gtk.GtkMenuItem(_("Entire Database"))
myMenu.append(menuitem)
menuitem.set_data("filter",entire_database)
menuitem.show()
name = person.getPrimaryName().getRegularName()
menuitem = GtkMenuItem(_("Ancestors of %s") % name)
menuitem = gtk.GtkMenuItem(_("Ancestors of %s") % name)
myMenu.append(menuitem)
menuitem.set_data("filter",active_person_ancestors)
menuitem.show()
menuitem = GtkMenuItem(_("Descendants of %s") % name)
menuitem = gtk.GtkMenuItem(_("Descendants of %s") % name)
myMenu.append(menuitem)
menuitem.set_data("filter",active_person_descendants)
menuitem.show()
menuitem = GtkMenuItem(_("Ancestors and Descendants of %s") % name)
menuitem = gtk.GtkMenuItem(_("Ancestors and Descendants of %s") % name)
myMenu.append(menuitem)
menuitem.set_data("filter",active_person_ancestors_and_descendants)
menuitem.show()
menuitem = GtkMenuItem(_("People somehow connected to %s") % name)
menuitem = gtk.GtkMenuItem(_("People somehow connected to %s") % name)
myMenu.append(menuitem)
menuitem.set_data("filter",interconnected)
menuitem.show()
filter_obj.set_menu(myMenu)
self.filter_menu = myMenu
target_obj = self.topDialog.get_widget("target")
myMenu = gtk.GtkMenu()
for (name,dest,adopt,conc,alt,cal) in targets:
menuitem = gtk.GtkMenuItem(name)
myMenu.append(menuitem)
menuitem.set_data("data",(dest,adopt,conc,alt,cal))
menuitem.show()
target_obj.set_menu(myMenu)
self.target_menu = myMenu
self.topDialog.get_widget("gedcomExport").show()
@ -393,8 +463,9 @@ class GedcomWriter:
self.restrict = self.topDialog.get_widget("restrict").get_active()
self.private = self.topDialog.get_widget("private").get_active()
filter_obj = self.topDialog.get_widget("filter").get_menu().get_active()
filter = filter_obj.get_data("filter")
filter = self.filter_menu.get_active().get_data("filter")
act_tgt = self.target_menu.get_active()
(self.dest,self.adopt,self.conc,self.altname,self.cal) = act_tgt.get_data("data")
if self.topDialog.get_widget("ansel").get_active():
self.cnvtxt = latin_to_ansel
@ -403,13 +474,13 @@ class GedcomWriter:
name = self.topDialog.get_widget("filename").get_text()
(self.people_list,self.family_list,self.source_list) = filter(self.db,self.person)
(self.plist,self.flist,self.slist) = filter(self.db,self.person,self.private)
utils.destroy_passed_object(obj)
glade_file = "%s/gedcomexport.glade" % os.path.dirname(__file__)
self.exprogress = GladeXML(glade_file,"exportprogress")
self.exprogress = libglade.GladeXML(glade_file,"exportprogress")
self.exprogress.signal_autoconnect({
"on_close_clicked" : utils.destroy_passed_object
})
@ -433,11 +504,11 @@ class GedcomWriter:
self.g = open(filename,"w")
except IOError,msg:
msg = "%s\n%s" % (_("Could not create %s") % filename,str(msg))
GnomeErrorDialog(msg)
gnome.ui.GnomeErrorDialog(msg)
self.progress.destroy()
return
except:
GnomeErrorDialog(_("Could not create %s") % filename)
gnome.ui.GnomeErrorDialog(_("Could not create %s") % filename)
self.progress.destroy()
return
@ -447,7 +518,8 @@ class GedcomWriter:
self.g.write("1 SOUR GRAMPS\n")
self.g.write("2 VERS " + const.version + "\n")
self.g.write("2 NAME Gramps\n")
self.g.write("1 DEST GRAMPS\n")
if self.dest:
self.g.write("1 DEST %s\n" % self.dest)
self.g.write("1 DATE %s %s %s\n" % (date[2],string.upper(date[1]),date[4]))
if self.cnvtxt == latin_to_ansel:
self.g.write("1 CHAR ANSEL\n");
@ -489,28 +561,28 @@ class GedcomWriter:
self.g.write('1 ADDR Not Provided\n')
self.g.write('2 CONT Not Provided\n')
self.people_list.sort(sortById)
nump = float(len(self.people_list))
self.plist.sort(sortById)
nump = float(len(self.plist))
index = 0.0
for person in self.people_list:
for person in self.plist:
self.write_person(person)
index = index + 1
self.pbar.set_value((100*index)/nump)
while(events_pending()):
mainiteration()
while(gtk.events_pending()):
gtk.mainiteration()
self.pbar.set_value(100.0)
nump = float(len(self.family_list))
nump = float(len(self.flist))
index = 0.0
for family in self.family_list:
self.g.write("0 @F%s@ FAM\n" % family.getId())
for family in self.flist:
self.g.write("0 @%s@ FAM\n" % self.fid(family.getId()))
person = family.getFather()
if person != None:
self.g.write("1 HUSB @I%s@\n" % person.getId())
self.g.write("1 HUSB @%s@\n" % self.pid(person.getId()))
person = family.getMother()
if person != None:
self.g.write("1 WIFE @I%s@\n" % person.getId())
self.g.write("1 WIFE @%s@\n" % self.pid(person.getId()))
father = family.getFather()
mother = family.getMother()
@ -533,8 +605,8 @@ class GedcomWriter:
self.dump_event_stats(event)
for person in family.getChildList():
self.g.write("1 CHIL @I%s@\n" % person.getId())
if self.adopt_mode == 2:
self.g.write("1 CHIL @%s@\n" % self.pid(person.getId()))
if self.adopt == _ADOPT_FTW:
if person.getMainFamily() == family:
self.g.write('2 _FREL Natural\n')
self.g.write('2 _MREL Natural\n')
@ -544,7 +616,7 @@ class GedcomWriter:
self.g.write('2 _FREL %s\n' % f[2])
self.g.write('2 _MREL %s\n' % f[1])
break
if self.adopt_mode == 3:
if self.adopt == _ADOPT_LEGACY:
for f in person.getAltFamilyList():
if f[0] == family:
self.g.write('2 _STAT %s\n' % f[2])
@ -552,14 +624,14 @@ class GedcomWriter:
index = index + 1
self.fbar.set_value((100*index)/nump)
while(events_pending()):
mainiteration()
while(gtk.events_pending()):
gtk.mainiteration()
self.fbar.set_value(100.0)
nump = float(len(self.source_list))
nump = float(len(self.slist))
index = 0.0
for source in self.source_list:
self.g.write("0 @S%s@ SOUR\n" % source.getId())
for source in self.slist:
self.g.write("0 @%s@ SOUR\n" % self.sid(source.getId()))
if source.getTitle() != "":
self.g.write("1 TITL %s\n" % fmtline(self.cnvtxt(source.getTitle()),248,1))
if source.getAuthor() != "":
@ -571,22 +643,24 @@ class GedcomWriter:
if source.getCallNumber() != "":
self.g.write("1 CALN %s\n" % self.cnvtxt(source.getCallNumber()))
if source.getNote() != "":
write_long_text(g,"NOTE",1,source.getNote())
self.write_long_text("NOTE",1,source.getNote())
index = index + 1
self.sbar.set_value((100*index)/nump)
while(events_pending()):
mainiteration()
while(gtk.events_pending()):
gtk.mainiteration()
self.sbar.set_value(100.0)
self.g.write("0 TRLR\n")
self.g.close()
def write_person(self,person):
self.g.write("0 @I%s@ INDI\n" % person.getId())
self.g.write("0 @%s@ INDI\n" % self.pid(person.getId()))
self.write_person_name(person.getPrimaryName(),person.getNickName())
# for name in person.getAlternateNames():
# self.write_person_name(name,"")
if self.altname == _ALT_STD:
for name in person.getAlternateNames():
self.write_person_name(name,"")
if person.getGender() == Person.male:
self.g.write("1 SEX M\n")
@ -620,7 +694,7 @@ class GedcomWriter:
val = const.personalConstantEvents[name]
else:
val = ""
if self.adopt_mode == 1 and val == "ADOP":
if self.adopt == _ADOPT_EVENT and val == "ADOP":
ad = 1
self.g.write('1 ADOP\n')
fam = None
@ -631,7 +705,7 @@ class GedcomWriter:
fam = f[0]
break
if fam:
self.g.write('2 FAMC @F%s@\n' % fam.getId())
self.g.write('2 FAMC @%s@\n' % self.fid(fam.getId()))
if mrel == frel:
self.g.write('3 ADOP BOTH\n')
elif mrel == "adopted":
@ -647,7 +721,7 @@ class GedcomWriter:
self.dump_event_stats(event)
if self.adopt_mode == 1 and ad == 0 and len(person.getAltFamilyList()) != 0:
if self.adopt == _ADOPT_EVENT and ad == 0 and len(person.getAltFamilyList()) != 0:
self.g.write('1 ADOP\n')
fam = None
for f in person.getAltFamilyList():
@ -657,7 +731,7 @@ class GedcomWriter:
fam = f[0]
break
if fam:
self.g.write('2 FAMC @F%s@\n' % fam.getId())
self.g.write('2 FAMC @%s@\n' % self.fid(fam.getId()))
if mrel == frel:
self.g.write('3 ADOP BOTH\n')
elif mrel == "adopted":
@ -706,18 +780,18 @@ class GedcomWriter:
self.write_source_ref(3,srcref)
family = person.getMainFamily()
if family != None and family in self.family_list:
self.g.write("1 FAMC @F%s@\n" % family.getId())
if family != None and family in self.flist:
self.g.write("1 FAMC @%s@\n" % self.fid(family.getId()))
for family in person.getAltFamilyList():
self.g.write("1 FAMC @F%s@\n" % family[0].getId())
if self.adopt_mode == 0:
self.g.write("1 FAMC @%s@\n" % self.fid(family[0].getId()))
if self.adopt == _ADOPT_PEDI:
if string.lower(family[1]) == "adopted":
self.g.write("2 PEDI Adopted\n")
for family in person.getFamilyList():
if family != None and family in self.family_list:
self.g.write("1 FAMS @F%s@\n" % family.getId())
if family != None and family in self.flist:
self.g.write("1 FAMS @%s@\n" % self.fid(family.getId()))
for url in person.getUrlList():
self.g.write('1 OBJE\n')
@ -731,17 +805,52 @@ class GedcomWriter:
self.write_long_text("NOTE",1,person.getNote())
def write_long_text(self,tag,level,note):
if self.conc == _CONC_OK:
self.write_conc_ok(tag,level,note)
else:
self.write_conc_broken(tag,level,note)
def write_conc_ok(self,tag,level,note):
prefix = "%d %s" % (level,tag)
textlines = string.split(note,'\n')
if len(note) == 0:
g.write("%s\n" % prefix)
self.g.write("%s\n" % prefix)
else:
for line in textlines:
ll = len(line)
while ll > 0:
brkpt = 70
if ll > brkpt:
while (ll > brkpt and line[brkpt] in string.whitespace):
while (ll > brkpt and \
(line[brkpt] in string.whitespace or line[brkpt+1] in string.whitespace)):
brkpt = brkpt+1
if ll == brkpt:
self.g.write("%s %s\n" % (prefix,line))
line = ''
else:
self.g.write("%s %s\n" % (prefix,line[0:brkpt+1]))
line = line[brkpt+1:]
else:
self.g.write("%s %s\n" % (prefix,line))
line = ""
if len(line) > 0:
prefix = "%d CONC" % (level+1)
else:
prefix = "%d CONT" % (level+1)
ll = len(line)
def write_conc_broken(self,tag,level,note):
prefix = "%d %s" % (level,tag)
textlines = string.split(note,'\n')
if len(note) == 0:
self.g.write("%s\n" % prefix)
else:
for line in textlines:
ll = len(line)
while ll > 0:
brkpt = 70
if ll > brkpt:
while (ll > brkpt and line[brkpt] not in string.whitespace):
brkpt = brkpt+1
if ll == brkpt:
self.g.write("%s %s\n" % (prefix,line))
@ -777,34 +886,33 @@ class GedcomWriter:
start = date.get_start_date()
if date.get_calendar() == Date.GREGORIAN:
cal = ''
if date.isRange():
val = "FROM %s TO %s" % (make_date(start,_month),
make_date(date.get_stop_date(),_month))
else:
val = make_date(start,_month)
elif date.get_calendar() == Date.HEBREW:
cal = '@#HEBREW@ '
self.g.write("%s %s\n" % (prefix,val))
else:
if self.cal == _CAL_YES:
(mlist,cal) = _calmap[date.get_calendar()]
if date.isRange():
val = "FROM %s TO %s" % (make_date(start,_hmonth),
make_date(date.get_stop_date(),_hmonth))
stop = date.get_stop_date()
val = "FROM %s TO %s" % (make_date(start,mlist),
make_date(stop,mlist))
else:
val = make_date(start,_hmonth)
elif date.get_calendar() == Date.FRENCH:
cal = '@#FRENCH R@ '
if date.isRange():
val = "FROM %s TO %s" % (make_date(start,_fmonth),
make_date(date.get_stop_date(),_fmonth))
self.g.write("%s %s %s\n" % (prefix,cal,val))
else:
val = make_date(start,_fmonth)
else:
cal = '@#JULIAN@ '
if date.isRange():
mydate = Date.Date(date)
mydate.set_calendar(Date.GREGORIAN)
start = mydate.get_start_date()
if mydate.isRange():
stop = mydate.get_stop_date()
val = "FROM %s TO %s" % (make_date(start,_month),
make_date(date.get_stop_date(),_month))
make_date(stop,_month))
else:
val = make_date(start,_month)
self.g.write("%s %s%s\n" % (prefix,cal,val))
self.g.write("%s %s\n" % (prefix,val))
def write_person_name(self,name,nick):
firstName = self.cnvtxt(name.getFirstName())
@ -834,7 +942,7 @@ class GedcomWriter:
def write_source_ref(self,level,ref):
if ref.getBase() == None:
return
self.g.write("%d SOUR @S%s@\n" % (level,ref.getBase().getId()))
self.g.write("%d SOUR @%s@\n" % (level,self.sid(ref.getBase().getId())))
if ref.getPage() != "":
self.g.write("%d PAGE %s\n" % (level+1,ref.getPage()))
@ -849,10 +957,8 @@ class GedcomWriter:
self.write_long_text("NOTE",level+1,ref.getComments())
def probably_alive(self,person):
if person == None:
return 1
if self.restrict == 0:
return 0
@ -869,6 +975,32 @@ class GedcomWriter:
return 0
return 1
def fid(self,id):
if self.fidmap.has_key(id):
return self.fidmap[id]
else:
val = "F%05d" % self.fidval
self.fidval = self.fidval + 1
self.fidmap[id] = val
return val
def pid(self,id):
if self.pidmap.has_key(id):
return self.pidmap[id]
else:
val = "I%05d" % self.pidval
self.pidval = self.pidval + 1
self.pidmap[id] = val
return val
def sid(self,id):
if self.sidmap.has_key(id):
return self.sidmap[id]
else:
val = "S%05d" % self.sidval
self.sidval = self.sidval + 1
self.sidmap[id] = val
return val
#-------------------------------------------------------------------------
#

View File

@ -20,7 +20,7 @@
<position>GTK_WIN_POS_CENTER</position>
<modal>True</modal>
<allow_shrink>False</allow_shrink>
<allow_grow>False</allow_grow>
<allow_grow>True</allow_grow>
<auto_shrink>False</auto_shrink>
<auto_close>False</auto_close>
<hide_on_close>False</hide_on_close>
@ -244,6 +244,49 @@
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<widget>
<class>GtkHBox</class>
<name>hbox1</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkLabel</class>
<name>label5</name>
<label>Target</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>5</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkOptionMenu</class>
<name>target</name>
<can_focus>True</can_focus>
<items>Standard GEDCOM 5.5
</items>
<initial_choice>0</initial_choice>
<child>
<padding>5</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
</widget>
<widget>
<class>GtkCheckButton</class>
<name>private</name>