* src/DateDisplay.py: Make DateDisplayEn inherit from DateDisplay, make

DateDisplay handle only ISO dates
* src/DateHandler.py: use DateDisplayEn for English languages, use
DateDisplay for CJK
* src/GrampsCfg.py: Don't do initial redisplay of Person List when
dialog comes up, update dates dynamically when date format changes


svn: r3908
This commit is contained in:
Don Allingham 2005-01-12 21:23:31 +00:00
parent 2b583a8e6d
commit 5d61ffc49c
4 changed files with 132 additions and 81 deletions

View File

@ -1,3 +1,11 @@
2005-01-12 Don Allingham <dallingham@users.sourceforge.net>
* src/DateDisplay.py: Make DateDisplayEn inherit from DateDisplay, make
DateDisplay handle only ISO dates
* src/DateHandler.py: use DateDisplayEn for English languages, use
DateDisplay for CJK
* src/GrampsCfg.py: Don't do initial redisplay of Person List when
dialog comes up, update dates dynamically when date format changes
2005-01-12 Martin Hawlisch <Martin.Hawlisch@gmx.de>
* src/DisplayModels.py: Add Date and Place columns to Media model;
Zip to Place model.

View File

@ -31,24 +31,8 @@ __version__ = "$Revision$"
import Date
import locale
class DateDisplay:
"""
U.S English date display class.
"""
formats = (
"YYYY-MM-DD (ISO)", "Numerical", "Month Day, Year",
"MON DAY, YEAR", "Day Month Year", "DAY MON YEAR"
)
calendar = (
""," (Julian)"," (Hebrew)"," (French Republican)",
" (Persian)"," (Islamic)"
)
_mod_str = ("","before ","after ","about ","","","")
_qual_str = ("","estimated ","calculated ")
# determine the code set returned by nl_langinfo
_codeset = locale.nl_langinfo(locale.CODESET)
@ -117,6 +101,104 @@ class DateDisplay:
"Ramadan", "Shawwal", "Dhu l-Qa`da", "Dhu l-Hijja"
)
formats = ("YYYY-MM-DD (ISO)",)
calendar = (
""," (Julian)"," (Hebrew)"," (French Republican)",
" (Persian)"," (Islamic)"
)
_mod_str = ("","before ","after ","about ","","","")
_qual_str = ("","estimated ","calculated ")
def __init__(self,format=None):
pass
def set_format(self,format):
pass
def verify_format(self,format):
pass
def quote_display(self,date):
"""
Similar to the display task, except that if the value is a text only
value, it is enclosed in quotes.
"""
if date.get_modifier() == Date.MOD_TEXTONLY:
return '"%s"' % self.display(date)
else:
return self.display(date)
def display(self,date):
"""
Returns a text string representing the date.
"""
mod = date.get_modifier()
cal = date.get_calendar()
qual = date.get_quality()
start = date.get_start_date()
qual_str = self._qual_str[qual]
if mod == Date.MOD_TEXTONLY:
return date.get_text()
elif start == Date.EMPTY:
return ""
elif mod == Date.MOD_SPAN or mod == Date.MOD_RANGE:
d1 = self.display_iso(start)
d2 = self.display_iso(date.get_stop_date())
return "%s %s - %s%s" % (qual_str,d1,d2,self.calendar[cal])
elif mod == Date.MOD_RANGE:
d1 = self.display_iso(start)
d2 = self.display_cal[cal](date.get_stop_date())
return "%s %s - %s%s" % (qual_str,d1,d2,self.calendar[cal])
else:
text = self.display_iso(start)
return "%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal])
def _slash_year(self,val,slash):
bc = ""
if val < 0:
val = - val
bc = " B.C.E"
if slash:
return "%d/%d%s" % (val,(val%10)+1,bc)
else:
return "%d%s" % (val,bc)
def display_iso(self,date_val):
# YYYY-MM-DD (ISO)
year = self._slash_year(date_val[2],date_val[3])
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s-%02d" % (year,date_val[1])
else:
value = "%s-%02d-%02d" % (year,date_val[1],date_val[0])
return value
def text_display(self,date):
"""
Similar to the display task, except that if the value is a text only
value, it is enclosed in quotes.
"""
return date.get_text()
class DateDisplayEn(DateDisplay):
"""
English language date display class.
"""
formats = (
"YYYY-MM-DD (ISO)", "Numerical", "Month Day, Year",
"MON DAY, YEAR", "Day Month Year", "DAY MON YEAR"
)
def __init__(self,format=None):
"""
Creates a DateDisplay class that converts a Date object to a string
@ -142,30 +224,6 @@ class DateDisplay:
def set_format(self,format):
self.format = format
def verify_format(self,format):
"""
Verifies that the format value is within the correct range.
"""
pass
#assert(format < len(self.formats)-1)
def quote_display(self,date):
"""
Similar to the display task, except that if the value is a text only
value, it is enclosed in quotes.
"""
if date.get_modifier() == Date.MOD_TEXTONLY:
return '"%s"' % self.display(date)
else:
return self.display(date)
def text_display(self,date):
"""
Similar to the display task, except that if the value is a text only
value, it is enclosed in quotes.
"""
return date.get_text()
def display(self,date):
"""
Returns a text string representing the date.
@ -193,28 +251,10 @@ class DateDisplay:
text = self.display_cal[date.get_calendar()](start)
return "%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal])
def _slash_year(self,val,slash):
bc = ""
if val < 0:
val = - val
bc = " B.C.E"
if slash:
return "%d/%d%s" % (val,(val%10)+1,bc)
else:
return "%d%s" % (val,bc)
def _display_gregorian(self,date_val):
year = self._slash_year(date_val[2],date_val[3])
if self.format == 0:
# YYYY-MM-DD (ISO)
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = "%s-%02d" % (year,date_val[1])
else:
value = "%s-%02d-%02d" % (year,date_val[1],date_val[0])
value = self.display_iso(date_val)
elif self.format == 1:
if date_val[0] == 0 and date_val[1] == 0:
value = str(date_val[2])
@ -267,14 +307,7 @@ class DateDisplay:
def _display_calendar(self,date_val,month_list):
year = date_val[2]
if self.format == 0 or self.format == 1:
# YYYY-MM-DD (ISO)
if date_val[0] == 0:
if date_val[1] == 0:
return year
else:
return "%d-%d" % (year,date_val[1])
else:
return "%d-%d-%d" % (year,date_val[1],date_val[0])
return self.display_iso(date_val)
else:
if date_val[0] == 0:
if date_val[1] == 0:

View File

@ -58,13 +58,19 @@ _lang_to_parser = {
}
_lang_to_display = {
'C' : DateDisplay.DateDisplay,
'en_US' : DateDisplay.DateDisplay,
'en_GB' : DateDisplay.DateDisplay,
'en_AU' : DateDisplay.DateDisplay,
'en_CA' : DateDisplay.DateDisplay,
'en_SE' : DateDisplay.DateDisplay,
'en' : DateDisplay.DateDisplay,
'C' : DateDisplay.DateDisplayEn,
'en_US' : DateDisplay.DateDisplayEn,
'en_GB' : DateDisplay.DateDisplayEn,
'en_AU' : DateDisplay.DateDisplayEn,
'en_CA' : DateDisplay.DateDisplayEn,
'en_SE' : DateDisplay.DateDisplayEn,
'en' : DateDisplay.DateDisplayEn,
'zh_CN' : DateDisplay.DateDisplay,
'zh_TW' : DateDisplay.DateDisplay,
'zh_SG' : DateDisplay.DateDisplay,
'zh_HK' : DateDisplay.DateDisplay,
'ja_JP' : DateDisplay.DateDisplay,
'ko_KR' : DateDisplay.DateDisplay,
}
def get_date_formats():
@ -78,7 +84,7 @@ def get_date_formats():
def set_format(value):
try:
_lang_to_display[_lang].set_format(value)
displayer.set_format(value)
except:
pass

View File

@ -85,6 +85,11 @@ def set_calendar_date_format():
format_list = DateHandler.get_date_formats()
DateHandler.set_format(GrampsKeys.get_date_format(format_list))
def _update_calendar_date_format(active,dlist):
GrampsKeys.save_date_format(active,dlist)
format_list = DateHandler.get_date_formats()
DateHandler.set_format(active)
#-------------------------------------------------------------------------
#
# make_path -
@ -273,11 +278,6 @@ class GrampsPreferences:
store.append(row=[item])
date_option.set_model(store)
date_option.connect("changed",
lambda obj:
GrampsKeys.save_date_format(obj.get_active(),dlist)
)
try:
# Technically, a selected format might be out of range
# for this locale's format list.
@ -285,6 +285,10 @@ class GrampsPreferences:
except:
date_option.set_active(0)
date_option.connect("changed",
lambda obj:
_update_calendar_date_format(obj.get_active(),dlist)
)
resname = self.top.get_widget("resname")
resname.set_text(GrampsKeys.get_researcher_name())