Date handling improvements (calendar conversions)

svn: r1233
This commit is contained in:
Don Allingham 2002-12-30 00:42:47 +00:00
parent 537578f0d2
commit f2fa2ce15e
7 changed files with 136 additions and 141 deletions

View File

@ -126,7 +126,7 @@ def sdn_to_gregorian(sdn):
month = month + 3 month = month + 3
else: else:
year = year + 1 year = year + 1
month = month + 9 month = month - 9
# Adjust to the B.C./A.D. type numbering # Adjust to the B.C./A.D. type numbering
year = year - 4800 year = year - 4800

View File

@ -56,15 +56,19 @@ FRENCH = 3
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
_fmonth = [ _fmonth = [
"Vendémiaire", "Brumaire", "Frimaire", "Nivôse", "Pluviôse", unicode("Vendémiaire",'latin-1'), unicode("Brumaire",'latin-1'),
"Ventôse", "Germinal", "Floréal", "Prairial", "Messidor", unicode("Frimaire",'latin-1'), unicode("Nivôse",'latin-1'),
"Thermidor", "Fructidor", "Extra", unicode("Pluviôse",'latin-1'), unicode("Ventôse",'latin-1'),
unicode("Germinal",'latin-1'), unicode("Floréal",'latin-1'),
unicode("Prairial",'latin-1'), unicode("Messidor",'latin-1'),
unicode("Thermidor",'latin-1'), unicode("Fructidor",'latin-1'),
unicode("Extra",'latin-1'),
] ]
_fmonth2num = { _fmonth2num = {
"vend" : 0, "brum" : 1, "frim" : 2, "nivo" : 3, "pluv" : 4, "vend" : 0, "brum" : 1, "frim" : 2, "nivo" : 3, "pluv" : 4, "vent" : 5,
"vent" : 5, "germ" : 6, "flor" : 7, "prai" : 8, "mess" : 9, "germ" : 6, "flor" : 7, "prai" : 8, "mess" : 9, "ther" :10, "fruc" :11,
"ther" :10, "fruc" :11, "extr" : 12,"comp" :12, "nivô" : 3 "extr" : 12,"comp" :12, unicode("nivô",'latin-1') : 3
} }
_hmonth = [ _hmonth = [
@ -188,7 +192,6 @@ class Date:
""" Returns true if any part of the date is valid""" """ Returns true if any part of the date is valid"""
return self.start.year != UNDEF or self.start.month != UNDEF or self.start.day != UNDEF return self.start.year != UNDEF or self.start.month != UNDEF or self.start.day != UNDEF
def getIncomplete(self): def getIncomplete(self):
return self.range == 0 and self.start.year == UNDEF or \ return self.range == 0 and self.start.year == UNDEF or \
self.start.month == UNDEF or self.start.day == UNDEF self.start.month == UNDEF or self.start.day == UNDEF
@ -307,7 +310,7 @@ class Date:
def isEmpty(self): def isEmpty(self):
s = self.start s = self.start
return s.year==UNDEF and s.month==UNDEF and s.day==UNDEF and not s.text return s.year==UNDEF and s.month==UNDEF and s.day==UNDEF and not self.text
def isValid(self): def isValid(self):
return self.range != -1 return self.range != -1
@ -821,12 +824,16 @@ class SingleDate:
if match: if match:
matches = match.groups() matches = match.groups()
self.setMode(matches[0]) self.setMode(matches[0])
monthstr = unicode(matches[2]).lower()
if l == 0: if l == 0:
mon = string.lower(matches[2]) mon = monthstr
else: else:
mon = string.lower(matches[2])[0:l] mon = monthstr[0:l]
self.setYear(int(matches[3])) self.setYear(int(matches[3]))
self.setMonthStr(mon) if month_map.has_key(mon):
self.setMonth(month_map[mon]+1)
else:
self.setMonth(UNDEF)
self.setDay(int(matches[1])) self.setDay(int(matches[1]))
return return
match = SingleDate.fmt3.match(text) match = SingleDate.fmt3.match(text)
@ -962,7 +969,7 @@ class SingleDate:
day = 1 day = 1
else: else:
day = self.day day = self.day
if self.calendar == GREGORIAN: if self.calendar == GREGORIAN:
sdn = Calendar.gregorian_to_sdn(self.year,month,day) sdn = Calendar.gregorian_to_sdn(self.year,month,day)
elif self.calendar == FRENCH: elif self.calendar == FRENCH:

View File

@ -70,6 +70,7 @@ class DisplayTrace:
'email message to gramps-bugs@lists.sourceforge.net\n\n')) 'email message to gramps-bugs@lists.sourceforge.net\n\n'))
msg.write("GRAMPS : %s\n" % const.version) msg.write("GRAMPS : %s\n" % const.version)
msg.write("LANG : %s\n" % os.environ['LANG'])
msg.write("Python : %s.%s.%s %s\n" % (ver[0],ver[1],ver[2],ver[3])) msg.write("Python : %s.%s.%s %s\n" % (ver[0],ver[1],ver[2],ver[3]))
msg.write("GTK : %s.%s.%s\n" % gtk.gtk_version) msg.write("GTK : %s.%s.%s\n" % gtk.gtk_version)
for n in _release_files: for n in _release_files:

View File

@ -149,12 +149,13 @@ class EventEditor:
pass pass
def on_menu_changed(self,obj): def on_menu_changed(self,obj):
self.date.set(self.date_field.get_text())
self.date.set_calendar(obj.get_data("d")) self.date.set_calendar(obj.get_data("d"))
self.date_field.set_text(self.date.getDate()) self.date_field.set_text(self.date.getDate())
def get_place(self,field,makenew=0): def get_place(self,field,makenew=0):
text = strip(field.get_text()) text = strip(field.get_text())
if text != "": if text:
if self.pmap.has_key(text): if self.pmap.has_key(text):
return self.parent.db.getPlaceMap()[self.pmap[text]] return self.parent.db.getPlaceMap()[self.pmap[text]]
elif makenew: elif makenew:

View File

@ -182,7 +182,6 @@ class Gramps:
self.pl_other = self.gtop.get_widget("pl_other") self.pl_other = self.gtop.get_widget("pl_other")
self.ptabs.set_show_tabs(0) self.ptabs.set_show_tabs(0)
self.pl_page = [ self.pl_page = [
ListModel.ListModel(self.pl_other, pl_titles, self.row_changed, ListModel.ListModel(self.pl_other, pl_titles, self.row_changed,
self.alpha_event, _sel_mode), self.alpha_event, _sel_mode),
@ -869,7 +868,7 @@ class Gramps:
del_id = pid del_id = pid
if self.id2col.has_key(del_id): if self.id2col.has_key(del_id):
(model,iter,page) = self.id2col[del_id] (model,iter) = self.id2col[del_id]
model.remove(iter) model.remove(iter)
del self.id2col[del_id] del self.id2col[del_id]
@ -1382,12 +1381,15 @@ class Gramps:
self.alpha_event,_sel_mode) self.alpha_event,_sel_mode)
self.alpha_page[pg] = model self.alpha_page[pg] = model
for index in range(0,len(self.tab_list)): for index in range(0,len(self.tab_list)):
if pg < self.tab_list[index]: try:
self.ptabs.insert_page(display,gtk.Label(pg),index) if pg < self.tab_list[index]:
self.ptabs.set_show_tabs(1) self.ptabs.insert_page(display,gtk.Label(pg),index)
self.tab_list.insert(index,pg) self.ptabs.set_show_tabs(1)
self.pl_page.insert(index,model) self.tab_list.insert(index,pg)
break self.pl_page.insert(index,model)
break
except:
print index
else: else:
self.ptabs.insert_page(display,gtk.Label(pg),len(self.tab_list)) self.ptabs.insert_page(display,gtk.Label(pg),len(self.tab_list))
self.ptabs.set_show_tabs(1) self.ptabs.set_show_tabs(1)

View File

@ -18,45 +18,10 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
import sys def utf8_to_latin(s):
return s.encode('iso-8859-1','replace')
if sys.version[0] != '1': def latin_to_utf8(s):
def utf8_to_latin(s): return unicode(s,'latin-1')
return s.encode('iso-8859-1','replace')
def latin_to_utf8(s):
return s
else:
try:
import cStringIO
from xml.unicode.utf8_iso import code_to_utf8
from xml.unicode.iso8859 import UTF8String
def utf8_to_latin(s):
y = UTF8String(s)
try:
return y.encode("iso-8859-1",'replace')
except:
return s
def latin_to_utf8(s):
buff = cStringIO.StringIO()
for c in s:
try:
cv = code_to_utf8(1,c)
except Exception:
cv = '?'
buff.write(cv)
ans = buff.getvalue()
buff.close()
return ans
except:
def utf8_to_latin(s):
return s
def latin_to_utf8(s):
return s

View File

@ -20,29 +20,44 @@
"Export to GEDCOM" "Export to GEDCOM"
from RelLib import * #-------------------------------------------------------------------------
import GenericFilter #
# Standard Python Modules
#
#-------------------------------------------------------------------------
import os import os
import string import string
import time import time
import const
import Utils
import Date
import re import re
from intl import gettext as _
#-------------------------------------------------------------------------
#
# GNOME/GTK modules
#
#-------------------------------------------------------------------------
import gtk import gtk
import gnome.ui import gnome.ui
import gtk.glade import gtk.glade
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from RelLib import *
import GenericFilter
import const
import Utils
import Date
from intl import gettext as _
from latin_utf8 import latin_to_utf8
from GedcomInfo import * from GedcomInfo import *
try: try:
from ansel import latin_to_ansel from ansel import latin_to_ansel
except: except:
from latin_ansel import latin_to_ansel from latin_ansel import latin_to_ansel
from latin_utf8 import latin_to_utf8
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Calendar month names # Calendar month names
@ -78,8 +93,7 @@ _caldef = {
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
_get_int = re.compile('([0-9]+)')
get_int = re.compile('([0-9]+)')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -92,7 +106,7 @@ def add_familys_sources(family,slist,private):
continue continue
for source_ref in event.getSourceRefList(): for source_ref in event.getSourceRefList():
sbase = source_ref.getBase() sbase = source_ref.getBase()
if sbase != None and not slist.has_key(sbase): if sbase != None and not slist.has_key(sbase.getId()):
slist[sbase.getId()] = 1 slist[sbase.getId()] = 1
for attr in family.getAttributeList(): for attr in family.getAttributeList():
if private and attr.getPrivacy(): if private and attr.getPrivacy():
@ -195,16 +209,16 @@ def make_date(subdate):
if not day_valid: if not day_valid:
try: try:
if not mon_valid: if not mon_valid:
retval = '(%d)' % year retval = '%d' % year
elif not year_valid: elif not year_valid:
retval = '(%s)' % mmap[mon] retval = '(%s)' % mmap[mon]
else: else:
retval = "(%s %d)" % (mmap[mon],year) retval = "%s %d" % (mmap[mon],year)
except IndexError: except IndexError:
print "Month index error - %d" % mon print "Month index error - %d" % mon
retval = '(%d)' % year retval = '%d' % year
elif not mon_valid: elif not mon_valid:
retval = '(%d)' % year retval = '%d' % year
else: else:
try: try:
month = mmap[mon] month = mmap[mon]
@ -224,6 +238,11 @@ def make_date(subdate):
return retval return retval
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def fmtline(text,limit,level): def fmtline(text,limit,level):
new_text = [] new_text = []
while len(text) > limit: while len(text) > limit:
@ -455,8 +474,8 @@ class GedcomWriter:
self.g.write("0 HEAD\n") self.g.write("0 HEAD\n")
self.g.write("1 SOUR GRAMPS\n") self.g.write("1 SOUR GRAMPS\n")
self.g.write("2 VERS " + const.version + "\n") self.g.write("2 VERS %s\n" % const.version)
self.g.write("2 NAME Gramps\n") self.g.write("2 NAME GRAMPS\n")
if self.dest: if self.dest:
self.g.write("1 DEST %s\n" % 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])) self.g.write("1 DATE %s %s %s\n" % (date[2],string.upper(date[1]),date[4]))
@ -471,28 +490,28 @@ class GedcomWriter:
self.g.write('2 FORM LINEAGE-LINKED\n') self.g.write('2 FORM LINEAGE-LINKED\n')
self.g.write("0 @SUBM@ SUBM\n") self.g.write("0 @SUBM@ SUBM\n")
owner = self.db.getResearcher() owner = self.db.getResearcher()
if owner.getName() != "": if owner.getName():
self.g.write("1 NAME " + self.cnvtxt(owner.getName()) +"\n") self.g.write("1 NAME %s\n" % self.cnvtxt(owner.getName()))
else: else:
self.g.write('1 NAME Not Provided\n') self.g.write('1 NAME Not Provided\n')
if owner.getAddress() != "": if owner.getAddress():
cnt = 0 cnt = 0
self.g.write("1 ADDR " + self.cnvtxt(owner.getAddress()) + "\n") self.g.write("1 ADDR %s\n" % self.cnvtxt(owner.getAddress()))
if owner.getCity() != "": if owner.getCity():
self.g.write("2 CONT " + self.cnvtxt(owner.getCity()) + "\n") self.g.write("2 CONT %s\n" % self.cnvtxt(owner.getCity()))
cnt = 1 cnt = 1
if owner.getState() != "": if owner.getState():
self.g.write("2 CONT " + self.cnvtxt(owner.getState()) + "\n") self.g.write("2 CONT %s\n" % self.cnvtxt(owner.getState()))
cnt = 1 cnt = 1
if owner.getPostalCode() != "": if owner.getPostalCode():
self.g.write("2 CONT " + self.cnvtxt(owner.getPostalCode()) + "\n") self.g.write("2 CONT %s\n" % self.cnvtxt(owner.getPostalCode()))
cnt = 1 cnt = 1
if owner.getCountry() != "": if owner.getCountry():
self.g.write("2 CONT " + self.cnvtxt(owner.getCountry()) + "\n") self.g.write("2 CONT %s\n" % self.cnvtxt(owner.getCountry()))
cnt = 1 cnt = 1
if owner.getPhone() != "": if owner.getPhone():
self.g.write("2 PHON " + self.cnvtxt(owner.getPhone()) + "\n") self.g.write("2 PHON %s\n" % self.cnvtxt(owner.getPhone()))
cnt = 1 cnt = 1
if cnt == 0: if cnt == 0:
self.g.write('2 CONT Not Provided\n') self.g.write('2 CONT Not Provided\n')
@ -508,10 +527,10 @@ class GedcomWriter:
self.write_person(self.db.getPerson(key)) self.write_person(self.db.getPerson(key))
index = index + 1 index = index + 1
if index%100 == 0: if index%100 == 0:
self.pbar.set_value((100*index)/nump) self.pbar.set_fraction(index/nump)
while(gtk.events_pending()): while(gtk.events_pending()):
gtk.mainiteration() gtk.mainiteration()
self.pbar.set_value(100.0) self.pbar.set_fraction(1.0)
self.write_families() self.write_families()
self.write_sources() self.write_sources()
@ -550,7 +569,7 @@ class GedcomWriter:
if val == "": if val == "":
val = self.target_ged.gramps2tag(name) val = self.target_ged.gramps2tag(name)
if val != "": if val:
self.g.write("1 %s %s\n" % (self.cnvtxt(val), self.g.write("1 %s %s\n" % (self.cnvtxt(val),
self.cnvtxt(event.getDescription()))) self.cnvtxt(event.getDescription())))
else: else:
@ -581,10 +600,10 @@ class GedcomWriter:
index = index + 1 index = index + 1
if index % 100 == 0: if index % 100 == 0:
self.fbar.set_value((100*index)/nump) self.fbar.set_fraction(index/nump)
while(gtk.events_pending()): while(gtk.events_pending()):
gtk.mainiteration() gtk.mainiteration()
self.fbar.set_value(100.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))
@ -592,24 +611,24 @@ class GedcomWriter:
for key in self.slist.keys(): for key in self.slist.keys():
source = self.db.getSource(key) source = self.db.getSource(key)
self.g.write("0 @%s@ SOUR\n" % self.sid(source.getId())) self.g.write("0 @%s@ SOUR\n" % self.sid(source.getId()))
if source.getTitle() != "": if source.getTitle():
self.g.write("1 TITL %s\n" % fmtline(self.cnvtxt(source.getTitle()),248,1)) self.g.write("1 TITL %s\n" % fmtline(self.cnvtxt(source.getTitle()),248,1))
if source.getAuthor() != "": if source.getAuthor():
self.g.write("1 AUTH %s\n" % self.cnvtxt(source.getAuthor())) self.g.write("1 AUTH %s\n" % self.cnvtxt(source.getAuthor()))
if source.getPubInfo() != "": if source.getPubInfo():
self.g.write("1 PUBL %s\n" % self.cnvtxt(source.getPubInfo())) self.g.write("1 PUBL %s\n" % self.cnvtxt(source.getPubInfo()))
if source.getTitle() != "": if source.getTitle():
self.g.write("1 ABBR %s\n" % self.cnvtxt(source.getTitle())) self.g.write("1 ABBR %s\n" % self.cnvtxt(source.getTitle()))
if source.getCallNumber() != "": if source.getCallNumber():
self.g.write("1 CALN %s\n" % self.cnvtxt(source.getCallNumber())) self.g.write("1 CALN %s\n" % self.cnvtxt(source.getCallNumber()))
if source.getNote() != "": if source.getNote():
self.write_long_text("NOTE",1,self.cnvtxt(source.getNote())) self.write_long_text("NOTE",1,self.cnvtxt(source.getNote()))
index = index + 1 index = index + 1
if index % 100 == 0: if index % 100 == 0:
self.sbar.set_value((100*index)/nump) self.sbar.set_fraction(index/nump)
while(gtk.events_pending()): while(gtk.events_pending()):
gtk.mainiteration() gtk.mainiteration()
self.sbar.set_value(100.0) self.sbar.set_fraction(1.0)
def write_person(self,person): def write_person(self,person):
self.g.write("0 @%s@ INDI\n" % self.pid(person.getId())) self.g.write("0 @%s@ INDI\n" % self.pid(person.getId()))
@ -629,18 +648,18 @@ class GedcomWriter:
birth = person.getBirth() birth = person.getBirth()
if not (self.private and birth.getPrivacy()): if not (self.private and birth.getPrivacy()):
if not birth.getDateObj().isEmpty() or birth.getPlaceName() != "": if not birth.getDateObj().isEmpty() or birth.getPlaceName():
self.g.write("1 BIRT\n") self.g.write("1 BIRT\n")
self.dump_event_stats(birth) self.dump_event_stats(birth)
death = person.getDeath() death = person.getDeath()
if not (self.private and death.getPrivacy()): if not (self.private and death.getPrivacy()):
if not death.getDateObj().isEmpty() or death.getPlaceName() != "": if not death.getDateObj().isEmpty() or death.getPlaceName():
self.g.write("1 DEAT\n") self.g.write("1 DEAT\n")
self.dump_event_stats(death) self.dump_event_stats(death)
uid = person.getPafUid() uid = person.getPafUid()
if uid != "": if uid:
self.g.write("1 _UID %s\n" % uid) self.g.write("1 _UID %s\n" % uid)
ad = 0 ad = 0
@ -677,7 +696,7 @@ class GedcomWriter:
self.g.write('3 ADOP WIFE\n') self.g.write('3 ADOP WIFE\n')
else: else:
self.g.write('3 ADOP HUSB\n') self.g.write('3 ADOP HUSB\n')
elif val != "" : elif val :
self.g.write("1 %s %s\n" % (self.cnvtxt(val),\ self.g.write("1 %s %s\n" % (self.cnvtxt(val),\
self.cnvtxt(event.getDescription()))) self.cnvtxt(event.getDescription())))
else: else:
@ -712,13 +731,13 @@ class GedcomWriter:
val = const.personalConstantAttributes[name] val = const.personalConstantAttributes[name]
else: else:
val = "" val = ""
if val != "" : if val :
self.g.write("1 %s\n" % val) self.g.write("1 %s\n" % val)
else: else:
self.g.write("1 EVEN\n") self.g.write("1 EVEN\n")
self.g.write("2 TYPE %s\n" % self.cnvtxt(name)) self.g.write("2 TYPE %s\n" % self.cnvtxt(name))
self.g.write("2 PLAC %s\n" % self.cnvtxt(attr.getValue())) self.g.write("2 PLAC %s\n" % self.cnvtxt(attr.getValue()))
if attr.getNote() != "": if attr.getNote():
self.write_long_text("NOTE",2,self.cnvtxt(attr.getNote())) self.write_long_text("NOTE",2,self.cnvtxt(attr.getNote()))
for srcref in attr.getSourceRefList(): for srcref in attr.getSourceRefList():
self.write_source_ref(2,srcref) self.write_source_ref(2,srcref)
@ -730,13 +749,13 @@ class GedcomWriter:
self.print_date("2 DATE",addr.getDateObj()) self.print_date("2 DATE",addr.getDateObj())
if self.resi == 0: if self.resi == 0:
self.write_long_text("ADDR",2,addr.getStreet()) self.write_long_text("ADDR",2,addr.getStreet())
if addr.getCity() != "": if addr.getCity():
self.g.write("3 CITY %s\n" % addr.getCity()) self.g.write("3 CITY %s\n" % addr.getCity())
if addr.getState() != "": if addr.getState():
self.g.write("3 STAE %s\n" % addr.getState()) self.g.write("3 STAE %s\n" % addr.getState())
if addr.getPostal() != "": if addr.getPostal():
self.g.write("3 POST %s\n" % addr.getPostal()) self.g.write("3 POST %s\n" % addr.getPostal())
if addr.getCountry() != "": if addr.getCountry():
self.g.write("3 CTRY %s\n" % addr.getCountry()) self.g.write("3 CTRY %s\n" % addr.getCountry())
else: else:
text = addr.getStreet() text = addr.getStreet()
@ -746,7 +765,7 @@ class GedcomWriter:
text = addr_append(text,addr.getCountry()) text = addr_append(text,addr.getCountry())
if text: if text:
self.g.write("2 PLAC %s\n" % text) self.g.write("2 PLAC %s\n" % text)
if addr.getNote() != "": if addr.getNote():
self.write_long_text("NOTE",3,self.cnvtxt(addr.getNote())) self.write_long_text("NOTE",3,self.cnvtxt(addr.getNote()))
for srcref in addr.getSourceRefList(): for srcref in addr.getSourceRefList():
self.write_source_ref(3,srcref) self.write_source_ref(3,srcref)
@ -766,12 +785,12 @@ class GedcomWriter:
for url in person.getUrlList(): for url in person.getUrlList():
self.g.write('1 OBJE\n') self.g.write('1 OBJE\n')
self.g.write('2 FORM URL\n') self.g.write('2 FORM URL\n')
if url.get_description() != "": if url.get_description():
self.g.write('2 TITL %s\n' % url.get_description()) self.g.write('2 TITL %s\n' % url.get_description())
if url.get_path() != "": if url.get_path():
self.g.write('2 FILE %s\n' % url.get_path()) self.g.write('2 FILE %s\n' % url.get_path())
if person.getNote() != "": if person.getNote():
self.write_long_text("NOTE",1,self.cnvtxt(person.getNote())) self.write_long_text("NOTE",1,self.cnvtxt(person.getNote()))
def write_long_text(self,tag,level,note): def write_long_text(self,tag,level,note):
@ -841,11 +860,11 @@ class GedcomWriter:
def dump_event_stats(self,event): def dump_event_stats(self,event):
dateobj = event.getDateObj() dateobj = event.getDateObj()
self.print_date("2 DATE",dateobj) self.print_date("2 DATE",dateobj)
if event.getPlaceName() != "": if event.getPlaceName():
self.g.write("2 PLAC %s\n" % self.cnvtxt(event.getPlaceName())) self.g.write("2 PLAC %s\n" % self.cnvtxt(event.getPlaceName()))
if event.getCause() != "": if event.getCause():
self.g.write("2 CAUS %s\n" % self.cnvtxt(event.getCause())) self.g.write("2 CAUS %s\n" % self.cnvtxt(event.getCause()))
if event.getNote() != "": if event.getNote():
self.write_long_text("NOTE",2,self.cnvtxt(event.getNote())) self.write_long_text("NOTE",2,self.cnvtxt(event.getNote()))
for srcref in event.getSourceRefList(): for srcref in event.getSourceRefList():
self.write_source_ref(2,srcref) self.write_source_ref(2,srcref)
@ -857,13 +876,13 @@ class GedcomWriter:
self.print_date("%d DATE" % (index + 1), ord.getDateObj()) self.print_date("%d DATE" % (index + 1), ord.getDateObj())
if ord.getFamily(): if ord.getFamily():
self.g.write('%d FAMC @%s@\n' % (index+1,self.fid(ord.getFamily().getId()))) self.g.write('%d FAMC @%s@\n' % (index+1,self.fid(ord.getFamily().getId())))
if ord.getTemple() != "": if ord.getTemple():
self.g.write('%d TEMP %s\n' % (index+1,ord.getTemple())) self.g.write('%d TEMP %s\n' % (index+1,ord.getTemple()))
if ord.getPlaceName() != "": if ord.getPlaceName():
self.g.write("2 PLAC %s\n" % self.cnvtxt(ord.getPlaceName())) self.g.write("2 PLAC %s\n" % self.cnvtxt(ord.getPlaceName()))
if ord.getStatus() != 0: if ord.getStatus() != 0:
self.g.write("2 STAT %s\n" % self.cnvtxt(statlist[ord.getStatus()])) self.g.write("2 STAT %s\n" % self.cnvtxt(statlist[ord.getStatus()]))
if ord.getNote() != "": if ord.getNote():
self.write_long_text("NOTE",index+1,self.cnvtxt(ord.getNote())) self.write_long_text("NOTE",index+1,self.cnvtxt(ord.getNote()))
for srcref in ord.getSourceRefList(): for srcref in ord.getSourceRefList():
self.write_source_ref(index+1,srcref) self.write_source_ref(index+1,srcref)
@ -872,14 +891,14 @@ class GedcomWriter:
start = date.get_start_date() start = date.get_start_date()
if date.isEmpty(): if date.isEmpty():
val = date.getText() val = date.getText()
if val != "": if val:
self.g.write("%s %s\n" % (prefix,self.cnvtxt(val))) self.g.write("%s %s\n" % (prefix,self.cnvtxt(val)))
else: else:
if date.isRange(): if date.isRange():
val = "FROM %s TO %s" % (make_date(start), val = "FROM %s TO %s" % (make_date(start),
make_date(date.get_stop_date())) make_date(date.get_stop_date()))
else: else:
val = make_date(start,_month) val = make_date(start)
self.g.write("%s %s\n" % (prefix,val)) self.g.write("%s %s\n" % (prefix,val))
def write_person_name(self,name,nick): def write_person_name(self,name,nick):
@ -889,22 +908,22 @@ class GedcomWriter:
suffix = self.cnvtxt(name.getSuffix()) suffix = self.cnvtxt(name.getSuffix())
title = self.cnvtxt(name.getTitle()) title = self.cnvtxt(name.getTitle())
if suffix == "": if suffix == "":
if surPref: if not surPref:
self.g.write("1 NAME %s /%s/\n" % (firstName,surName)) self.g.write("1 NAME %s /%s/\n" % (firstName,surName))
else: else:
self.g.write("1 NAME %s /%s %s/\n" % (firstName,surPref,surName)) self.g.write("1 NAME %s /%s %s/\n" % (firstName,surPref,surName))
else: else:
if surPref: if not surPref:
self.g.write("1 NAME %s /%s %s/, %s\n" % (firstName,surPref,surName,suffix)) self.g.write("1 NAME %s /%s %s/, %s\n" % (firstName,surPref,surName,suffix))
else: else:
self.g.write("1 NAME %s /%s/, %s\n" % (firstName,surName,suffix)) self.g.write("1 NAME %s /%s/, %s\n" % (firstName,surName,suffix))
if name.getFirstName() != "": if name.getFirstName():
self.g.write("2 GIVN %s\n" % firstName) self.g.write("2 GIVN %s\n" % firstName)
if self.prefix: if self.prefix:
if surPref: if surPref:
self.g.write('2 SPFX %s\n' % surPref) self.g.write('2 SPFX %s\n' % surPref)
if surName != "": if surName:
self.g.write("2 SURN %s\n" % surName) self.g.write("2 SURN %s\n" % surName)
else: else:
if surPref: if surPref:
@ -912,13 +931,13 @@ class GedcomWriter:
elif surName: elif surName:
self.g.write("2 SURN %s\n" % surName) self.g.write("2 SURN %s\n" % surName)
if name.getSuffix() != "": if name.getSuffix():
self.g.write("2 NSFX %s\n" % suffix) self.g.write("2 NSFX %s\n" % suffix)
if name.getTitle() != "": if name.getTitle():
self.g.write("2 NPFX %s\n" % title) self.g.write("2 NPFX %s\n" % title)
if nick != "": if nick:
self.g.write('2 NICK %s\n' % nick) self.g.write('2 NICK %s\n' % nick)
if name.getNote() != "": if name.getNote():
self.write_long_text("NOTE",2,self.cnvtxt(name.getNote())) self.write_long_text("NOTE",2,self.cnvtxt(name.getNote()))
for srcref in name.getSourceRefList(): for srcref in name.getSourceRefList():
self.write_source_ref(2,srcref) self.write_source_ref(2,srcref)
@ -927,29 +946,29 @@ class GedcomWriter:
if ref.getBase() == None: if ref.getBase() == None:
return return
self.g.write("%d SOUR @%s@\n" % (level,self.sid(ref.getBase().getId()))) self.g.write("%d SOUR @%s@\n" % (level,self.sid(ref.getBase().getId())))
if ref.getPage() != "": if ref.getPage():
self.g.write("%d PAGE %s\n" % (level+1,ref.getPage())) self.g.write("%d PAGE %s\n" % (level+1,ref.getPage()))
ref_text = ref.getText() ref_text = ref.getText()
if ref_text != "" or not ref.getDate().isEmpty(): if ref_text or not ref.getDate().isEmpty():
self.g.write('%d DATA\n' % (level+1)) self.g.write('%d DATA\n' % (level+1))
if ref_text != "": if ref_text:
self.write_long_text("TEXT",level+2,ref_text) self.write_long_text("TEXT",level+2,ref_text)
pfx = "%d DATE" % (level+2) pfx = "%d DATE" % (level+2)
self.print_date(pfx,ref.getDate()) self.print_date(pfx,ref.getDate())
if ref.getComments() != "": if ref.getComments():
self.write_long_text("NOTE",level+1,ref.getComments()) self.write_long_text("NOTE",level+1,ref.getComments())
def fid(self,id): def fid(self,id):
return id return id
def prefn(self,person): def prefn(self,person):
match = get_int.search(person.getId()) match = _get_int.search(person.getId())
if match: if match:
self.g.write('1 REFN %d\n' % int(match.groups()[0])) self.g.write('1 REFN %d\n' % int(match.groups()[0]))
def frefn(self,family): def frefn(self,family):
match = get_int.search(family.getId()) match = _get_int.search(family.getId())
if match: if match:
self.g.write('1 REFN %d\n' % int(match.groups()[0])) self.g.write('1 REFN %d\n' % int(match.groups()[0]))