From 7b80dfb4d20b46d51184c71410cead24871b136c Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 26 Dec 2004 17:43:22 +0000 Subject: [PATCH] * 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 --- gramps2/ChangeLog | 7 ++++++ gramps2/src/DateHandler.py | 47 ++++++++++++++++++++++++++++++------ gramps2/src/RelLib.py | 23 +++++++++++++++--- gramps2/src/dates/Date_es.py | 7 +++--- gramps2/src/dates/Date_fr.py | 6 ++--- gramps2/src/dates/Date_ru.py | 7 +++--- 6 files changed, 75 insertions(+), 22 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 118c858d7..d34fc8132 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,10 @@ +2004-12-26 Don Allingham + * 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 * src/RelLib.py: documentation improvements, move family relations constants from const.py.in diff --git a/gramps2/src/DateHandler.py b/gramps2/src/DateHandler.py index e26ada715..9303d622b 100644 --- a/gramps2/src/DateHandler.py +++ b/gramps2/src/DateHandler.py @@ -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 diff --git a/gramps2/src/RelLib.py b/gramps2/src/RelLib.py index fb82d8b70..4a9a8c920 100644 --- a/gramps2/src/RelLib.py +++ b/gramps2/src/RelLib.py @@ -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 diff --git a/gramps2/src/dates/Date_es.py b/gramps2/src/dates/Date_es.py index 04b20a982..cc47d13f7 100644 --- a/gramps2/src/dates/Date_es.py +++ b/gramps2/src/dates/Date_es.py @@ -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) + diff --git a/gramps2/src/dates/Date_fr.py b/gramps2/src/dates/Date_fr.py index 3ac6500aa..5ecde7dc4 100644 --- a/gramps2/src/dates/Date_fr.py +++ b/gramps2/src/dates/Date_fr.py @@ -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) diff --git a/gramps2/src/dates/Date_ru.py b/gramps2/src/dates/Date_ru.py index 9249af901..e35858ba8 100644 --- a/gramps2/src/dates/Date_ru.py +++ b/gramps2/src/dates/Date_ru.py @@ -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) +