2007-10-15 Douglas S. Blank <dblank@cs.brynmawr.edu>
* src/plugins/WebCal.py: fixed a wrong indent level * src/plugins/Calendar.py: handle divorces, weekdays, easter, eval values in XML svn: r9191
This commit is contained in:
parent
8aaf924411
commit
f9606c4b03
@ -1,3 +1,7 @@
|
|||||||
|
2007-10-15 Douglas S. Blank <dblank@cs.brynmawr.edu>
|
||||||
|
* src/plugins/WebCal.py: fixed a wrong indent level
|
||||||
|
* src/plugins/Calendar.py: handle divorces, weekdays, easter, eval values in XML
|
||||||
|
|
||||||
2007-10-15 Brian Matherly <brian@gramps-project.org>
|
2007-10-15 Brian Matherly <brian@gramps-project.org>
|
||||||
* src/plugins/WebCal.py: Create directory if it doesn't exist.
|
* src/plugins/WebCal.py: Create directory if it doesn't exist.
|
||||||
|
|
||||||
|
@ -50,6 +50,38 @@ from FontScale import string_trim, string_width
|
|||||||
pt2cm = ReportUtils.pt2cm
|
pt2cm = ReportUtils.pt2cm
|
||||||
cm2pt = ReportUtils.cm2pt
|
cm2pt = ReportUtils.cm2pt
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Support functions
|
||||||
|
#
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
def easter(year):
|
||||||
|
"""
|
||||||
|
Computes the year/month/day of easter. Based on work by
|
||||||
|
J.-M. Oudin (1940) and is reprinted in the "Explanatory Supplement
|
||||||
|
to the Astronomical Almanac", ed. P. K. Seidelmann (1992). Note:
|
||||||
|
Ash Wednesday is 46 days before Easter Sunday.
|
||||||
|
"""
|
||||||
|
c = year / 100
|
||||||
|
n = year - 19 * (year / 19)
|
||||||
|
k = (c - 17) / 25
|
||||||
|
i = c - c / 4 - (c - k) / 3 + 19 * n + 15
|
||||||
|
i = i - 30 * (i / 30)
|
||||||
|
i = i - (i / 28) * (1 - (i / 28) * (29 / (i + 1))
|
||||||
|
* ((21 - n) / 11))
|
||||||
|
j = year + year / 4 + i + 2 - c + c / 4
|
||||||
|
j = j - 7 * (j / 7)
|
||||||
|
l = i - j
|
||||||
|
month = 3 + (l + 40) / 44
|
||||||
|
day = l + 28 - 31 * ( month / 4 )
|
||||||
|
return "%d/%d/%d" % (year, month, day)
|
||||||
|
|
||||||
|
def g2iso(dow):
|
||||||
|
""" Converst GRAMPS day of week to ISO day of week """
|
||||||
|
# GRAMPS: SUN = 1
|
||||||
|
# ISO: MON = 1
|
||||||
|
return (dow + 5) % 7 + 1
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Calendar
|
# Calendar
|
||||||
@ -192,15 +224,19 @@ class Calendar(Report):
|
|||||||
cell_height = (height - header)/ 6
|
cell_height = (height - header)/ 6
|
||||||
current_date = datetime.date(year, month, 1)
|
current_date = datetime.date(year, month, 1)
|
||||||
spacing = pt2cm(1.25 * ptext.get_font().get_size()) # 158
|
spacing = pt2cm(1.25 * ptext.get_font().get_size()) # 158
|
||||||
if current_date.isoweekday() != self.start_dow:
|
if current_date.isoweekday() != g2iso(self.start_dow + 1):
|
||||||
# Go back to previous first day of week, and start from there
|
# Go back to previous first day of week, and start from there
|
||||||
current_ord = current_date.toordinal() - ( (current_date.isoweekday() + 7) - self.start_dow ) % 7
|
current_ord = (current_date.toordinal() -
|
||||||
|
((current_date.isoweekday() + 7) -
|
||||||
|
g2iso(self.start_dow + 1) ) % 7)
|
||||||
else:
|
else:
|
||||||
current_ord = current_date.toordinal()
|
current_ord = current_date.toordinal()
|
||||||
for day_col in range(7):
|
for day_col in range(7):
|
||||||
font_height = pt2cm(pdaynames.get_font().get_size())
|
font_height = pt2cm(pdaynames.get_font().get_size())
|
||||||
self.doc.center_text("CAL-Daynames",
|
self.doc.center_text("CAL-Daynames",
|
||||||
GrampsLocale.long_days[(day_col+self.start_dow) % 7 + 1],
|
GrampsLocale.long_days[(day_col+
|
||||||
|
g2iso(self.start_dow + 1))
|
||||||
|
% 7 + 1],
|
||||||
day_col * cell_width + cell_width/2,
|
day_col * cell_width + cell_width/2,
|
||||||
header - font_height * 1.5)
|
header - font_height * 1.5)
|
||||||
for week_row in range(6):
|
for week_row in range(6):
|
||||||
@ -301,20 +337,33 @@ class Calendar(Report):
|
|||||||
if self.alive:
|
if self.alive:
|
||||||
if not probably_alive(spouse, self.database, self.year):
|
if not probably_alive(spouse, self.database, self.year):
|
||||||
continue
|
continue
|
||||||
|
# TEMP: this will hanlde ordered events
|
||||||
|
# GRAMPS 3.0 will have a new mechanism for start/stop events
|
||||||
|
are_married = None
|
||||||
for event_ref in fam.get_event_ref_list():
|
for event_ref in fam.get_event_ref_list():
|
||||||
event = self.database.get_event_from_handle(event_ref.ref)
|
event = self.database.get_event_from_handle(event_ref.ref)
|
||||||
event_obj = event.get_date_object()
|
if int(event.get_type()) in [gen.lib.EventType.MARRIAGE,
|
||||||
year = event_obj.get_year()
|
gen.lib.EventType.MARR_ALT]:
|
||||||
month = event_obj.get_month()
|
are_married = event
|
||||||
day = event_obj.get_day()
|
elif int(event.get_type()) in [gen.lib.EventType.DIVORCE,
|
||||||
years = self.year - year
|
gen.lib.EventType.ANNULMENT,
|
||||||
if years >= 0:
|
gen.lib.EventType.DIV_FILING]:
|
||||||
text = _("%(spouse)s and\n %(person)s, %(nyears)d") % {
|
are_married = None
|
||||||
'spouse' : spouse_name,
|
if are_married != None:
|
||||||
'person' : short_name,
|
for event_ref in fam.get_event_ref_list():
|
||||||
'nyears' : years,
|
event = self.database.get_event_from_handle(event_ref.ref)
|
||||||
}
|
event_obj = event.get_date_object()
|
||||||
self.add_day_item(text, year, month, day)
|
year = event_obj.get_year()
|
||||||
|
month = event_obj.get_month()
|
||||||
|
day = event_obj.get_day()
|
||||||
|
years = self.year - year
|
||||||
|
if years >= 0:
|
||||||
|
text = _("%(spouse)s and\n %(person)s, %(nyears)d") % {
|
||||||
|
'spouse' : spouse_name,
|
||||||
|
'person' : short_name,
|
||||||
|
'nyears' : years,
|
||||||
|
}
|
||||||
|
self.add_day_item(text, year, month, day)
|
||||||
|
|
||||||
class CalendarReport(Calendar):
|
class CalendarReport(Calendar):
|
||||||
""" The Calendar text report """
|
""" The Calendar text report """
|
||||||
@ -684,6 +733,10 @@ class Holidays:
|
|||||||
else:
|
else:
|
||||||
# must be a dayname
|
# must be a dayname
|
||||||
offset = rule["offset"]
|
offset = rule["offset"]
|
||||||
|
if len(rule["value"]) > 0 and rule["value"][0] == '&':
|
||||||
|
# eval exp -> year/num[/day[/month]]
|
||||||
|
y, m, d = date.year, date.month, date.day
|
||||||
|
rule["value"] = eval(rule["value"][1:])
|
||||||
if rule["value"].count("/") == 3: # year/num/day/month, "3rd wednesday in april"
|
if rule["value"].count("/") == 3: # year/num/day/month, "3rd wednesday in april"
|
||||||
y, num, dayname, mon = rule["value"].split("/")
|
y, num, dayname, mon = rule["value"].split("/")
|
||||||
if y == "*":
|
if y == "*":
|
||||||
|
@ -641,10 +641,10 @@ class WebReport(Report):
|
|||||||
married = True
|
married = True
|
||||||
for event_ref in fam.get_event_ref_list():
|
for event_ref in fam.get_event_ref_list():
|
||||||
event = self.database.get_event_from_handle(event_ref.ref)
|
event = self.database.get_event_from_handle(event_ref.ref)
|
||||||
if event and int(event.get_type()) in [gen.lib.EventType.DIVORCE,
|
if event and int(event.get_type()) in [gen.lib.EventType.DIVORCE,
|
||||||
gen.lib.EventType.ANNULMENT,
|
gen.lib.EventType.ANNULMENT,
|
||||||
gen.lib.EventType.DIV_FILING]:
|
gen.lib.EventType.DIV_FILING]:
|
||||||
married = False
|
married = False
|
||||||
if married:
|
if married:
|
||||||
for event_ref in fam.get_event_ref_list():
|
for event_ref in fam.get_event_ref_list():
|
||||||
event = self.database.get_event_from_handle(event_ref.ref)
|
event = self.database.get_event_from_handle(event_ref.ref)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user