diff --git a/ChangeLog b/ChangeLog index d2d72cbdf..c9c38f922 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,11 @@ 2006-05-14 Alex Roitman + * src/DateHandler/__init__.py: Proper import sequence. + * src/DateHandler/_DateHandler.py: Split into parts. + * src/DateHandler/_DateUtils.py: Add new file. + * src/DateHandler/_Date_sk.py: Bring to the new module structure. + * src/DateHandler/Makefile.am (pkgdata_PYTHON): Ship new file. + * src/GrampsDb/_ReadGedcom.py: Import from proper module. + * src/plugins/ChangeTypes.py (init_gui): Work around intltool bug. * src/plugins/Summary.py: Set titles properly. * src/plugins/CountAncestors.py: Add window title, remove extra text. diff --git a/src/DateHandler/Makefile.am b/src/DateHandler/Makefile.am index bcf738be3..d24d1246d 100644 --- a/src/DateHandler/Makefile.am +++ b/src/DateHandler/Makefile.am @@ -18,6 +18,7 @@ pkgdata_PYTHON = \ _DateDisplay.py\ _DateParser.py\ _DateHandler.py\ + _DateUtils.py\ __init__.py pkgpyexecdir = @pkgpyexecdir@/DateHandler diff --git a/src/DateHandler/_DateHandler.py b/src/DateHandler/_DateHandler.py index 7acc0d0fe..6fea36127 100644 --- a/src/DateHandler/_DateHandler.py +++ b/src/DateHandler/_DateHandler.py @@ -26,10 +26,9 @@ Class handling language-specific selection for date parser and displayer. #------------------------------------------------------------------------- # -# Standard python modules +# Python modules # #------------------------------------------------------------------------- -import os import locale #------------------------------------------------------------------------- @@ -75,21 +74,6 @@ _lang_to_display = { 'ko_KR' : DateDisplay, } -def get_date_formats(): - """ - Returns the lists supported formats for date parsers and displayers - """ - try: - return _lang_to_display[_lang].formats - except: - return _lang_to_display["C"].formats - -def set_format(value): - try: - displayer.set_format(value) - except: - pass - def register_datehandler(locales,parse_class,display_class): """ Registers the passed date parser class and date displayer @@ -107,80 +91,3 @@ def register_datehandler(locales,parse_class,display_class): for lang_str in locales: _lang_to_parser[lang_str] = parse_class _lang_to_display[lang_str] = display_class - -#------------------------------------------------------------------------- -# -# Initialize global parser -# -#------------------------------------------------------------------------- - -try: - if _lang_to_parser.has_key(_lang): - parser = _lang_to_parser[_lang]() - else: - parser = _lang_to_parser[_lang_short]() -except: - print "Date parser for",_lang,"not available, using default" - parser = _lang_to_parser["C"]() - -try: - import Config - val = Config.get_date_format(_lang_to_display[_lang].formats) -except: - try: - val = Config.get_date_format(_lang_to_display["C"].formats) - except: - val = 0 - -try: - if _lang_to_display.has_key(_lang): - displayer = _lang_to_display[_lang](val) - else: - displayer = _lang_to_display[_lang_short](val) -except: - print "Date displayer for",_lang,"not available, using default" - displayer = _lang_to_display["C"](val) - - -#-------------------------------------------------------------- -# -# Convenience functions -# -#-------------------------------------------------------------- - -def set_date(date_base, text) : - """ - Sets the date of the DateBase instance. - - The date is parsed into a L{Date} instance. - - @param date: String representation of a date. The locale specific - L{DateParser} is used to parse the string into a GRAMPS L{Date} - object. - @type date: str - """ - parser.set_date(date_base.get_date_object(),text) - -def get_date(date_base) : - """ - Returns a string representation of the date of the DateBase instance. - - This representation is based off the default date display format - determined by the locale's L{DateDisplay} instance. - @return: Returns a string representing the DateBase date - @rtype: str - """ - return displayer.display(date_base.get_date_object()) - -def get_quote_date(self) : - """ - Returns a string representation of the date of the DateBase instance. - - This representation is based off the default date display format - determined by the locale's L{DateDisplay} instance. The date is - enclosed in quotes if the L{Date} is not a valid date. - - @return: Returns a string representing the DateBase date - @rtype: str - """ - return displayer.quote_display(date_base.get_date_object()) diff --git a/src/DateHandler/_DateUtils.py b/src/DateHandler/_DateUtils.py new file mode 100644 index 000000000..ce4bf8848 --- /dev/null +++ b/src/DateHandler/_DateUtils.py @@ -0,0 +1,89 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2004-2006 Donald N. Allingham +# +# 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id: _DateHandler.py 6136 2006-03-11 04:58:58Z rshura $ + +""" +Class handling language-specific selection for date parser and displayer. +""" + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from DateHandler import _lang_to_display, _lang, parser, displayer + +#-------------------------------------------------------------- +# +# Convenience functions +# +#-------------------------------------------------------------- +def get_date_formats(): + """ + Returns the lists supported formats for date parsers and displayers + """ + try: + return _lang_to_display[_lang].formats + except: + return _lang_to_display["C"].formats + +def set_format(value): + try: + displayer.set_format(value) + except: + pass + +def set_date(date_base, text) : + """ + Sets the date of the DateBase instance. + + The date is parsed into a L{Date} instance. + + @param date: String representation of a date. The locale specific + L{DateParser} is used to parse the string into a GRAMPS L{Date} + object. + @type date: str + """ + parser.set_date(date_base.get_date_object(),text) + +def get_date(date_base) : + """ + Returns a string representation of the date of the DateBase instance. + + This representation is based off the default date display format + determined by the locale's L{DateDisplay} instance. + @return: Returns a string representing the DateBase date + @rtype: str + """ + return displayer.display(date_base.get_date_object()) + +def get_quote_date(date_base): + """ + Returns a string representation of the date of the DateBase instance. + + This representation is based off the default date display format + determined by the locale's L{DateDisplay} instance. The date is + enclosed in quotes if the L{Date} is not a valid date. + + @return: Returns a string representing the DateBase date + @rtype: str + """ + return displayer.quote_display(date_base.get_date_object()) diff --git a/src/DateHandler/_Date_sk.py b/src/DateHandler/_Date_sk.py index cec31ac20..4c5c5cb79 100644 --- a/src/DateHandler/_Date_sk.py +++ b/src/DateHandler/_Date_sk.py @@ -37,9 +37,10 @@ import re # GRAMPS modules # #------------------------------------------------------------------------- -import Date -from DateParser import DateParser -from DateDisplay import DateDisplay +from RelLib import Date +from _DateParser import DateParser +from _DateDisplay import DateDisplay +from _DateHandler import register_datehandler #------------------------------------------------------------------------- # @@ -145,5 +146,4 @@ class DateDisplaySK(DateDisplay): # Register classes # #------------------------------------------------------------------------- -from DateHandler import register_datehandler register_datehandler(('sk_SK','sk','SK'),DateParserSK, DateDisplaySK) diff --git a/src/DateHandler/__init__.py b/src/DateHandler/__init__.py index 288a2a93b..5de11561a 100644 --- a/src/DateHandler/__init__.py +++ b/src/DateHandler/__init__.py @@ -23,6 +23,12 @@ """ Class handling language-specific selection for date parser and displayer. """ + +# import prerequisites for localized handlers +from _DateHandler import _lang, _lang_short, \ + _lang_to_parser, _lang_to_display, register_datehandler + +# Import all the localized handlers import _Date_de import _Date_es import _Date_fi @@ -31,5 +37,37 @@ import _Date_lt import _Date_nl import _Date_ru import _Date_sv +import _Date_sk -from _DateHandler import * +# Initialize global parser +try: + if _lang_to_parser.has_key(_lang): + parser = _lang_to_parser[_lang]() + else: + parser = _lang_to_parser[_lang_short]() +except: + print "Date parser for",_lang,"not available, using default" + parser = _lang_to_parser["C"]() + +# Initialize global displayer +try: + import Config + val = Config.get_date_format(_lang_to_display[_lang].formats) +except: + try: + val = Config.get_date_format(_lang_to_display["C"].formats) + except: + val = 0 + +try: + if _lang_to_display.has_key(_lang): + displayer = _lang_to_display[_lang](val) + else: + displayer = _lang_to_display[_lang_short](val) +except: + print "Date displayer for",_lang,"not available, using default" + displayer = _lang_to_display["C"](val) + + +# Import utility functions +from _DateUtils import * diff --git a/src/GrampsDb/_ReadGedcom.py b/src/GrampsDb/_ReadGedcom.py index 03cdfe872..9adce0d7d 100644 --- a/src/GrampsDb/_ReadGedcom.py +++ b/src/GrampsDb/_ReadGedcom.py @@ -65,7 +65,7 @@ import gtk.glade #------------------------------------------------------------------------- import Errors import RelLib -from DateHandler import DateParser +from DateHandler._DateParser import DateParser import NameDisplay import Utils import Mime