1#
2# Gramps - a GTK+/GNOME based genealogy program
3#
4# Copyright (C) 2015-      Serge Noiraud
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19#
20# https://en.wikipedia.org/wiki/Miscellaneous_Symbols
21# http://www.w3schools.com/charsets/ref_utf_symbols.asp
22#
23
24#-------------------------------------------------------------------------
25#
26# Standard python modules
27#
28#-------------------------------------------------------------------------
29from gramps.gen.const import GRAMPS_LOCALE as glocale
30_ = glocale.translation.sgettext
31
32# pylint: disable=superfluous-parens
33# pylint: disable=anomalous-unicode-escape-in-string
34
35class Symbols(object):
36    # genealogical symbols
37    SYMBOL_FEMALE                    = 0
38    SYMBOL_MALE                      = 1
39    SYMBOL_ASEXUAL_SEXLESS           = 2 # Unknown
40    SYMBOL_LESBIAN                   = 3
41    SYMBOL_MALE_HOMOSEXUAL           = 4
42    SYMBOL_HETEROSEXUAL              = 5
43    SYMBOL_HERMAPHRODITE             = 6
44    SYMBOL_TRANSGENDER               = 7
45    SYMBOL_NEUTER                    = 8
46
47    SYMBOL_ILLEGITIM                 = 9
48    SYMBOL_BIRTH                     = 10
49    SYMBOL_BAPTISM                   = 11 # CHRISTENING
50    SYMBOL_ENGAGED                   = 12
51    SYMBOL_MARRIAGE                  = 13
52    SYMBOL_DIVORCE                   = 14
53    SYMBOL_UNMARRIED_PARTNERSHIP     = 15
54    SYMBOL_BURIED                    = 16
55    SYMBOL_CREMATED                  = 17 # Funeral urn
56    SYMBOL_KILLED_IN_ACTION          = 18
57    SYMBOL_EXTINCT                   = 19
58
59    all_symbols = [
60               # Name                     UNICODE       SUBSTITUTION
61               (_("Female"),              '\u2640',     ""),
62               (_("Male"),                '\u2642',     ""),
63               (_("Asexuality, sexless, genderless"), '\u26aa', ""),
64               (_("Lesbianism"),          '\u26a2',     "oo"),
65               (_("Male homosexuality"),  '\u26a3',     "oo"),
66               (_("Heterosexuality"),     '\u26a4',     "oo"),
67               (_("Transgender, hermaphrodite (in entomology)"), '\u26a5', ""),
68               (_("Transgender"),         '\u26a6',     ""),
69               (_("Neuter"),              '\u26b2',     ""),
70
71               (_("Illegitimate"),        '\u229b',     ""),
72               (_("Birth"),               '\u002a',     "*"),
73               (_("Baptism/Christening"), '\u007e',     "~"),
74               (_("Engaged"),             '\u26ac',     "o"),
75               (_("Marriage"),            '\u26ad',     "oo"),
76               (_("Divorce"),             '\u26ae',     "o|o"),
77               (_("Unmarried partnership"), '\u26af',   "o-o"),
78               (_("Buried"),              '\u26b0',     "d"),
79               (_("Cremated/Funeral urn"), '\u26b1',    "d"),
80               (_("Killed in action"),    '\u2694',     "d"),
81               (_("Extinct"),             '\u2021',     ""),
82              ]
83
84    # genealogical death symbols
85    DEATH_SYMBOL_NONE                      = 0
86    DEATH_SYMBOL_X                         = 1
87    DEATH_SYMBOL_SKULL                     = 2
88    DEATH_SYMBOL_ANKH                      = 3
89    DEATH_SYMBOL_ORTHODOX_CROSS            = 4
90    DEATH_SYMBOL_CHI_RHO                   = 5
91    DEATH_SYMBOL_LORRAINE_CROSS            = 6
92    DEATH_SYMBOL_JERUSALEM_CROSS           = 7
93    DEATH_SYMBOL_STAR_CRESCENT             = 8
94    DEATH_SYMBOL_WEST_SYRIAC_CROSS         = 9
95    DEATH_SYMBOL_EAST_SYRIAC_CROSS         = 10
96    DEATH_SYMBOL_HEAVY_GREEK_CROSS         = 11
97    DEATH_SYMBOL_LATIN_CROSS               = 12
98    DEATH_SYMBOL_SHADOWED_LATIN_CROSS      = 13
99    DEATH_SYMBOL_MALTESE_CROSS             = 14
100    DEATH_SYMBOL_STAR_OF_DAVID             = 15
101    DEATH_SYMBOL_DEAD                      = 16
102
103    # The following is used in the global preferences in the display tab.
104    #                Name
105    #                                                  UNICODE    SUBSTITUTION
106    death_symbols = [(_("Nothing"),                    "",        ""),
107                     ("x",                             "x",       "x"),
108                     (_("Skull and crossbones"),       "\u2620",  "+"),
109                     (_("Ankh"),                       "\u2625",  "+"),
110                     (_("Orthodox cross"),             "\u2626",  "+"),
111                     (_("Chi rho"),                    "\u2627",  "+"),
112                     (_("Cross of Lorraine"),          "\u2628",  "+"),
113                     (_("Cross of Jerusalem"),         "\u2629",  "+"),
114                     (_("Star and crescent"),          "\u262a",  "+"),
115                     (_("West Syriac cross"),          "\u2670",  "+"),
116                     (_("East Syriac cross"),          "\u2671",  "+"),
117                     (_("Heavy Greek cross"),          "\u271a",  "+"),
118                     (_("Latin cross"),                "\u271d",  "+"),
119                     (_("Shadowed White Latin cross"), "\u271e",  "+"),
120                     (_("Maltese cross"),              "\u2720",  "+"),
121                     (_("Star of David"),              "\u2721",  "+"),
122                     (_("Dead"),                       _("Dead"), _("Dead"))
123                ]
124
125    def __init__(self):
126        self.symbols = None
127    #
128    # functions for general symbols
129    #
130    def get_symbol_for_html(self, symbol):
131        """ return the html string like '⚪' """
132        return '&#%d;' % ord(self.all_symbols[symbol][1])
133
134    def get_symbol_name(self, symbol):
135        """
136        Return the name of the symbol.
137        """
138        return self.all_symbols[symbol][0]
139
140    def get_symbol_for_string(self, symbol):
141        """ return the utf-8 character like '\u2670' """
142        return self.all_symbols[symbol][1]
143
144    def get_symbol_fallback(self, symbol):
145        """
146        Return the replacement string.
147        This is used if the utf-8 symbol in not present within a font.
148        """
149        return self.all_symbols[symbol][2]
150
151    #
152    # functions for death symbols
153    #
154    def get_death_symbols(self):
155        """
156        Return the list of death symbols.
157        This is used in the global preference to choose which symbol we'll use.
158        """
159        return self.death_symbols
160
161    def get_death_symbol_name(self, symbol):
162        """
163        Return the name of the symbol.
164        """
165        return self.death_symbols[symbol][0]
166
167    def get_death_symbol_for_html(self, symbol):
168        """
169        return the html string like '⚪'.
170        """
171        return '&#%d;' % ord(self.death_symbols[symbol][1])
172
173    def get_death_symbol_for_char(self, symbol):
174        """
175        Return the utf-8 character for the symbol.
176        """
177        return self.death_symbols[symbol][1]
178
179    def get_death_symbol_fallback(self, symbol):
180        """
181        Return the string replacement for the symbol.
182        """
183        return self.death_symbols[symbol][2]
184
185    #
186    # functions for all symbols
187    #
188    def get_how_many_symbols(self):
189        return len(self.death_symbols) + len(self.all_symbols) - 4
190