First attempt at alternate calendars

svn: r576
This commit is contained in:
Don Allingham 2001-11-22 21:08:16 +00:00
parent ef85983963
commit 9722180ef3
8 changed files with 392 additions and 243 deletions

View File

@ -21,9 +21,9 @@
"Support for the dates" "Support for the dates"
from re import IGNORECASE, compile from re import IGNORECASE, compile
import string import string
from Calendar import *
from intl import gettext from intl import gettext
_ = gettext _ = gettext
@ -43,6 +43,21 @@ _cal2index = { _("Gregorian") : 0,
_("Hebrew") : 2, _("Hebrew") : 2,
_("French Republican"): 3 } _("French Republican"): 3 }
_fmonth = [
"Vendemiaire", "Brumaire", "Frimaire", "Nivose", "Pluviose",
"Ventose", "Germinal", "Floreal", "Prairial", "Messidor", "Thermidor",
"Fructidor", "Extra", ]
_fmonth2num = {
"VEND" : 1, "BRUM" : 2, "FRIM" : 3, "NIVO" : 4, "PLUV" : 5,
"VENT" : 6, "GERM" : 7, "FLOR" : 8, "PRAI" : 8, "MESS" : 10,
"THER" :11, "FRUC" :12, "EXTR" : 13 }
_hmonth = [
"", "Tishri", "Heshvan", "Kislev", "Tevet", "Shevat", "AdarI",
"AdarII", "Nisan", "Iyyar", "Sivan", "Tammuz", "Av", "Elul"
]
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Date class # Date class
@ -69,7 +84,7 @@ class Date:
def __init__(self,source=None): def __init__(self,source=None):
if source: if source:
self.start = SingleDate(source.start) self.start = SingleDate(source.start)
if source.start: if source.stop:
self.stop = SingleDate(source.stop) self.stop = SingleDate(source.stop)
else: else:
self.stop = None self.stop = None
@ -88,6 +103,9 @@ class Date:
def set_calendar(self,val): def set_calendar(self,val):
self.calendar = val self.calendar = val
self.start.convert_to(val)
if self.stop:
self.stop.convert_to(val)
def get_start_date(self): def get_start_date(self):
return self.start return self.start
@ -95,6 +113,7 @@ class Date:
def get_stop_date(self): def get_stop_date(self):
if self.stop == None: if self.stop == None:
self.stop = SingleDate() self.stop = SingleDate()
self.stop.calendar = self.calendar
return self.stop return self.stop
def getYear(self): def getYear(self):
@ -118,16 +137,19 @@ class Date:
def getStopYear(self): def getStopYear(self):
if self.stop == None: if self.stop == None:
self.stop = SingleDate() self.stop = SingleDate()
self.stop.calendar = self.calendar
return self.get_stop_date().getYear() return self.get_stop_date().getYear()
def getStopMonth(self): def getStopMonth(self):
if self.stop == None: if self.stop == None:
self.stop = SingleDate() self.stop = SingleDate()
self.stop.calendar = self.calendar
return self.get_stop_date().getMonth() return self.get_stop_date().getMonth()
def getStopDay(self): def getStopDay(self):
if self.stop == None: if self.stop == None:
self.stop = SingleDate() self.stop = SingleDate()
self.stop.calendar = self.calendar
return self.get_stop_date().getDay() return self.get_stop_date().getDay()
def getText(self): def getText(self):
@ -150,6 +172,7 @@ class Date:
self.start.set(matches[1]) self.start.set(matches[1])
if self.stop == None: if self.stop == None:
self.stop = SingleDate() self.stop = SingleDate()
self.stop.calendar = self.calendar
self.stop.set(matches[3]) self.stop.set(matches[3])
self.range = 1 self.range = 1
else: else:
@ -164,26 +187,105 @@ class Date:
def getDate(self): def getDate(self):
if self.range == 0: if self.range == 0:
return _func(self.start) return self.start.getDate()
elif self.range == -1: elif self.range == -1:
return self.text return self.text
else: else:
d1 = _func(self.start) d1 = self.start.getDate()
d2 = _func(self.stop) d2 = self.stop.getDate()
return "%s %s %s %s" % ( _("from"),d1,_("to"),d2 )
def getFrench(self):
if self.range == 0:
return self.start.getFrench()
elif self.range == -1:
return self.text
else:
d1 = self.start.displayFrench(self.start)
d2 = self.start.displayFrench(self.stop)
return "%s %s %s %s" % ( _("from"),d1,_("to"),d2 )
def getHebrew(self):
if self.range == 0:
return self.start.displayHebrew()
elif self.range == -1:
return self.text
else:
d1 = self.start.displayHebrew(self.start)
d2 = self.start.displayHebrew(self.stop)
return "%s %s %s %s" % ( _("from"),d1,_("to"),d2 )
def getJulian(self):
if self.range == 0:
return self.start.displayJulian()
elif self.range == -1:
return self.text
else:
d1 = self.start.displayJulian(self.start)
d2 = self.start.displayJulian(self.stop)
return "%s %s %s %s" % ( _("from"),d1,_("to"),d2 ) return "%s %s %s %s" % ( _("from"),d1,_("to"),d2 )
def getQuoteDate(self): def getQuoteDate(self):
if self.range == 0: if self.calendar == GREGORIAN:
return _func(self.start) return self.getGregorianQuoteDate()
elif self.calendar == JULIAN:
return self.getJulianQuoteDate()
elif self.calendar == HEBREW:
return self.getHebrewQuoteDate()
else:
return self.getFrenchQuoteDate()
def getGregorianQuoteDate(self):
if self.range == 0:
return _func(self.start)
elif self.range == -1: elif self.range == -1:
if self.text: if self.text:
return '"%s"' % self.text return '"%s"' % self.text
else: else:
return '' return ''
else: else:
d1 = _func(self.start) d1 = _func(self.start)
d2 = _func(self.stop) d2 = _func(self.stop)
return "%s %s %s %s" % ( _("from"),d1,_("to"), d2) return "%s %s %s %s" % ( _("from"),d1,_("to"), d2)
def getFrenchQuoteDate(self):
if self.range == 0:
return "%s (%s)" % (self.start.displayFrench(),_("French"))
elif self.range == -1:
if self.text:
return '"%s (%s)"' % (self.text,_("French"))
else:
return '%s' % _("French")
else:
d1 = self.start.getFrench()
d2 = self.stop.getFrench()
return "%s %s %s %s (%s)" % ( _("from"),d1,_("to"), d2,_("French"))
def getJulianQuoteDate(self):
if self.range == 0:
return "%s (%s)" % (self.start.displayJulian(),_("Julian"))
elif self.range == -1:
if self.text:
return '"%s (%s)"' % (self.text,_("Julian"))
else:
return '%s' % _("Julian")
else:
d1 = self.start.getJulian()
d2 = self.stop.getJulian()
return "%s %s %s %s (%s)" % ( _("from"),d1,_("to"), d2,_("Julian"))
def getHebrewQuoteDate(self):
if self.range == 0:
return "%s (%s)" % (self.start.displayHebrew(),_("Hebrew"))
elif self.range == -1:
if self.text:
return '"%s (%s)"' % (self.text,_("Hebrew"))
else:
return '%s' % _("Hebrew")
else:
d1 = self.start.getHebrew()
d2 = self.stop.getHebrew()
return "%s %s %s %s (%s)" % ( _("from"),d1,_("to"), d2,_("Hebrew"))
def getSaveDate(self): def getSaveDate(self):
if self.range == 1: if self.range == 1:
@ -213,27 +315,6 @@ class Date:
else: else:
return 0 return 0
def quick_set(self,text):
try:
match = Date.efmt.match(text)
if match:
matches = match.groups()
self.start.set(matches[1])
if self.stop == None:
self.stop = SingleDate()
self.stop.set(matches[3])
self.range = 1
else:
try:
self.start.quick_set(text)
self.range = 0
except:
self.start.set(text)
self.range = 0
except:
self.range = -1
self.text = text
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
@ -342,50 +423,20 @@ class SingleDate:
fmt5 = compile(start + "(\d+)\s*$", IGNORECASE) fmt5 = compile(start + "(\d+)\s*$", IGNORECASE)
fmt6 = compile(start + "(\S+)\s*$", IGNORECASE) fmt6 = compile(start + "(\S+)\s*$", IGNORECASE)
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def __init__(self,source=None): def __init__(self,source=None):
if source: if source:
self.month = source.month self.month = source.month
self.day = source.day self.day = source.day
self.year = source.year self.year = source.year
self.mode = source.mode self.mode = source.mode
self.calendar = source.calendar
else: else:
self.month = -1 self.month = -1
self.day = -1 self.day = -1
self.year = -1 self.year = -1
self.mode = SingleDate.exact self.mode = SingleDate.exact
self.calendar = GREGORIAN
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def my__cmp__(self,other):
if other == None:
return 0
elif self.year != other.year:
return cmp(self.year,other.year)
elif self.month != other.month:
return cmp(self.month,other.month)
elif self.day != other.day:
return cmp(self.day,other.day)
elif self.mode != other.mode:
if self.mode == SingleDate.exact:
return -1
else:
return 1
else:
return 0
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def setMode(self,val): def setMode(self,val):
if val == None: if val == None:
self.mode = SingleDate.exact self.mode = SingleDate.exact
@ -393,73 +444,33 @@ class SingleDate:
val = string.lower(val) val = string.lower(val)
self.mode = SingleDate.m2v[val] self.mode = SingleDate.m2v[val]
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def setMonth(self,val): def setMonth(self,val):
if val > 12: if val > 12:
self.month = -1 self.month = -1
else: else:
self.month = val - 1 self.month = val - 1
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getMonth(self): def getMonth(self):
return self.month + 1 return self.month + 1
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def setDay(self,val): def setDay(self,val):
self.day = val self.day = val
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getDay(self): def getDay(self):
return self.day return self.day
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def setYear(self,val): def setYear(self,val):
self.year = val self.year = val
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getYear(self): def getYear(self):
return self.year return self.year
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def setMonthStr(self,text): def setMonthStr(self,text):
try: try:
self.month = SingleDate.m2num[string.lower(text[0:3])] self.month = SingleDate.m2num[string.lower(text[0:3])]
except KeyError: except KeyError:
self.setMonthStrEng(text) self.setMonthStrEng(text)
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def setMonthStrEng(self,text): def setMonthStrEng(self,text):
try: try:
self.month = SingleDate.em2num[string.lower(text[0:3])] self.month = SingleDate.em2num[string.lower(text[0:3])]
@ -487,11 +498,6 @@ class SingleDate:
d = "-%02d" % self.day d = "-%02d" % self.day
return "%s%s%s" % (y,m,d) return "%s%s%s" % (y,m,d)
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getSaveDate(self): def getSaveDate(self):
retval = "" retval = ""
@ -553,11 +559,6 @@ class SingleDate:
return retval return retval
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getFmt2(self): def getFmt2(self):
if self.month == -1 and self.day == -1 and self.year == -1 : if self.month == -1 and self.day == -1 and self.year == -1 :
return "" return ""
@ -588,11 +589,6 @@ class SingleDate:
return retval return retval
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getFmt3(self): def getFmt3(self):
retval = "" retval = ""
@ -625,11 +621,6 @@ class SingleDate:
return retval return retval
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getFmt10(self): def getFmt10(self):
retval = "" retval = ""
@ -661,11 +652,6 @@ class SingleDate:
return retval return retval
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def get_mmddyyyy(self,sep): def get_mmddyyyy(self,sep):
retval = "" retval = ""
@ -696,11 +682,6 @@ class SingleDate:
return retval return retval
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def get_yyyymmdd(self,sep): def get_yyyymmdd(self,sep):
retval = "" retval = ""
@ -731,35 +712,15 @@ class SingleDate:
return retval return retval
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getFmt4(self): def getFmt4(self):
return self.get_mmddyyyy("/") return self.get_mmddyyyy("/")
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getFmt5(self): def getFmt5(self):
return self.get_mmddyyyy("-") return self.get_mmddyyyy("-")
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getFmt8(self): def getFmt8(self):
return self.get_mmddyyyy(".") return self.get_mmddyyyy(".")
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def get_ddmmyyyy(self,sep): def get_ddmmyyyy(self,sep):
retval = "" retval = ""
@ -788,52 +749,22 @@ class SingleDate:
retval = "%s %s" % (_("AFTER"),retval) retval = "%s %s" % (_("AFTER"),retval)
return retval return retval
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getFmt6(self): def getFmt6(self):
return self.get_ddmmyyyy("/") return self.get_ddmmyyyy("/")
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getFmt7(self): def getFmt7(self):
return self.get_ddmmyyyy("-") return self.get_ddmmyyyy("-")
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getFmt9(self): def getFmt9(self):
return self.get_ddmmyyyy(".") return self.get_ddmmyyyy(".")
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getFmt11(self): def getFmt11(self):
return self.get_yyyymmdd("/") return self.get_yyyymmdd("/")
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getFmt12(self): def getFmt12(self):
return self.get_yyyymmdd("-") return self.get_yyyymmdd("-")
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getFmt13(self): def getFmt13(self):
return self.get_yyyymmdd(".") return self.get_yyyymmdd(".")
@ -846,14 +777,60 @@ class SingleDate:
getFmt7, getFmt8, getFmt9, getFmt10, getFmt11, getFmt12, getFmt7, getFmt8, getFmt9, getFmt10, getFmt11, getFmt12,
getFmt13] getFmt13]
#-------------------------------------------------------------------- def displayFrench(self):
# if self.year==-1:
# if self.month == -1:
# return ""
#-------------------------------------------------------------------- elif self.day == -1:
return _fmonth[self.month]
else:
return "%02 %s" % (self.day,_fmonth[self.month])
elif self.month == -1:
return "%d" % self.year
elif self.day == -1:
return "%s %d" % (_fmonth[self.month],self.year)
else:
return "%02d %s %d" % (self.day,_fmonth[self.month],self.year)
def displayHebrew(self):
if self.year==-1:
if self.month == -1:
return ""
elif self.day == -1:
return _hmonth[self.month]
else:
return "%02 %s" % (self.day,_hmonth[self.month])
elif self.month == -1:
return "%d" % self.year
elif self.day == -1:
return "%s %d" % (_hmonth[self.month],self.year)
else:
return "%02d %s %d" % (self.day,_hmonth[self.month],self.year)
def displayJulian(self):
if self.year==-1:
if self.month == -1:
return ""
elif self.day == -1:
return self.mname[self.month]
else:
return "%02 %s" % (self.day,self.mname[self.month])
elif self.month == -1:
return "%d" % self.year
elif self.day == -1:
return "%s %d" % (self.mname[self.month],self.year)
else:
return "%02d %s %d" % (self.day,self.mname[self.month],self.year)
def getDate(self): def getDate(self):
function = SingleDate.fmtFunc[Date.formatCode] if self.calendar == GREGORIAN:
return function(self) return _func(self)
elif self.calendar == JULIAN:
return self.displayJulian()
elif self.calendar == HEBREW:
return self.displayHebrew()
else:
return self.displayFrench()
def setIsoDate(self,v): def setIsoDate(self,v):
data = string.split(v) data = string.split(v)
@ -875,18 +852,12 @@ class SingleDate:
else: else:
self.day = -1 self.day = -1
def getModeVal(self): def getModeVal(self):
return self.mode return self.mode
def setModeVal(self,val): def setModeVal(self,val):
self.mode = val self.mode = val
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def getMode(self,val): def getMode(self,val):
if val == None: if val == None:
self.mode = SingleDate.exact self.mode = SingleDate.exact
@ -899,12 +870,72 @@ class SingleDate:
else: else:
self.mode = SingleDate.exact self.mode = SingleDate.exact
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def set(self,text): def set(self,text):
if self.calendar == GREGORIAN:
self.set_gregorian(text)
elif self.calendar == JULIAN:
self.set_julian(text)
elif self.calendar == HEBREW:
self.set_hebrew(text)
else:
self.set_french(text)
def set_french(self,text):
match = SingleDate.fmt2.match(text)
if match:
matches = match.groups()
mon = string.upper(matches[2])[0:4]
if _fmonth2num.has_key(mon):
self.setYear(int(matches[3]))
self.setMonth(_fmonth2num[mon])
self.setDay(int(matches[1]))
return
else:
self.setYear(int(matches[3]))
self.setMonth(-1)
self.setDay(-1)
return
match = SingleDate.fmt3.match(text)
if match:
matches = match.groups()
self.setYear(int(matches[3]))
self.setMonth(int(matches[2]))
self.setDay(int(matches[1]))
else:
self.setYear(-1)
self.setMonth(-1)
self.setDay(-1)
def set_hebrew(self,text):
pass
def set_julian(self,text):
match = SingleDate.fmt2.match(text)
if match:
matches = match.groups()
mon = string.lower(matches[2])[0:3]
if SingleDate.m2num.has_key(mon):
self.setYear(int(matches[3]))
self.setMonth(SingleDate.m2num[mon]+1)
self.setDay(int(matches[1]))
return
else:
self.setYear(int(matches[3]))
self.setMonth(-1)
self.setDay(-1)
return
match = SingleDate.fmt3.match(text)
if match:
matches = match.groups()
self.setYear(int(matches[3]))
self.setMonth(int(matches[2]))
self.setDay(int(matches[1]))
else:
self.setYear(-1)
self.setMonth(-1)
self.setDay(-1)
def set_gregorian(self,text):
match = SingleDate.fmt2.match(text) match = SingleDate.fmt2.match(text)
if match != None: if match != None:
matches = match.groups() matches = match.groups()
@ -1063,33 +1094,89 @@ class SingleDate:
raise Date.Error,text raise Date.Error,text
#-------------------------------------------------------------------- def get_sdn(self):
# if self.year == -1:
# return 0
# if self.month == -1:
#-------------------------------------------------------------------- month = 1
def quick_set(self,text):
match = SingleDate.quick.match(text)
if match != None:
matches = match.groups()
self.setMode(matches[0])
self.setMonthStrEng(matches[2])
if self.month == -1:
raise Date.Error,text
self.day = int(matches[1])
if len(matches) == 4:
val = matches[3]
if val == None or val[0] == '?':
self.year = -1
else:
self.year = int(val)
else:
self.year = -1
else: else:
month = self.month + 1
if self.day == -1:
day = 1
else:
day = self.day
if self.calendar == GREGORIAN:
sdn = gregorian_to_sdn(self.year,month,day)
elif self.calendar == FRENCH:
sdn = french_to_sdn(self.year,month,day)
if self.calendar == HEBREW:
sdn = jewish_to_sdn(self.year,month,day)
if self.calendar == JULIAN:
sdn = julian_to_sdn(self.year,month,day)
return sdn
def convert_to(self,val):
if val == GREGORIAN:
self.convertGregorian()
elif val == JULIAN:
self.convertJulian()
elif val == HEBREW:
self.convertHebrew()
else:
self.convertFrench()
def convertFrench(self):
sdn = self.get_sdn()
(y,m,d) = sdn_to_french(sdn)
self.calendar = FRENCH
if y == 0 and m == 0 and d == 0:
self.year = -1 self.year = -1
self.month = -1 self.month = -1
self.day = -1 self.day = -1
raise Date.Error,text else:
self.year = y
self.month = m-1
self.day = d
def convertHebrew(self):
sdn = self.get_sdn()
(y,m,d) = sdn_to_jewish(sdn)
self.calendar = HEBREW
if y == 0 and m == 0 and d == 0:
self.year = -1
self.month = -1
self.day = -1
else:
self.year = y
self.month = m-1
self.day = d
def convertJulian(self):
sdn = self.get_sdn()
self.calendar = JULIAN
(y,m,d) = sdn_to_julian(sdn)
if y == 0 and m == 0 and d == 0:
self.year = -1
self.month = -1
self.day = -1
else:
self.year = y
self.month = m-1
self.day = d
def convertGregorian(self):
sdn = self.get_sdn()
self.calendar = GREGORIAN
(y,m,d) = sdn_to_gregorian(sdn)
if y == 0 and m == 0 and d == 0:
self.year = -1
self.month = -1
self.day = -1
else:
self.year = y
self.month = m-1
self.day = d
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -1097,6 +1184,8 @@ class SingleDate:
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def compare_dates(f,s): def compare_dates(f,s):
if f.calendar != s.calendar:
return 1
if f.range == -1 and s.range == -1: if f.range == -1 and s.range == -1:
return cmp(f.text,s.text) return cmp(f.text,s.text)
if f.range == -1 or s.range == -1: if f.range == -1 or s.range == -1:
@ -1108,8 +1197,17 @@ def compare_dates(f,s):
return cmp(first.year,second.year) return cmp(first.year,second.year)
elif first.month != second.month: elif first.month != second.month:
return cmp(first.month,second.month) return cmp(first.month,second.month)
else: elif f.range != 1:
return cmp(first.day,second.day) return cmp(first.day,second.day)
else:
first = f.get_stop_date()
second = s.get_stop_date()
if first.year != second.year:
return cmp(first.year,second.year)
elif first.month != second.month:
return cmp(first.month,second.month)
else:
return cmp(first.day,second.day)
_func = SingleDate.fmtFunc[0] _func = SingleDate.fmtFunc[0]
@ -1145,4 +1243,11 @@ if __name__ == "__main__":
print "----------" print "----------"
checkit("BET. 1994 - 1999") checkit("BET. 1994 - 1999")
sdn = french_to_sdn(1,1,1)
print sdn_to_gregorian(sdn)
d = Date()
d.get_start_date().setMonth(9)
d.get_start_date().setYear(1792)
d.get_start_date().setDay(22)
print d.get_start_date().getFrench()

View File

@ -26,6 +26,7 @@ from string import strip
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import libglade import libglade
import gtk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -36,7 +37,10 @@ import Sources
import const import const
import utils import utils
import Config import Config
from Date import compare_dates
from RelLib import * from RelLib import *
from intl import gettext
_ = gettext
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -48,6 +52,7 @@ class EventEditor:
def __init__(self,parent,name,list,trans,event,def_placename,read_only): def __init__(self,parent,name,list,trans,event,def_placename,read_only):
self.parent = parent self.parent = parent
self.event = event self.event = event
self.date = Date(event.getDateObj())
self.trans = trans self.trans = trans
if event: if event:
self.srcreflist = self.event.getSourceRefList() self.srcreflist = self.event.getSourceRefList()
@ -93,7 +98,7 @@ class EventEditor:
self.place_field.set_text(event.getPlaceName()) self.place_field.set_text(event.getPlaceName())
if (def_placename): if (def_placename):
self.place_field.set_text(def_placename) self.place_field.set_text(def_placename)
self.date_field.set_text(event.getDate()) self.date_field.set_text(event.getPrefDate())
self.cause_field.set_text(event.getCause()) self.cause_field.set_text(event.getCause())
self.descr_field.set_text(event.getDescription()) self.descr_field.set_text(event.getDescription())
self.priv.set_active(event.getPrivacy()) self.priv.set_active(event.getPrivacy())
@ -106,8 +111,9 @@ class EventEditor:
if (def_placename): if (def_placename):
self.place_field.set_text(def_placename) self.place_field.set_text(def_placename)
if (not read_only): if not read_only:
self.name_field.select_region(0, -1) self.name_field.select_region(0, -1)
self.window.set_data("o",self) self.window.set_data("o",self)
self.top.signal_autoconnect({ self.top.signal_autoconnect({
"destroy_passed_object" : utils.destroy_passed_object, "destroy_passed_object" : utils.destroy_passed_object,
@ -116,13 +122,29 @@ class EventEditor:
"on_source_clicked" : self.on_edit_source_clicked "on_source_clicked" : self.on_edit_source_clicked
}) })
menu = gtk.GtkMenu()
names = [ _("Gregorian"), _("Julian"), _("Hebrew"), ("French") ]
for index in range(0,len(names)):
item = gtk.GtkMenuItem(names[index])
item.set_data("d",index)
item.connect("activate",self.on_menu_changed)
item.show()
menu.append(item)
menu.set_active(self.date.get_calendar())
self.calendar.set_menu(menu)
def on_menu_changed(self,obj):
self.date.set_calendar(obj.get_data("d"))
self.date_field.set_text(self.date.getDate())
def on_edit_source_clicked(self,obj): def on_edit_source_clicked(self,obj):
Sources.SourceSelector(self.srcreflist,self.parent,src_changed) Sources.SourceSelector(self.srcreflist,self.parent,src_changed)
def on_event_edit_ok_clicked(self,obj): def on_event_edit_ok_clicked(self,obj):
ename = self.name_field.get_text() ename = self.name_field.get_text()
edate = self.date_field.get_text() self.date.set(self.date_field.get_text())
ecause = self.cause_field.get_text() ecause = self.cause_field.get_text()
eplace = strip(self.place_field.get_text()) eplace = strip(self.place_field.get_text())
eplace_obj = utils.get_place_from_list(self.place_combo) eplace_obj = utils.get_place_from_list(self.place_combo)
@ -140,7 +162,7 @@ class EventEditor:
eplace_obj.set_title(eplace) eplace_obj.set_title(eplace)
self.parent.db.addPlace(eplace_obj) self.parent.db.addPlace(eplace_obj)
self.update_event(ename,edate,eplace_obj,edesc,enote,epriv,ecause) self.update_event(ename,self.date,eplace_obj,edesc,enote,epriv,ecause)
self.parent.redraw_event_list() self.parent.redraw_event_list()
utils.destroy_passed_object(obj) utils.destroy_passed_object(obj)
@ -161,8 +183,10 @@ class EventEditor:
self.event.setNote(note) self.event.setNote(note)
self.parent.lists_changed = 1 self.parent.lists_changed = 1
if self.event.getDate() != date: dobj = self.event.getDateObj()
self.event.setDate(date)
if compare_dates(dobj,date) != 0:
self.event.setDateObj(date)
self.parent.lists_changed = 1 self.parent.lists_changed = 1
if self.event.getCause() != cause: if self.event.getCause() != cause:

View File

@ -385,8 +385,8 @@ class GrampsParser:
d = self.event.getDateObj() d = self.event.getDateObj()
d.get_start_date().setIsoDate(attrs['start']) d.get_start_date().setIsoDate(attrs['start'])
d.get_stop_date().setIsoDate(attrs['stop']) d.get_stop_date().setIsoDate(attrs['stop'])
if attrs.has_key("dpref"): if attrs.has_key("calendar"):
d.set_calendar(int(attrs['dpref'])) d.set_calendar(int(attrs['calendar']))
def start_dateval(self,attrs): def start_dateval(self,attrs):
if self.address: if self.address:
@ -401,8 +401,8 @@ class GrampsParser:
else: else:
d.get_start_date().getMode(None) d.get_start_date().getMode(None)
if attrs.has_key("dpref"): if attrs.has_key("calendar"):
d.set_calendar(int(attrs['dpref'])) d.set_calendar(int(attrs['calendar']))
def start_datestr(self,attrs): def start_datestr(self,attrs):
if self.address: if self.address:
@ -519,7 +519,7 @@ class GrampsParser:
def stop_sdate(self,tag): def stop_sdate(self,tag):
date = Date() date = Date()
date.quick_set(u2l(tag)) date.set(u2l(tag))
self.source_ref.setDate(date) self.source_ref.setDate(date)
def stop_street(self,tag): def stop_street(self,tag):

View File

@ -263,7 +263,11 @@ class HtmlDoc(TextDoc):
return return
self.empty = 0 self.empty = 0
im = PIL.Image.open(name) try:
im = PIL.Image.open(name)
except:
return
nx,ny = im.size nx,ny = im.size
scale = float(nx)/float(ny) scale = float(nx)/float(ny)

View File

@ -40,7 +40,6 @@ from gnome.ui import GnomeErrorDialog
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from RelLib import * from RelLib import *
from GrampsParser import GrampsParser, GrampsImportParser from GrampsParser import GrampsParser, GrampsImportParser
from xml.parsers.expat import ExpatError
from intl import gettext from intl import gettext
_ = gettext _ = gettext
@ -96,9 +95,6 @@ def importData(database, filename, callback):
try: try:
parser.parse(xml_file) parser.parse(xml_file)
except ExpatError,msg:
errmsg = "%s\n%s" % (_("Error reading %s") % filename,str(msg))
GnomeErrorDialog(errmsg)
except IOError,msg: except IOError,msg:
GnomeErrorDialog(_("Error reading %s") % filename + "\n" + str(msg)) GnomeErrorDialog(_("Error reading %s") % filename + "\n" + str(msg))
import traceback import traceback

View File

@ -561,6 +561,11 @@ class Address(DataObj):
lived at the address""" lived at the address"""
return self.date.getDate() return self.date.getDate()
def getPrefDate(self):
"""returns a string representation of the date that the person
lived at the address"""
return self.date.getPrefDate()
def getDateObj(self): def getDateObj(self):
"""returns the Date object associated with the Address""" """returns the Date object associated with the Address"""
return self.date return self.date
@ -1128,6 +1133,12 @@ class Event(DataObj):
return self.date.getDate() return self.date.getDate()
return "" return ""
def getPrefDate(self) :
"""returns a string representation of the date of the Event instance"""
if self.date:
return self.date.getDate()
return ""
def getQuoteDate(self) : def getQuoteDate(self) :
"""returns a string representation of the date of the Event instance, """returns a string representation of the date of the Event instance,
enclosing the results in quotes if it is not a valid date""" enclosing the results in quotes if it is not a valid date"""
@ -1141,6 +1152,10 @@ class Event(DataObj):
self.date = Date() self.date = Date()
return self.date return self.date
def setDateObj(self,date):
"""sets the Date object associated with the Event"""
self.date = date
def getSaveDate(self) : def getSaveDate(self) :
"""returns the date of the Event in the form wanted by gramps XML save""" """returns the date of the Event in the form wanted by gramps XML save"""
if self.date: if self.date:

View File

@ -217,7 +217,7 @@ def write_date(g,date,indent=1):
cal = date.get_calendar() cal = date.get_calendar()
if cal != 0: if cal != 0:
calstr = 'dpref="%s"' % fix(str(cal)) calstr = ' calendar="%s"' % fix(str(cal))
else: else:
calstr = '' calstr = ''

View File

@ -569,6 +569,11 @@
<visible>False</visible> <visible>False</visible>
<tooltip>Selects the calendar format for display</tooltip> <tooltip>Selects the calendar format for display</tooltip>
<can_focus>True</can_focus> <can_focus>True</can_focus>
<signal>
<name>clicked</name>
<handler>on_calendar_clicked</handler>
<last_modification_time>Wed, 21 Nov 2001 15:24:48 GMT</last_modification_time>
</signal>
<items>Gregorian <items>Gregorian
Julian Julian
Hebrew Hebrew