GEPS008: Create new module for string mappings
svn: r19917
This commit is contained in:
parent
b7d5b91535
commit
4209730bcb
@ -327,6 +327,7 @@ src/gen/utils/keyword.py
|
||||
src/gen/utils/lds.py
|
||||
src/gen/utils/name.py
|
||||
src/gen/utils/place.py
|
||||
src/gen/utils/string.py
|
||||
src/gen/utils/trans.py
|
||||
src/gen/utils/unknown.py
|
||||
|
||||
|
47
src/Utils.py
47
src/Utils.py
@ -31,12 +31,7 @@ Non GUI/GTK related utility functions
|
||||
# Standard python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import os
|
||||
import sys
|
||||
import locale
|
||||
import random
|
||||
import time
|
||||
import uuid
|
||||
import logging
|
||||
LOG = logging.getLogger(".")
|
||||
|
||||
@ -45,51 +40,14 @@ LOG = logging.getLogger(".")
|
||||
# Gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gen.display.name import displayer as name_displayer
|
||||
import gen.lib
|
||||
from gen.display.name import displayer as name_displayer
|
||||
from gen.datehandler import codeset
|
||||
from gen.config import config
|
||||
from const import GRAMPS_UUID
|
||||
from gen.constfunc import mac, win
|
||||
from gen.ggettext import sgettext as _
|
||||
from gen.utils.name import family_name
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Integer to String mappings for constants
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
gender = {
|
||||
gen.lib.Person.MALE : _("male"),
|
||||
gen.lib.Person.FEMALE : _("female"),
|
||||
gen.lib.Person.UNKNOWN : _("gender|unknown"),
|
||||
}
|
||||
|
||||
def format_gender( type):
|
||||
return gender.get(type[0], _("Invalid"))
|
||||
|
||||
confidence = {
|
||||
gen.lib.Citation.CONF_VERY_HIGH : _("Very High"),
|
||||
gen.lib.Citation.CONF_HIGH : _("High"),
|
||||
gen.lib.Citation.CONF_NORMAL : _("Normal"),
|
||||
gen.lib.Citation.CONF_LOW : _("Low"),
|
||||
gen.lib.Citation.CONF_VERY_LOW : _("Very Low"),
|
||||
}
|
||||
|
||||
family_rel_descriptions = {
|
||||
gen.lib.FamilyRelType.MARRIED : _("A legal or common-law relationship "
|
||||
"between a husband and wife"),
|
||||
gen.lib.FamilyRelType.UNMARRIED : _("No legal or common-law relationship "
|
||||
"between man and woman"),
|
||||
gen.lib.FamilyRelType.CIVIL_UNION : _("An established relationship between "
|
||||
"members of the same sex"),
|
||||
gen.lib.FamilyRelType.UNKNOWN : _("Unknown relationship between a man "
|
||||
"and woman"),
|
||||
gen.lib.FamilyRelType.CUSTOM : _("An unspecified relationship between "
|
||||
"a man and woman"),
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# modified flag
|
||||
@ -101,9 +59,6 @@ def history_broken():
|
||||
global _history_brokenFlag
|
||||
_history_brokenFlag = 1
|
||||
|
||||
data_recover_msg = _('The data can only be recovered by Undo operation '
|
||||
'or by quitting with abandoning changes.')
|
||||
|
||||
def fix_encoding(value, errors='strict'):
|
||||
# The errors argument specifies the response when the input string can't be
|
||||
# converted according to the encoding's rules. Legal values for this
|
||||
|
@ -29,7 +29,7 @@ Provide utilities for printing endnotes in text reports.
|
||||
from gen.plug.docgen import FontStyle, ParagraphStyle, FONT_SANS_SERIF
|
||||
from gen.lib import NoteType, Citation
|
||||
from gen.ggettext import gettext as _
|
||||
from Utils import confidence
|
||||
from gen.utils.string import confidence
|
||||
from gen.datehandler import displayer
|
||||
|
||||
def add_endnote_styles(style_sheet):
|
||||
|
@ -30,7 +30,7 @@ from types import NoneType
|
||||
|
||||
import gen.lib
|
||||
import gen.datehandler
|
||||
import Utils
|
||||
from gen.utils.string import gender as gender_map
|
||||
import gen.utils
|
||||
from gen.plug.report.utils import place_name
|
||||
|
||||
@ -195,7 +195,7 @@ class SimpleAccess(object):
|
||||
person = self.dbase.get_person_from_handle(person)
|
||||
assert(isinstance(person, (gen.lib.Person, NoneType)))
|
||||
if person:
|
||||
return Utils.gender[person.get_gender()]
|
||||
return gender_map[person.get_gender()]
|
||||
return u''
|
||||
|
||||
def __parent(self, person, func):
|
||||
|
@ -23,6 +23,7 @@ pkgpython_PYTHON = \
|
||||
mactrans.py \
|
||||
place.py \
|
||||
referent.py \
|
||||
string.py \
|
||||
trans.py \
|
||||
tree.py \
|
||||
unknown.py
|
||||
|
73
src/gen/utils/string.py
Normal file
73
src/gen/utils/string.py
Normal file
@ -0,0 +1,73 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2007 Donald N. Allingham
|
||||
# Copyright (C) 2009 Gary Burton
|
||||
# Copyright (C) 2011 Tim G L Lyons
|
||||
#
|
||||
# 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$
|
||||
|
||||
"""
|
||||
String mappings for constants
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gen.lib
|
||||
from gen.ggettext import sgettext as _
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Integer to String mappings for constants
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
gender = {
|
||||
gen.lib.Person.MALE : _("male"),
|
||||
gen.lib.Person.FEMALE : _("female"),
|
||||
gen.lib.Person.UNKNOWN : _("gender|unknown"),
|
||||
}
|
||||
|
||||
def format_gender( type):
|
||||
return gender.get(type[0], _("Invalid"))
|
||||
|
||||
confidence = {
|
||||
gen.lib.Citation.CONF_VERY_HIGH : _("Very High"),
|
||||
gen.lib.Citation.CONF_HIGH : _("High"),
|
||||
gen.lib.Citation.CONF_NORMAL : _("Normal"),
|
||||
gen.lib.Citation.CONF_LOW : _("Low"),
|
||||
gen.lib.Citation.CONF_VERY_LOW : _("Very Low"),
|
||||
}
|
||||
|
||||
family_rel_descriptions = {
|
||||
gen.lib.FamilyRelType.MARRIED : _("A legal or common-law relationship "
|
||||
"between a husband and wife"),
|
||||
gen.lib.FamilyRelType.UNMARRIED : _("No legal or common-law relationship "
|
||||
"between man and woman"),
|
||||
gen.lib.FamilyRelType.CIVIL_UNION : _("An established relationship between "
|
||||
"members of the same sex"),
|
||||
gen.lib.FamilyRelType.UNKNOWN : _("Unknown relationship between a man "
|
||||
"and woman"),
|
||||
gen.lib.FamilyRelType.CUSTOM : _("An unspecified relationship between "
|
||||
"a man and woman"),
|
||||
}
|
||||
|
||||
data_recover_msg = _('The data can only be recovered by Undo operation '
|
||||
'or by quitting with abandoning changes.')
|
@ -35,7 +35,7 @@ import cgi
|
||||
#-------------------------------------------------------------------------
|
||||
import gen.datehandler
|
||||
from gen.display.name import displayer as name_displayer
|
||||
import Utils
|
||||
from gen.utils.string import gender as gender_map
|
||||
import gen.lib
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
|
||||
@ -57,7 +57,7 @@ class ChildModel(gtk.ListStore):
|
||||
index + 1,
|
||||
child.get_gramps_id(),
|
||||
name_displayer.display(child),
|
||||
Utils.gender[child.get_gender()],
|
||||
gender_map[child.get_gender()],
|
||||
str(child_ref.get_father_relation()),
|
||||
str(child_ref.get_mother_relation()),
|
||||
self.column_birth_day(child),
|
||||
|
@ -69,7 +69,7 @@ from gui.autocomp import StandardCustomSelector, fill_entry
|
||||
from gui.selectors import SelectorFactory
|
||||
from gen.display.name import displayer as _nd
|
||||
from gen.utils.name import family_name
|
||||
import Utils
|
||||
from gen.utils.string import confidence
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -552,7 +552,7 @@ class EditRule(ManagedWindow):
|
||||
t = MyList(taglist, taglist)
|
||||
elif v == _('Confidence level:'):
|
||||
t = MyList(map(str, range(5)),
|
||||
[Utils.confidence[i] for i in range(5)])
|
||||
[confidence[i] for i in range(5)])
|
||||
else:
|
||||
t = MyEntry()
|
||||
tlist.append(t)
|
||||
|
@ -48,7 +48,7 @@ from gen.filters import GenericFilterFactory, rules
|
||||
from gen.filters.rules.citation import (RegExpIdOf, HasIdOf, HasCitation,
|
||||
HasNoteMatchingSubstringOf,
|
||||
HasNoteRegexp, MatchesFilter)
|
||||
from Utils import confidence
|
||||
from gen.utils.string import confidence
|
||||
GenericCitationFilter = GenericFilterFactory('Citation')
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
|
@ -35,7 +35,7 @@ import const
|
||||
from gui.display import display_help
|
||||
from gui.managedwindow import ManagedWindow
|
||||
import gen.datehandler
|
||||
from Utils import confidence
|
||||
from gen.utils.string import confidence
|
||||
from gen.merge import MergeCitationQuery
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
@ -59,6 +59,7 @@ from gui.filters import SearchBar
|
||||
from gui.utils import add_menuitem
|
||||
import const
|
||||
import Utils
|
||||
from gen.utils.string import data_recover_msg
|
||||
from gen.utils.file import get_unicode_path_from_file_chooser
|
||||
from gui.dialog import QuestionDialog, QuestionDialog2
|
||||
from gui.editors import FilterEditor
|
||||
@ -518,7 +519,7 @@ class ListView(NavigationView):
|
||||
else:
|
||||
msg = _('Deleting item will remove it from the database.')
|
||||
|
||||
msg += ' ' + Utils.data_recover_msg
|
||||
msg += ' ' + data_recover_msg
|
||||
#descr = object.get_description()
|
||||
#if descr == "":
|
||||
descr = object.get_gramps_id()
|
||||
|
@ -41,7 +41,7 @@ LOG = logging.getLogger(".citation")
|
||||
#-------------------------------------------------------------------------
|
||||
import gen.datehandler
|
||||
import gen.lib
|
||||
from Utils import confidence
|
||||
from gen.utils.string import confidence
|
||||
from gen.config import config
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
@ -52,7 +52,7 @@ LOG = logging.getLogger(".ExportCSV")
|
||||
import gen.lib
|
||||
from gen.lib.eventroletype import EventRoleType
|
||||
from gui.plug.export import WriterOptionBox
|
||||
import Utils
|
||||
from gen.utils.string import gender as gender_map
|
||||
import gen.datehandler
|
||||
from gui.glade import Glade
|
||||
|
||||
@ -366,11 +366,11 @@ class CSVWriter(object):
|
||||
callname = primary_name.get_call_name()
|
||||
gender = person.get_gender()
|
||||
if gender == gen.lib.Person.MALE:
|
||||
gender = Utils.gender[gen.lib.Person.MALE]
|
||||
gender = gender_map[gen.lib.Person.MALE]
|
||||
elif gender == gen.lib.Person.FEMALE:
|
||||
gender = Utils.gender[gen.lib.Person.FEMALE]
|
||||
gender = gender_map[gen.lib.Person.FEMALE]
|
||||
else:
|
||||
gender = Utils.gender[gen.lib.Person.UNKNOWN]
|
||||
gender = gender_map[gen.lib.Person.UNKNOWN]
|
||||
# Birth:
|
||||
birthdate = ""
|
||||
birthplace = ""
|
||||
|
@ -53,7 +53,7 @@ import gen.lib
|
||||
from gen.db import DbTxn
|
||||
from gen.plug.utils import OpenFileOrStdin
|
||||
from gen.datehandler import parser as _dp
|
||||
from Utils import gender as gender_map
|
||||
from gen.utils.string import gender as gender_map
|
||||
from gen.utils.id import create_id
|
||||
from gui.utils import ProgressMeter
|
||||
from gen.lib.eventroletype import EventRoleType
|
||||
|
@ -50,7 +50,7 @@ _LOG = logging.getLogger(".gui.personview")
|
||||
import gen.lib
|
||||
from gen.db import DbTxn
|
||||
from gui.views.listview import ListView
|
||||
import Utils
|
||||
from gen.utils.string import data_recover_msg
|
||||
from gen.display.name import displayer as name_displayer
|
||||
from gui.dialog import ErrorDialog, QuestionDialog
|
||||
from gen.errors import WindowActiveError
|
||||
@ -295,7 +295,7 @@ class BasePersonView(ListView):
|
||||
|
||||
msg = _('Deleting the person will remove the person '
|
||||
'from the database.')
|
||||
msg = "%s %s" % (msg, Utils.data_recover_msg)
|
||||
msg = "%s %s" % (msg, data_recover_msg)
|
||||
QuestionDialog(_('Delete %s?') % name,
|
||||
msg,
|
||||
_('_Delete Person'),
|
||||
|
@ -45,7 +45,7 @@ import gtk
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from Utils import confidence
|
||||
from gen.utils.string import confidence
|
||||
import const
|
||||
from gui.utils import ProgressMeter
|
||||
from gui.plug import tool
|
||||
|
@ -52,7 +52,7 @@ from gen.lib import StyledText, StyledTextTag, StyledTextTagType
|
||||
from gen.db import DbTxn
|
||||
import gen.mime
|
||||
from gui.plug import tool
|
||||
import Utils
|
||||
from gen.utils.string import confidence
|
||||
from gui.utils import ProgressMeter
|
||||
from gen.utils.lds import TEMPLES
|
||||
from gen.db.dbconst import *
|
||||
@ -1718,7 +1718,7 @@ class TestcaseGenerator(tool.BatchTool):
|
||||
#if randint(0,1) == 1:
|
||||
# (year, d) = self.rand_date( )
|
||||
# o.set_date_object( d)
|
||||
o.set_confidence_level(choice(Utils.confidence.keys()))
|
||||
o.set_confidence_level(choice(confidence.keys()))
|
||||
|
||||
if issubclass(o.__class__,gen.lib.tagbase.TagBase):
|
||||
if randint(0,1) == 1:
|
||||
|
@ -253,7 +253,7 @@ class FamilyView(ListView):
|
||||
|
||||
def remove(self, obj):
|
||||
from gui.dialog import QuestionDialog2
|
||||
from Utils import data_recover_msg
|
||||
from gen.utils.string import data_recover_msg
|
||||
msg = _('Deleting item will remove it from the database.')
|
||||
msg = msg + '\n' + data_recover_msg
|
||||
q = QuestionDialog2(_('Delete %s?') % _('family'), msg,
|
||||
|
@ -89,6 +89,7 @@ from gen.plug.report import utils as ReportUtils
|
||||
from gen.plug.report import MenuReportOptions
|
||||
|
||||
import Utils
|
||||
from gen.utils.string import confidence
|
||||
from gen.utils.file import media_path_full
|
||||
from gen.utils.referent import get_source_and_citation_referents
|
||||
from gen.constfunc import win
|
||||
@ -2290,13 +2291,13 @@ class BasePage(object):
|
||||
for key, sref in citation_ref_list:
|
||||
cit_ref_li = Html("li", id="sref%d%s" % (cindex, key))
|
||||
tmp = Html("ul")
|
||||
confidence = Utils.confidence.get(sref.confidence, _('Unknown'))
|
||||
if confidence == _('Normal'):
|
||||
confidence = None
|
||||
conf = confidence.get(sref.confidence, _('Unknown'))
|
||||
if conf == _('Normal'):
|
||||
conf = None
|
||||
for (label, data) in [
|
||||
[_("Date"), _dd.display(sref.date)],
|
||||
[_("Page"), sref.page],
|
||||
[_("Confidence"), confidence] ]:
|
||||
[_("Confidence"), conf] ]:
|
||||
if data:
|
||||
tmp += Html("li", "%s: %s" % (label, data))
|
||||
for handle in sref.get_note_list():
|
||||
|
Loading…
x
Reference in New Issue
Block a user