Committed same changes for NarrativeWeb and WebCal for Screen Readers and Braille writers.

svn: r15258
This commit is contained in:
Rob G. Healey 2010-04-22 01:31:51 +00:00
parent 13b5c5a524
commit 00b0412fee
2 changed files with 416 additions and 471 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,11 @@
# encoding: utf-8
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2007 Thom Sturgill # Copyright (C) 2007 Thom Sturgill
# Copyright (C) 2007-2009 Brian G. Matherly # Copyright (C) 2007-2009 Brian G. Matherly
# Copyright (C) 2008-2009 Rob G. Healey <robhealey1@gmail.com> # Copyright (C) 2008-2010 Rob G. Healey <robhealey1@gmail.com>
# Copyright (C) 2008 Jason Simanek # Copyright (C) 2008 Jason Simanek
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -25,14 +26,9 @@
""" """
Web Calendar generator. Web Calendar generator.
Refactoring. This is an ongoing job until this plugin is in a better shape.
""" """
from __future__ import with_statement
#------------------------------------------------------------------------ #------------------------------------------------------------------------
#
# python modules # python modules
#
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import os, codecs, shutil, re import os, codecs, shutil, re
import datetime, calendar import datetime, calendar
@ -41,19 +37,15 @@ from gen.ggettext import ngettext
from itertools import imap from itertools import imap
#------------------------------------------------------------------------ #------------------------------------------------------------------------
#
# Set up logging # Set up logging
#
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import logging import logging
log = logging.getLogger(".WebPage") log = logging.getLogger(".WebPage")
#------------------------------------------------------------------------ #------------------------------------------------------------------------
#
# GRAMPS module # GRAMPS module
#
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gen.lib import date, Date, Name, Person, NameType, EventType import gen.lib
import const import const
import constfunc import constfunc
from ReportBase import Report, ReportUtils, MenuReportOptions, CSS_FILES from ReportBase import Report, ReportUtils, MenuReportOptions, CSS_FILES
@ -67,7 +59,6 @@ from gui.utils import ProgressMeter
from DateHandler import displayer as _dd from DateHandler import displayer as _dd
from gen.display.name import displayer as _nd from gen.display.name import displayer as _nd
from DateHandler import displayer as _dd
import libholiday import libholiday
from libhtml import Html from libhtml import Html
@ -76,7 +67,6 @@ from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS
# import styled notes from # import styled notes from
# src/plugins/lib/libhtmlbackend.py # src/plugins/lib/libhtmlbackend.py
from libhtmlbackend import HtmlBackend from libhtmlbackend import HtmlBackend
import Utils
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# constants # constants
@ -151,7 +141,7 @@ class WebCalReport(Report):
self.email = researcher.email self.email = researcher.email
# set to today's date # set to today's date
self.today = date.Today() self.today = gen.lib.date.Today()
self.warn_dir = True # Only give warning once. self.warn_dir = True # Only give warning once.
@ -280,11 +270,11 @@ class WebCalReport(Report):
if month > 0: if month > 0:
try: try:
event_date = Date(year, month, day) event_date = gen.lib.Date(year, month, day)
except ValueError: except ValueError:
event_date = Date.EMPTY event_date = gen.lib.Date.EMPTY
else: else:
event_date = Date.EMPTY # Incomplete date.... event_date = gen.lib.Date.EMPTY # Incomplete date....
day_list.append((text, event, event_date)) day_list.append((text, event, event_date))
month_dict[day] = day_list month_dict[day] = day_list
@ -329,6 +319,11 @@ class WebCalReport(Report):
fname = os.path.join(const.DATA_DIR, self.css) fname = os.path.join(const.DATA_DIR, self.css)
self.copy_file(fname, _CALENDARSCREEN, "styles") self.copy_file(fname, _CALENDARSCREEN, "styles")
# copy Navigation Menu Layout if Blue or Visually is being used
if self.css == "Web_Basic-Blue.css" or "Web_Visually.css":
fname = os.path.join(const.DATA_DIR, "Web_Navigation-Horizontal.css")
self.copy_file(fname, "Web_Navigation-Menus.css", "styles")
# copy print stylesheet # copy print stylesheet
fname = os.path.join(const.DATA_DIR, "Web_Print-Default.css") fname = os.path.join(const.DATA_DIR, "Web_Print-Default.css")
self.copy_file(fname, _CALENDARPRINT, "styles") self.copy_file(fname, _CALENDARPRINT, "styles")
@ -389,7 +384,7 @@ class WebCalReport(Report):
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
# Beginning of Calendar Creation # Beginning of Calendar Creation
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
def write_header(self, nr_up, body_id, title, add_print=True): def write_header(self, nr_up, title, body_id = None, add_print = True):
""" """
This creates the header for the Calendars This creates the header for the Calendars
'nr_up' - number of directory levels up, started from current page, to the 'nr_up' - number of directory levels up, started from current page, to the
@ -410,6 +405,10 @@ class WebCalReport(Report):
page, head, body = Html.page(title, self.encoding, xmllang) page, head, body = Html.page(title, self.encoding, xmllang)
# add body id tag if not None
if body_id is not None:
body.attr = "id = '%(idtag)s'" % { 'idtag' : body_id }
# GRAMPS favicon # GRAMPS favicon
fname1 = os.path.join(subdirs, "images", "favicon.ico") fname1 = os.path.join(subdirs, "images", "favicon.ico")
@ -422,24 +421,25 @@ class WebCalReport(Report):
) )
# links for GRAMPS favicon and stylesheets # links for GRAMPS favicon and stylesheets
links = Html("link", rel='shortcut icon', href=fname1, links = Html("link", rel='shortcut icon', href=fname1, type = "image/x-icon") + (
type = "image/x-icon") + ( Html("link",rel="stylesheet", href=fname2, type="text/css", media= "screen", indent = False)
Html("link",rel="stylesheet", href=fname2, type="text/css", media= "screen",
indent = False)
) )
# add printer stylesheet to webcalendar() and one_day() only # add printer stylesheet to webcalendar() and one_day() only
if add_print: if add_print:
fname = os.path.join(subdirs, "styles", _CALENDARPRINT) fname = os.path.join(subdirs, "styles", _CALENDARPRINT)
links += Html("link",rel="stylesheet", href=fname,type="text/css", media="print", links += Html("link",rel="stylesheet", href=fname,type="text/css", media="print", indent = False)
indent = False)
# add horizontal menu if css == Blue or Visually because there is no menus
if self.css in ["Web_Basic-Blue.css", "Web_Visually.css"]:
# Link to Navigation Menus stylesheet
fname = os.path.join(subdirs, "styles", "Web_Navigation-Menus.css")
links.extend( Html("link", href = fname, type = "text/css", media = "screen", rel = "stylesheet") )
# add meta tags and links to head section # add meta tags and links to head section
head += (meta, links) head += (meta, links)
# replace standard body element with custom one
body.attr = 'id="%s"' % body_id
# start header division section # start header division section
header = Html("div", id="header") + ( header = Html("div", id="header") + (
@ -500,10 +500,11 @@ class WebCalReport(Report):
# Figure out if we need <li class="CurrentSection"> or just plain <li> # Figure out if we need <li class="CurrentSection"> or just plain <li>
cs = str(cal_year) == currentsection and 'class="CurrentSection"' or '' cs = str(cal_year) == currentsection and 'class="CurrentSection"' or ''
unordered += Html("li", attr=cs, inline = True) + ( unordered += Html("li", attr = cs, inline = True) + (
# create hyperlink # create hyperlink
Html("a", str(cal_year), href = url, title = "Year %04d" % cal_year, inline = True) Html("a", str(cal_year), href = url, title = _("Sub Navigation Menu Item: "
"Year %04d" % cal_year), inline = True)
) )
# return yearnav to its caller # return yearnav to its caller
@ -528,7 +529,9 @@ class WebCalReport(Report):
# An optional link to a home page # An optional link to a home page
navs.append((self.home_link, _('html|Home'), add_home)) navs.append((self.home_link, _('html|Home'), add_home))
navs.extend((month, month, True) for month in range(1,13)) navs.extend(
(month, month, True) for month in range(1,13)
)
# Add a link for year_glance() if requested # Add a link for year_glance() if requested
navs.append(('fullyearlinked', _('Year Glance'), self.fullyear)) navs.append(('fullyearlinked', _('Year Glance'), self.fullyear))
@ -570,7 +573,7 @@ class WebCalReport(Report):
unordered += Html("li", attr = cs, inline = True) + ( unordered += Html("li", attr = cs, inline = True) + (
# create hyperlink # create hyperlink
Html("a", nav_text, href = url, title=url_fname, inline = True) Html("a", nav_text, href = url, title = _("Main Navigation Menu Item: %s" % url_fname), inline = True)
) )
# return monthnav to its caller # return monthnav to its caller
@ -727,7 +730,7 @@ class WebCalReport(Report):
bday_anniv_list = self.calendar.get(month, {}).get(thisday.day, []) bday_anniv_list = self.calendar.get(month, {}).get(thisday.day, [])
# date is an instance because of subtracting abilities in date.py # date is an instance because of subtracting abilities in date.py
event_date = Date(thisday.year, thisday.month, thisday.day) event_date = gen.lib.Date(thisday.year, thisday.month, thisday.day)
# get events for this day # get events for this day
day_list = get_day_list(event_date, holiday_list, bday_anniv_list) day_list = get_day_list(event_date, holiday_list, bday_anniv_list)
@ -776,8 +779,8 @@ class WebCalReport(Report):
tcell += unordered tcell += unordered
for nyears, date, text, event in day_list: for nyears, date, text, event in day_list:
unordered += Html("li", text, inline = False if event == 'Anniversary' unordered += Html("li", text, inline = False
else True) if event == 'Anniversary' else True)
# no events for this day # no events for this day
else: else:
@ -839,13 +842,12 @@ class WebCalReport(Report):
for month in range(1, 13): for month in range(1, 13):
# Name the file, and create it
cal_fname = get_full_month_name(month) cal_fname = get_full_month_name(month)
of = self.create_file(cal_fname, str(year)) of = self.create_file(cal_fname, str(year))
# Add xml, doctype, meta and stylesheets # Add xml, doctype, meta and stylesheets
# body has already been added to webcal already once # body has already been added to webcal already once
webcal, body = self.write_header(nr_up, 'WebCal', self.title_text) webcal, body = self.write_header(nr_up, self.title_text)
# create Year Navigation menu # create Year Navigation menu
if (self.multiyear and ((self.end_year - self.start_year) > 0)): if (self.multiyear and ((self.end_year - self.start_year) > 0)):
@ -901,7 +903,6 @@ class WebCalReport(Report):
# generate progress pass for "Year At A Glance" # generate progress pass for "Year At A Glance"
self.progress.set_pass(_('Creating Year At A Glance calendar'), 12) self.progress.set_pass(_('Creating Year At A Glance calendar'), 12)
# Name the file, and create it
of = self.create_file('fullyearlinked', str(year)) of = self.create_file('fullyearlinked', str(year))
# page title # page title
@ -909,7 +910,7 @@ class WebCalReport(Report):
# Create page header # Create page header
# body has already been added to yearglance already once # body has already been added to yearglance already once
yearglance, body = self.write_header(nr_up, 'fullyearlinked', title, False) yearglance, body = self.write_header(nr_up, title, "fullyearlinked", False)
# create Year Navigation menu # create Year Navigation menu
if (self.multiyear and ((self.end_year - self.start_year) > 0)): if (self.multiyear and ((self.end_year - self.start_year) > 0)):
@ -971,14 +972,13 @@ class WebCalReport(Report):
year = event_date.get_year() year = event_date.get_year()
month = event_date.get_month() month = event_date.get_month()
# Name the file, and crate it (see code in calendar_build)
od = self.create_file(fname_date, str(year)) od = self.create_file(fname_date, str(year))
# page title # page title
title = _('One Day Within A Year') title = _('One Day Within A Year')
# create page header # create page header
oneday, body = self.write_header(nr_up, 'OneDay', title) oneday, body = self.write_header(nr_up, title, "OneDay")
# create Year Navigation menu # create Year Navigation menu
if (self.multiyear and ((self.end_year - self.start_year) > 0)): if (self.multiyear and ((self.end_year - self.start_year) > 0)):
@ -1063,19 +1063,19 @@ class WebCalReport(Report):
married_name = None married_name = None
names = [primary_name] + person.get_alternate_names() names = [primary_name] + person.get_alternate_names()
for name in names: for name in names:
if int(name.get_type()) == NameType.MARRIED: if int(name.get_type()) == gen.lib.NameType.MARRIED:
married_name = name married_name = name
break break
# Now, decide which to use: # Now, decide which to use:
if maiden_name is not None: if maiden_name is not None:
if married_name is not None: if married_name is not None:
name = Name(married_name) name = gen.lib.Name(married_name)
else: else:
name = Name(primary_name) name = gen.lib.Name(primary_name)
name.set_surname(maiden_name) name.set_surname(maiden_name)
else: else:
name = Name(primary_name) name = gen.lib.Name(primary_name)
name.set_display_as(self.name_format) name.set_display_as(self.name_format)
return _nd.display_name(name) return _nd.display_name(name)
@ -1099,14 +1099,13 @@ class WebCalReport(Report):
family_list = person.get_family_handle_list() family_list = person.get_family_handle_list()
birth_ref = person.get_birth_ref() birth_ref = person.get_birth_ref()
birth_date = Date.EMPTY birth_date = gen.lib.Date.EMPTY
if birth_ref: if birth_ref:
birth_event = db.get_event_from_handle(birth_ref.ref) birth_event = db.get_event_from_handle(birth_ref.ref)
birth_date = birth_event.get_date_object() birth_date = birth_event.get_date_object()
# determine birthday information??? # determine birthday information???
if (self.birthday and birth_date is not Date.EMPTY if (self.birthday and birth_date is not gen.lib.Date.EMPTY and birth_date.is_valid()):
and birth_date.is_valid()):
year = birth_date.get_year() or this_year year = birth_date.get_year() or this_year
month = birth_date.get_month() month = birth_date.get_month()
@ -1114,11 +1113,11 @@ class WebCalReport(Report):
# date to figure if someone is still alive # date to figure if someone is still alive
# current year of calendar, month nd day is their birth month and birth day # current year of calendar, month nd day is their birth month and birth day
prob_alive_date = Date(this_year, month, day) prob_alive_date = gen.lib.Date(this_year, month, day)
# add some things to handle maiden name: # add some things to handle maiden name:
father_surname = None # husband, actually father_surname = None # husband, actually
if person.gender == Person.FEMALE: if person.gender == gen.lib.Person.FEMALE:
# get husband's last name: # get husband's last name:
if self.maiden_name in ['spouse_first', 'spouse_last']: if self.maiden_name in ['spouse_first', 'spouse_last']:
@ -1134,7 +1133,8 @@ class WebCalReport(Report):
if father_handle: if father_handle:
father = db.get_person_from_handle(father_handle) father = db.get_person_from_handle(father_handle)
if father is not None: if father is not None:
father_surname = _get_regular_surname(person.gender, father.primary_name) father_surname = _get_regular_surname(person.gender,
father.get_primary_name())
short_name = self.get_name(person, father_surname) short_name = self.get_name(person, father_surname)
alive = probably_alive(person, db, prob_alive_date) alive = probably_alive(person, db, prob_alive_date)
if (self.alive and alive) or not self.alive: if (self.alive and alive) or not self.alive:
@ -1168,13 +1168,13 @@ class WebCalReport(Report):
marriage_event = get_marriage_event(db, fam) marriage_event = get_marriage_event(db, fam)
if marriage_event: if marriage_event:
event_date = marriage_event.get_date_object() event_date = marriage_event.get_date_object()
if event_date is not Date.EMPTY and event_date.is_valid(): if event_date is not gen.lib.Date.EMPTY and event_date.is_valid():
year = event_date.get_year() year = event_date.get_year()
month = event_date.get_month() month = event_date.get_month()
day = event_date.get_day() day = event_date.get_day()
# date to figure if someone is still alive # date to figure if someone is still alive
prob_alive_date = Date(this_year, month, day) prob_alive_date = gen.lib.Date(this_year, month, day)
if self.link_to_narweb: if self.link_to_narweb:
spouse_name = Html("a", spouse_name, spouse_name = Html("a", spouse_name,
@ -1209,7 +1209,8 @@ class WebCalReport(Report):
# Display date as user set in preferences # Display date as user set in preferences
msg = _('Generated by <a href="http://gramps-project.org">' msg = _('Generated by <a href="http://gramps-project.org">'
'Gramps</a> on %(date)s') % {'date' : _dd.display(date.Today())} 'Gramps</a> on %(date)s') % {'date' : _dd.display(
gen.lib.date.Today())}
footer += Html("p", msg, id = 'createdate') footer += Html("p", msg, id = 'createdate')
copy_nr = self.copy copy_nr = self.copy
@ -1384,7 +1385,7 @@ class WebCalOptions(MenuReportOptions):
css = EnumeratedListOption(_('StyleSheet'), CSS_FILES[0][1]) css = EnumeratedListOption(_('StyleSheet'), CSS_FILES[0][1])
for style in CSS_FILES: for style in CSS_FILES:
css.add_item(style[1], style[0]) css.add_item(style[1], style[0])
css.set_help( _('The Style Sheet to be used for the web page')) css.set_help( _('The stylesheet to be used for the web pages'))
menu.add_option(category_name, "css", css) menu.add_option(category_name, "css", css)
def __add_content_options(self, menu): def __add_content_options(self, menu):
@ -1394,7 +1395,7 @@ class WebCalOptions(MenuReportOptions):
category_name = _("Content Options") category_name = _("Content Options")
# set to today's date for use in menu, etc. # set to today's date for use in menu, etc.
today = date.Today() today = gen.lib.date.Today()
self.__multiyear = BooleanOption(_('Create multiple year calendars'), False) self.__multiyear = BooleanOption(_('Create multiple year calendars'), False)
self.__multiyear.set_help(_('Whether to create Multiple year calendars or not.')) self.__multiyear.set_help(_('Whether to create Multiple year calendars or not.'))
@ -1608,7 +1609,7 @@ def _get_regular_surname(sex, name):
prefix = name.get_surname_prefix() prefix = name.get_surname_prefix()
if prefix: if prefix:
surname = prefix + " " + surname surname = prefix + " " + surname
if sex is not Person.FEMALE: if sex is not gen.lib.Person.FEMALE:
suffix = name.get_suffix() suffix = name.get_suffix()
if suffix: if suffix:
surname = surname + ", " + suffix surname = surname + ", " + suffix
@ -1700,7 +1701,7 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
# birthday/ anniversary on this day # birthday/ anniversary on this day
# Date.EMPTY signifies an incomplete date for an event. See add_day_item() # Date.EMPTY signifies an incomplete date for an event. See add_day_item()
bday_anniv_list = [(t, e, d) for t, e, d in bday_anniv_list bday_anniv_list = [(t, e, d) for t, e, d in bday_anniv_list
if d != Date.EMPTY] if d != gen.lib.Date.EMPTY]
# number of years have to be at least zero # number of years have to be at least zero
bday_anniv_list = [(t, e, d) for t, e, d in bday_anniv_list bday_anniv_list = [(t, e, d) for t, e, d in bday_anniv_list