1#
2# Gramps - a GTK+/GNOME based genealogy program
3#
4# Copyright (C) 2000-2007  Donald N. Allingham
5# Copyright (C) 2015       Paul Franklin
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21
22"""
23Provide the different Attribute Types for Gramps.
24"""
25
26#-------------------------------------------------------------------------
27#
28# Gramps modules
29#
30#-------------------------------------------------------------------------
31from .grampstype import GrampsType
32from ..const import GRAMPS_LOCALE as glocale
33_ = glocale.translation.gettext
34
35# _T_ is a gramps-defined keyword -- see po/update_po.py and po/genpot.sh
36def _T_(value): # enable deferred translations (see Python docs 22.1.3.4)
37    return value
38
39class AttributeType(GrampsType):
40
41    UNKNOWN = -1
42    CUSTOM = 0
43    CASTE = 1
44    DESCRIPTION = 2
45    ID = 3
46    NATIONAL = 4
47    NUM_CHILD = 5
48    SSN = 6
49    NICKNAME = 7
50    CAUSE = 8
51    AGENCY = 9
52    AGE = 10
53    FATHER_AGE = 11
54    MOTHER_AGE = 12
55    WITNESS = 13
56    TIME = 14
57    OCCUPATION = 15
58
59    _CUSTOM = CUSTOM
60    _DEFAULT = ID
61
62    _BASEMAP = [ # allow deferred translation of attribute UI strings
63        (UNKNOWN, _T_("Unknown"), "Unknown"),
64        (CUSTOM, _T_("Custom"), "Custom"),
65        (CASTE, _T_("Caste"), "Caste"),
66        (DESCRIPTION, _T_("Description"), "Description"),
67        (ID, _T_("Identification Number"), "Identification Number"),
68        (NATIONAL, _T_("National Origin"), "National Origin"),
69        (NUM_CHILD, _T_("Number of Children"), "Number of Children"),
70        (SSN, _T_("Social Security Number"), "Social Security Number"),
71        (NICKNAME, _T_("Nickname"), "Nickname"),
72        (CAUSE, _T_("Cause"), "Cause"),
73        (AGENCY, _T_("Agency"), "Agency"),
74        (AGE, _T_("Age"), "Age"),
75        (FATHER_AGE, _T_("Father's Age"), "Father Age"),
76        (MOTHER_AGE, _T_("Mother's Age"), "Mother Age"),
77        (WITNESS, _T_("Witness"), "Witness"),
78        (TIME, _T_("Time"), "Time"),
79        (OCCUPATION, _T_("Occupation"), "Occupation"),
80        ]
81
82    _DATAMAP = [(base[0], _(base[1]), base[2]) for base in _BASEMAP]
83
84    def __init__(self, value=None):
85        GrampsType.__init__(self, value)
86
87    def type2base(self):
88        """
89        Return the untranslated string suitable for UI (once translated).
90        """
91        if self.value == self.CUSTOM:
92            return str(self)
93        elif self._BASEMAP[self.value+1]: # UNKNOWN is before CUSTOM, sigh
94            return self._BASEMAP[self.value+1][1]
95        else:
96            return self.UNKNOWN
97