1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import copy
18
19 from libxyz.exceptions import XYZValueError
20
22 """
23 Base color
24 """
25
26 colors = {}
27 ctype = u"base"
28
30 if color not in self.colors:
31 raise XYZValueError(_(u"Invalid %s color: %s" % \
32 (self.ctype, str(color))))
33
34 self.color = self.colors[color]
35
36
37
39 return u"<%s color: %s>" % (self.ctype, str(self.color))
40
41
42
45
46
47
49 """
50 Foreground color
51 """
52
53 colors = {
54 u"BLACK": u"black",
55 u"BROWN": u"brown",
56 u"YELLOW": u"yellow",
57 u"WHITE": u"white",
58 u"DEFAULT": u"default",
59
60 u"DARK_BLUE": u"dark blue",
61 u"DARK_MAGENTA": u"dark magenta",
62 u"DARK_CYAN": u"dark cyan",
63 u"DARK_RED": u"dark red",
64 u"DARK_GREEN": u"dark green",
65 u"DARK_GRAY": u"dark gray",
66
67 u"LIGHT_GRAY": u"light gray",
68 u"LIGHT_RED": u"light red",
69 u"LIGHT_GREEN": u"light green",
70 u"LIGHT_BLUE": u"light blue",
71 u"LIGHT_MAGENTA": u"light magenta",
72 u"LIGHT_CYAN": u"light cyan",
73 }
74
75 ctype = u"foreground"
76
77
78
80 """
81 Background color
82 """
83
84 colors = {
85 u"BLACK": u"black",
86 u"BROWN": u"brown",
87 u"DEFAULT": u"default",
88
89 u"DARK_RED": u"dark red",
90 u"DARK_GREEN": u"dark green",
91 u"DARK_BLUE": u"dark blue",
92 u"DARK_MAGENTA": u"dark magenta",
93 u"DARK_CYAN": u"dark cyan",
94
95 u"LIGHT_GRAY": u"light gray",
96 }
97
98 ctype = u"background"
99
100
101
103 """
104 Monochrome color
105 """
106
107 colors = {
108 u"DEFAULT": None,
109 u"BOLD": u"bold",
110 u"UNDERLINE": u"underline",
111 u"STANDOUT": u"standout",
112 }
113
114 ctype = u"monochrome"
115
116
117
119 """
120 Wrapper for palette
121 """
122
123 - def __init__(self, name, fg, bg, ma=None):
124 self.name = name
125 self.fg = fg
126 self.bg = bg
127 self.ma = ma
128
129
130
132 """
133 Return urwid-compatible palette tuple
134 """
135
136 if self.ma is None:
137 _ma = None
138 elif isinstance(self.ma, tuple):
139 _ma = tuple([x.color for x in self.ma])
140 else:
141 _ma = self.ma.color
142
143 return (self.name, self.fg.color, self.bg.color, _ma)
144
145
146
148 """
149 Set foreground color
150 """
151
152 if not isinstance(fg, Foreground):
153 raise XYZValueError(_(u"Invalid argument type %s, "\
154 u"libxyz.ui.color.Foreground instance "\
155 u"expected." % type(fg)))
156
157 self.fg = fg
158
159
160
162 """
163 Set background color
164 """
165
166 if not isinstance(bg, Background):
167 raise XYZValueError(_(u"Invalid argument type %s, "\
168 u"libxyz.ui.color.Background instance "\
169 u"expected." % type(bg)))
170
171 self.bg = bg
172
173
174
176 """
177 Return copy of Palette object
178 """
179
180 return copy.deepcopy(self)
181