* 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. svn: r6657
This commit is contained in:
parent
1000571a10
commit
a5e00e22ed
@ -1,4 +1,11 @@
|
||||
2006-05-14 Alex Roitman <shura@gramps-project.org>
|
||||
* 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.
|
||||
|
@ -18,6 +18,7 @@ pkgdata_PYTHON = \
|
||||
_DateDisplay.py\
|
||||
_DateParser.py\
|
||||
_DateHandler.py\
|
||||
_DateUtils.py\
|
||||
__init__.py
|
||||
|
||||
pkgpyexecdir = @pkgpyexecdir@/DateHandler
|
||||
|
@ -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())
|
||||
|
89
src/DateHandler/_DateUtils.py
Normal file
89
src/DateHandler/_DateUtils.py
Normal file
@ -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())
|
@ -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)
|
||||
|
@ -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 *
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user