~onboard/onboard/trunk

« back to all changes in this revision

Viewing changes to Onboard/UnicodeData.py

  • Committer: marmuta
  • Date: 2017-02-10 10:33:11 UTC
  • mto: This revision was merged to the branch mainline in revision 2275.
  • Revision ID: marmvta@gmail.com-20170210103311-vthzd1ao0pg3vv9b
Initial emoji & symbol palette for Compact layout.

Not quite complete yet, but usable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
# Copyright © 2017 marmuta <marmvta@gmail.com>
 
5
#
 
6
# This file is part of Onboard.
 
7
#
 
8
# Onboard is free software; you can redistribute it and/or modify
 
9
# it under the terms of the GNU General Public License as published by
 
10
# the Free Software Foundation; either version 3 of the License, or
 
11
# (at your option) any later version.
 
12
#
 
13
# Onboard is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
20
 
 
21
from Onboard.emoji_data import emoji_data
 
22
 
 
23
 
 
24
class UnicodeData:
 
25
    """
 
26
    Singleton class providing emoji data and general Unicode information.
 
27
    """
 
28
 
 
29
    _symbol_data = [
 
30
        ["α", "αβγδεζηθικλμνξοπρςστυφχψω"        # Greek
 
31
              "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ"],
 
32
 
 
33
        ["ℝ", "ℝℂℕℙℚℤ"                           # math & physics
 
34
              "∅∃∄∈∉∀∑∥∦∡⊾∞"
 
35
              "∩∪⊂⊃⊄⊅⊈⊉⊆⊇…"
 
36
              "≤≥≦≧≨≩"
 
37
              "≁≂≃≄≅≆≇≈≉≊≋≌≍"
 
38
              "√∛∜"
 
39
              "∫∬∭"
 
40
              "℃℉№"
 
41
         ],
 
42
        ["€", "$₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵₶₷₸₹₺₻₼₽₾"   # currency
 
43
              ""
 
44
         ],
 
45
        ["²₂", "⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾"                 # super- and subscript
 
46
               "ⁱ"
 
47
               "₀₁₂₃₄₅₆₇₈₉₊₋₌₍₎"
 
48
               "ₐₑₒₓₔₕₖₗₘₙₚₛₜ"
 
49
         ],
 
50
    ]
 
51
 
 
52
    def __new__(cls, *args, **kwargs):
 
53
        """
 
54
        Singleton magic.
 
55
        """
 
56
        if not hasattr(cls, "self"):
 
57
            cls.self = object.__new__(cls, *args, **kwargs)
 
58
            cls.self.construct()
 
59
        return cls.self
 
60
 
 
61
    def __init__(self):
 
62
        """
 
63
        Called multiple times, don't use this.
 
64
        """
 
65
        pass
 
66
 
 
67
    def construct(self):
 
68
        """
 
69
        Singleton constructor, runs only once.
 
70
        """
 
71
        pass
 
72
 
 
73
    def cleanup(self):
 
74
        pass
 
75
 
 
76
    def get_emoji_categories(self):
 
77
        return [label for label, data in self._get_emoji_data()]
 
78
 
 
79
    def get_emoji(self, category):
 
80
        return tuple(sequence
 
81
                     for sequence, data in self._get_emoji_data()[category][1])
 
82
 
 
83
    def _get_emoji_data(self):
 
84
        return emoji_data
 
85
 
 
86
    def get_symbol_categories(self):
 
87
        return [label for label, data in self._get_symbol_data()]
 
88
 
 
89
    def get_symbols(self, category):
 
90
        return tuple(self._get_symbol_data()[category][1])
 
91
 
 
92
    def _get_symbol_data(self):
 
93
        return self._symbol_data
 
94
 
 
95