* src/DateHandler.py: provide date handler registration function

* src/RelLib.py: more documentation
* src/dates/Date_es.py: use new registration function
* src/dates/Date_fr.py: use new registration function
* src/dates/Date_ru.py: use new registration function


svn: r3837
This commit is contained in:
Don Allingham 2004-12-26 17:43:22 +00:00
parent b7bb274409
commit 7b80dfb4d2
6 changed files with 75 additions and 22 deletions

View File

@ -1,3 +1,10 @@
2004-12-26 Don Allingham <dallingham@users.sourceforge.net>
* src/DateHandler.py: provide date handler registration function
* src/RelLib.py: more documentation
* src/dates/Date_es.py: use new registration function
* src/dates/Date_fr.py: use new registration function
* src/dates/Date_ru.py: use new registration function
2004-12-24 Don Allingham <dallingham@users.sourceforge.net>
* src/RelLib.py: documentation improvements, move family
relations constants from const.py.in

View File

@ -74,6 +74,14 @@ _lang_to_display = {
#
#-------------------------------------------------------------------------
def create_parser():
"""
Creates a new date parser class, based on the current locale.
@returns: DateParser class specific to the locale specific. If
no parser exists for the current locale, the English language
parser is returned.
@rtype: DateParser
"""
try:
return _lang_to_parser[_lang]()
except:
@ -81,6 +89,14 @@ def create_parser():
return DateParser.DateParser()
def create_display():
"""
Creates a new date displayer class, based on the current locale.
@returns: DateDisplay class specific to the locale specific. If
no parser exists for the current locale, the English language
parser is returned.
@rtype: DateDisplay
"""
try:
val = GrampsGconfKeys.get_date_format(_lang_to_display[_lang].formats)
return _lang_to_display[_lang](val)
@ -89,6 +105,9 @@ def create_display():
return DateDisplay.DateDisplay(3)
def get_date_formats():
"""
Returns the lists supported formats for date parsers and displayers
"""
try:
return _lang_to_display[_lang].formats
except:
@ -96,16 +115,28 @@ def get_date_formats():
def set_format(val):
try:
_lang_to_display[_lang].format = val
_lang_to_display[_lang].formats = val
except:
pass
def get_format():
try:
return _lang_to_display[_lang].format
except:
print "not found"
return 0
def register_datehandler(locales,parse_class,display_class):
"""
Registers the passed date parser class and date displayer
classes with the specfied language locales.
@param locales: tuple of strings containing language codes.
The character encoding is not included, so the langauge
should be in the form of fr_FR, not fr_FR.utf8
@type locales: tuple
@param parse_class: Class to be associated with parsing
@type parse_class: DateParse
@param display_class: Class to be associated with displaying
@type display_class: DateDisplay
"""
for lang_str in locales:
_lang_to_parser[lang_str] = parse_class
_lang_to_display[lang_str] = display_class
#-------------------------------------------------------------------------
#
@ -115,3 +146,5 @@ def get_format():
from Plugins import load_plugins
from const import datesDir
load_plugins(datesDir)
print _lang_to_display[_lang].formats

View File

@ -309,9 +309,26 @@ class DataObj(SourceNote):
class Person(PrimaryObject,SourceNote):
"""
GRAMPS Person record. This object represents an individual person.
It contains all the information about the person, including names,
events, attributes, and other information.
Introduction
============
The Person record is the GRAMPS in-memory representation of an
individual person. It contains all the information related to
an individual.
Usage
=====
Person objects are usually created in one of two ways.
1. Creating a new person object, which is then initialized and
added to the database.
2. Retrieving an object from the database using the records
handle.
Once a Person object has been modified, it must be committed
to the database using the database object's commit_person function,
or the changes will be lost.
@sort: serialize, unserialize, get_*, set_*, add_*, remove_*
"""
unknown = 2

View File

@ -151,7 +151,6 @@ class DateDisplayES(DateDisplay):
# Register classes
#
#-------------------------------------------------------------------------
from DateHandler import _lang_to_parser, _lang_to_display
for lang_str in ('es_ES','es_ES.iso88591','es_ES.utf8','spanish'):
_lang_to_parser[lang_str] = DateParserES
_lang_to_display[lang_str] = DateDisplayES
from DateHandler import add_format
register_datehandler(('es_ES','spanish'),DateParserES, DateDisplayES)

View File

@ -145,7 +145,5 @@ class DateDisplayFR(DateDisplay):
# Register classes
#
#-------------------------------------------------------------------------
from DateHandler import _lang_to_parser, _lang_to_display
for lang_str in ('fr_FR','fr_FR.iso88591','fr_FR.utf8','french'):
_lang_to_parser[lang_str] = DateParserFR
_lang_to_display[lang_str] = DateDisplayFR
from DateHandler import add_format
register_datehandler(('fr_FR','french'),DateParserFR, DateDisplayFR)

View File

@ -160,7 +160,6 @@ class DateDisplayRU(DateDisplay):
# Register classes
#
#-------------------------------------------------------------------------
from DateHandler import _lang_to_parser, _lang_to_display
for lang_str in ('ru_RU','ru_RU.koi8r','ru_RU.utf8','russian'):
_lang_to_parser[lang_str] = DateParserRU
_lang_to_display[lang_str] = DateDisplayRU
from DateHandler import add_format
register_datehandler(('ru_RU','russian'),DateParserRU, DateDisplayRU)