47
def makeMultiSelection(name, values, selectedvals=None, size=5):
48
"""Make a HTML multiple <select> element with named `name` from a value list.
50
The list can either be a list of strings, or a list of (value, label) tuples.
51
`selectedvals` is a list of values that should be pre-selected.
54
from MoinMoin.widget import html
55
result = html.SELECT(name=name, size="%d" % int(size), multiple=True)
57
if not isinstance(val, type(())):
59
result.append(html.OPTION(
60
value=val[0], selected=(val[0] in selectedvals))
61
.append(html.Text(val[1]))
67
""" RGB-Triple that automatically converts from and to
68
"#RRGGBB" encoding, and also takes Netscape color names.
70
The color values are stored in the attributes `r`, `g` and `b`.
73
>>> from color import Color
76
>>> str(Color('yellow'))
78
>>> str(Color((128, 0, 128)))
85
'aliceblue': (0xF0, 0xF8, 0xFF),
86
'antiquewhite': (0xFA, 0xEB, 0xD7),
87
'aqua': (0x00, 0xFF, 0xFF),
88
'aquamarine': (0x7F, 0xFF, 0xD4),
89
'azure': (0xF0, 0xFF, 0xFF),
90
'beige': (0xF5, 0xF5, 0xDC),
91
'bisque': (0xFF, 0xE4, 0xC4),
92
'black': (0x00, 0x00, 0x00),
93
'blanchedalmond': (0xFF, 0xEB, 0xCD),
94
'blue': (0x00, 0x00, 0xFF),
95
'blueviolet': (0x8A, 0x2B, 0xE2),
96
'brown': (0xA5, 0x2A, 0x2A),
97
'burlywood': (0xDE, 0xB8, 0x87),
98
'cadetblue': (0x5F, 0x9E, 0xA0),
99
'chartreuse': (0x7F, 0xFF, 0x00),
100
'chocolate': (0xD2, 0x69, 0x1E),
101
'coral': (0xFF, 0x7F, 0x50),
102
'cornflowerblue': (0x64, 0x95, 0xED),
103
'cornsilk': (0xFF, 0xF8, 0xDC),
104
'crimson': (0xDC, 0x14, 0x3C),
105
'cyan': (0x00, 0xFF, 0xFF),
106
'darkblue': (0x00, 0x00, 0x8B),
107
'darkcyan': (0x00, 0x8B, 0x8B),
108
'darkgoldenrod': (0xB8, 0x86, 0x0B),
109
'darkgray': (0xA9, 0xA9, 0xA9),
110
'darkgreen': (0x00, 0x64, 0x00),
111
'darkkhaki': (0xBD, 0xB7, 0x6B),
112
'darkmagenta': (0x8B, 0x00, 0x8B),
113
'darkolivegreen': (0x55, 0x6B, 0x2F),
114
'darkorange': (0xFF, 0x8C, 0x00),
115
'darkorchid': (0x99, 0x32, 0xCC),
116
'darkred': (0x8B, 0x00, 0x00),
117
'darksalmon': (0xE9, 0x96, 0x7A),
118
'darkseagreen': (0x8F, 0xBC, 0x8F),
119
'darkslateblue': (0x48, 0x3D, 0x8B),
120
'darkslategray': (0x2F, 0x4F, 0x4F),
121
'darkturquoise': (0x00, 0xCE, 0xD1),
122
'darkviolet': (0x94, 0x00, 0xD3),
123
'deeppink': (0xFF, 0x14, 0x93),
124
'deepskyblue': (0x00, 0xBF, 0xFF),
125
'dimgray': (0x69, 0x69, 0x69),
126
'dodgerblue': (0x1E, 0x90, 0xFF),
127
'firebrick': (0xB2, 0x22, 0x22),
128
'floralwhite': (0xFF, 0xFA, 0xF0),
129
'forestgreen': (0x22, 0x8B, 0x22),
130
'fuchsia': (0xFF, 0x00, 0xFF),
131
'gainsboro': (0xDC, 0xDC, 0xDC),
132
'ghostwhite': (0xF8, 0xF8, 0xFF),
133
'gold': (0xFF, 0xD7, 0x00),
134
'goldenrod': (0xDA, 0xA5, 0x20),
135
'gray': (0x80, 0x80, 0x80),
136
'green': (0x00, 0x80, 0x00),
137
'greenyellow': (0xAD, 0xFF, 0x2F),
138
'honeydew': (0xF0, 0xFF, 0xF0),
139
'hotpink': (0xFF, 0x69, 0xB4),
140
'indianred': (0xCD, 0x5C, 0x5C),
141
'indigo': (0x4B, 0x00, 0x82),
142
'ivory': (0xFF, 0xFF, 0xF0),
143
'khaki': (0xF0, 0xE6, 0x8C),
144
'lavender': (0xE6, 0xE6, 0xFA),
145
'lavenderblush': (0xFF, 0xF0, 0xF5),
146
'lawngreen': (0x7C, 0xFC, 0x00),
147
'lemonchiffon': (0xFF, 0xFA, 0xCD),
148
'lightblue': (0xAD, 0xD8, 0xE6),
149
'lightcoral': (0xF0, 0x80, 0x80),
150
'lightcyan': (0xE0, 0xFF, 0xFF),
151
'lightgoldenrodyellow': (0xFA, 0xFA, 0xD2),
152
'lightgreen': (0x90, 0xEE, 0x90),
153
'lightgrey': (0xD3, 0xD3, 0xD3),
154
'lightpink': (0xFF, 0xB6, 0xC1),
155
'lightsalmon': (0xFF, 0xA0, 0x7A),
156
'lightseagreen': (0x20, 0xB2, 0xAA),
157
'lightskyblue': (0x87, 0xCE, 0xFA),
158
'lightslategray': (0x77, 0x88, 0x99),
159
'lightsteelblue': (0xB0, 0xC4, 0xDE),
160
'lightyellow': (0xFF, 0xFF, 0xE0),
161
'lime': (0x00, 0xFF, 0x00),
162
'limegreen': (0x32, 0xCD, 0x32),
163
'linen': (0xFA, 0xF0, 0xE6),
164
'magenta': (0xFF, 0x00, 0xFF),
165
'maroon': (0x80, 0x00, 0x00),
166
'mediumaquamarine': (0x66, 0xCD, 0xAA),
167
'mediumblue': (0x00, 0x00, 0xCD),
168
'mediumorchid': (0xBA, 0x55, 0xD3),
169
'mediumpurple': (0x93, 0x70, 0xDB),
170
'mediumseagreen': (0x3C, 0xB3, 0x71),
171
'mediumslateblue': (0x7B, 0x68, 0xEE),
172
'mediumspringgreen': (0x00, 0xFA, 0x9A),
173
'mediumturquoise': (0x48, 0xD1, 0xCC),
174
'mediumvioletred': (0xC7, 0x15, 0x85),
175
'midnightblue': (0x19, 0x19, 0x70),
176
'mintcream': (0xF5, 0xFF, 0xFA),
177
'mistyrose': (0xFF, 0xE4, 0xE1),
178
'moccasin': (0xFF, 0xE4, 0xB5),
179
'navajowhite': (0xFF, 0xDE, 0xAD),
180
'navy': (0x00, 0x00, 0x80),
181
'oldlace': (0xFD, 0xF5, 0xE6),
182
'olive': (0x80, 0x80, 0x00),
183
'olivedrab': (0x6B, 0x8E, 0x23),
184
'orange': (0xFF, 0xA5, 0x00),
185
'orangered': (0xFF, 0x45, 0x00),
186
'orchid': (0xDA, 0x70, 0xD6),
187
'palegoldenrod': (0xEE, 0xE8, 0xAA),
188
'palegreen': (0x98, 0xFB, 0x98),
189
'paleturquoise': (0xAF, 0xEE, 0xEE),
190
'palevioletred': (0xDB, 0x70, 0x93),
191
'papayawhip': (0xFF, 0xEF, 0xD5),
192
'peachpuff': (0xFF, 0xDA, 0xB9),
193
'peru': (0xCD, 0x85, 0x3F),
194
'pink': (0xFF, 0xC0, 0xCB),
195
'plum': (0xDD, 0xA0, 0xDD),
196
'powderblue': (0xB0, 0xE0, 0xE6),
197
'purple': (0x80, 0x00, 0x80),
198
'red': (0xFF, 0x00, 0x00),
199
'rosybrown': (0xBC, 0x8F, 0x8F),
200
'royalblue': (0x41, 0x69, 0xE1),
201
'saddlebrown': (0x8B, 0x45, 0x13),
202
'salmon': (0xFA, 0x80, 0x72),
203
'sandybrown': (0xF4, 0xA4, 0x60),
204
'seagreen': (0x2E, 0x8B, 0x57),
205
'seashell': (0xFF, 0xF5, 0xEE),
206
'sienna': (0xA0, 0x52, 0x2D),
207
'silver': (0xC0, 0xC0, 0xC0),
208
'skyblue': (0x87, 0xCE, 0xEB),
209
'slateblue': (0x6A, 0x5A, 0xCD),
210
'slategray': (0x70, 0x80, 0x90),
211
'snow': (0xFF, 0xFA, 0xFA),
212
'springgreen': (0x00, 0xFF, 0x7F),
213
'steelblue': (0x46, 0x82, 0xB4),
214
'tan': (0xD2, 0xB4, 0x8C),
215
'teal': (0x00, 0x80, 0x80),
216
'thistle': (0xD8, 0xBF, 0xD8),
217
'tomato': (0xFF, 0x63, 0x47),
218
'turquoise': (0x40, 0xE0, 0xD0),
219
'violet': (0xEE, 0x82, 0xEE),
220
'wheat': (0xF5, 0xDE, 0xB3),
221
'white': (0xFF, 0xFF, 0xFF),
222
'whitesmoke': (0xF5, 0xF5, 0xF5),
223
'yellow': (0xFF, 0xFF, 0x00),
224
'yellowgreen': (0x9A, 0xCD, 0x32),
227
def __init__(self, color):
228
""" Init color value, the 'color' parameter may be
229
another Color instance, a tuple containing 3 color values,
230
a Netscape color name or a HTML color ("#RRGGBB").
232
if isinstance(color, tuple) and len(color) == 3:
233
self.r, self.g, self.b = int(color[0]), int(color[1]), int(color[2])
234
elif isinstance(color, Color):
235
self.r, self.g, self.b = color.r, color.g, color.b
236
elif not isinstance(color, str):
237
raise TypeError("Color() expects a Color instance, a RGB triple or a color string")
238
elif color[0] == '#':
239
color = long(color[1:], 16)
240
self.r = (color >> 16) & 255
241
self.g = (color >> 8) & 255
243
elif color not in self.COLORS:
244
raise ValueError("Unknown color name '%s'" % color)
247
self.r, self.g, self.b = self.COLORS[color]
250
return "#%02X%02X%02X" % (self.r, self.g, self.b)
253
return "Color(%d, %d, %d)" % (self.r, self.g, self.b)
256
return self.__long__()
259
return (self.r << 16) | (self.g << 8) | self.b