Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate
1
# Copyright (C) 2006-2007 Red Hat, Inc.
2
#
3
# This library is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU Lesser General Public
5
# License as published by the Free Software Foundation; either
6
# version 2 of the License, or (at your option) any later version.
7
#
8
# This library is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
# Lesser General Public License for more details.
12
#
13
# You should have received a copy of the GNU Lesser General Public
14
# License along with this library; if not, write to the
15
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16
# Boston, MA 02111-1307, USA.
17
18
"""
19
STABLE.
20
"""
21
22
import random
23
import logging
24
25
import gconf
26
27
colors = [
28
['#B20008', '#FF2B34'], \
29
['#FF2B34', '#B20008'], \
30
['#E6000A', '#FF2B34'], \
31
['#FF2B34', '#E6000A'], \
32
['#FFADCE', '#FF2B34'], \
33
['#9A5200', '#FF2B34'], \
34
['#FF2B34', '#9A5200'], \
35
['#FF8F00', '#FF2B34'], \
36
['#FF2B34', '#FF8F00'], \
37
['#FFC169', '#FF2B34'], \
38
['#807500', '#FF2B34'], \
39
['#FF2B34', '#807500'], \
40
['#BE9E00', '#FF2B34'], \
41
['#FF2B34', '#BE9E00'], \
42
['#F8E800', '#FF2B34'], \
43
['#008009', '#FF2B34'], \
44
['#FF2B34', '#008009'], \
45
['#00B20D', '#FF2B34'], \
46
['#FF2B34', '#00B20D'], \
47
['#8BFF7A', '#FF2B34'], \
48
['#00588C', '#FF2B34'], \
49
['#FF2B34', '#00588C'], \
50
['#005FE4', '#FF2B34'], \
51
['#FF2B34', '#005FE4'], \
52
['#BCCDFF', '#FF2B34'], \
53
['#5E008C', '#FF2B34'], \
54
['#FF2B34', '#5E008C'], \
55
['#7F00BF', '#FF2B34'], \
56
['#FF2B34', '#7F00BF'], \
57
['#D1A3FF', '#FF2B34'], \
58
['#9A5200', '#FF8F00'], \
59
['#FF8F00', '#9A5200'], \
60
['#C97E00', '#FF8F00'], \
61
['#FF8F00', '#C97E00'], \
62
['#FFC169', '#FF8F00'], \
63
['#807500', '#FF8F00'], \
64
['#FF8F00', '#807500'], \
65
['#BE9E00', '#FF8F00'], \
66
['#FF8F00', '#BE9E00'], \
67
['#F8E800', '#FF8F00'], \
68
['#008009', '#FF8F00'], \
69
['#FF8F00', '#008009'], \
70
['#00B20D', '#FF8F00'], \
71
['#FF8F00', '#00B20D'], \
72
['#8BFF7A', '#FF8F00'], \
73
['#00588C', '#FF8F00'], \
74
['#FF8F00', '#00588C'], \
75
['#005FE4', '#FF8F00'], \
76
['#FF8F00', '#005FE4'], \
77
['#BCCDFF', '#FF8F00'], \
78
['#5E008C', '#FF8F00'], \
79
['#FF8F00', '#5E008C'], \
80
['#A700FF', '#FF8F00'], \
81
['#FF8F00', '#A700FF'], \
82
['#D1A3FF', '#FF8F00'], \
83
['#B20008', '#FF8F00'], \
84
['#FF8F00', '#B20008'], \
85
['#FF2B34', '#FF8F00'], \
86
['#FF8F00', '#FF2B34'], \
87
['#FFADCE', '#FF8F00'], \
88
['#807500', '#F8E800'], \
89
['#F8E800', '#807500'], \
90
['#BE9E00', '#F8E800'], \
91
['#F8E800', '#BE9E00'], \
92
['#FFFA00', '#EDDE00'], \
93
['#008009', '#F8E800'], \
94
['#F8E800', '#008009'], \
95
['#00EA11', '#F8E800'], \
96
['#F8E800', '#00EA11'], \
97
['#8BFF7A', '#F8E800'], \
98
['#00588C', '#F8E800'], \
99
['#F8E800', '#00588C'], \
100
['#00A0FF', '#F8E800'], \
101
['#F8E800', '#00A0FF'], \
102
['#BCCEFF', '#F8E800'], \
103
['#5E008C', '#F8E800'], \
104
['#F8E800', '#5E008C'], \
105
['#AC32FF', '#F8E800'], \
106
['#F8E800', '#AC32FF'], \
107
['#D1A3FF', '#F8E800'], \
108
['#B20008', '#F8E800'], \
109
['#F8E800', '#B20008'], \
110
['#FF2B34', '#F8E800'], \
111
['#F8E800', '#FF2B34'], \
112
['#FFADCE', '#F8E800'], \
113
['#9A5200', '#F8E800'], \
114
['#F8E800', '#9A5200'], \
115
['#FF8F00', '#F8E800'], \
116
['#F8E800', '#FF8F00'], \
117
['#FFC169', '#F8E800'], \
118
['#008009', '#00EA11'], \
119
['#00EA11', '#008009'], \
120
['#00B20D', '#00EA11'], \
121
['#00EA11', '#00B20D'], \
122
['#8BFF7A', '#00EA11'], \
123
['#00588C', '#00EA11'], \
124
['#00EA11', '#00588C'], \
125
['#005FE4', '#00EA11'], \
126
['#00EA11', '#005FE4'], \
127
['#BCCDFF', '#00EA11'], \
128
['#5E008C', '#00EA11'], \
129
['#00EA11', '#5E008C'], \
130
['#7F00BF', '#00EA11'], \
131
['#00EA11', '#7F00BF'], \
132
['#D1A3FF', '#00EA11'], \
133
['#B20008', '#00EA11'], \
134
['#00EA11', '#B20008'], \
135
['#FF2B34', '#00EA11'], \
136
['#00EA11', '#FF2B34'], \
137
['#FFADCE', '#00EA11'], \
138
['#9A5200', '#00EA11'], \
139
['#00EA11', '#9A5200'], \
140
['#FF8F00', '#00EA11'], \
141
['#00EA11', '#FF8F00'], \
142
['#FFC169', '#00EA11'], \
143
['#807500', '#00EA11'], \
144
['#00EA11', '#807500'], \
145
['#BE9E00', '#00EA11'], \
146
['#00EA11', '#BE9E00'], \
147
['#F8E800', '#00EA11'], \
148
['#00588C', '#00A0FF'], \
149
['#00A0FF', '#00588C'], \
150
['#005FE4', '#00A0FF'], \
151
['#00A0FF', '#005FE4'], \
152
['#BCCDFF', '#00A0FF'], \
153
['#5E008C', '#00A0FF'], \
154
['#00A0FF', '#5E008C'], \
155
['#9900E6', '#00A0FF'], \
156
['#00A0FF', '#9900E6'], \
157
['#D1A3FF', '#00A0FF'], \
158
['#B20008', '#00A0FF'], \
159
['#00A0FF', '#B20008'], \
160
['#FF2B34', '#00A0FF'], \
161
['#00A0FF', '#FF2B34'], \
162
['#FFADCE', '#00A0FF'], \
163
['#9A5200', '#00A0FF'], \
164
['#00A0FF', '#9A5200'], \
165
['#FF8F00', '#00A0FF'], \
166
['#00A0FF', '#FF8F00'], \
167
['#FFC169', '#00A0FF'], \
168
['#807500', '#00A0FF'], \
169
['#00A0FF', '#807500'], \
170
['#BE9E00', '#00A0FF'], \
171
['#00A0FF', '#BE9E00'], \
172
['#F8E800', '#00A0FF'], \
173
['#008009', '#00A0FF'], \
174
['#00A0FF', '#008009'], \
175
['#00B20D', '#00A0FF'], \
176
['#00A0FF', '#00B20D'], \
177
['#8BFF7A', '#00A0FF'], \
178
['#5E008C', '#AC32FF'], \
179
['#AC32FF', '#5E008C'], \
180
['#7F00BF', '#AC32FF'], \
181
['#AC32FF', '#7F00BF'], \
182
['#D1A3FF', '#AC32FF'], \
183
['#B20008', '#AC32FF'], \
184
['#AC32FF', '#B20008'], \
185
['#FF2B34', '#AC32FF'], \
186
['#AC32FF', '#FF2B34'], \
187
['#FFADCE', '#AC32FF'], \
188
['#9A5200', '#AC32FF'], \
189
['#AC32FF', '#9A5200'], \
190
['#FF8F00', '#AC32FF'], \
191
['#AC32FF', '#FF8F00'], \
192
['#FFC169', '#AC32FF'], \
193
['#807500', '#AC32FF'], \
194
['#AC32FF', '#807500'], \
195
['#BE9E00', '#AC32FF'], \
196
['#AC32FF', '#BE9E00'], \
197
['#F8E800', '#AC32FF'], \
198
['#008009', '#AC32FF'], \
199
['#AC32FF', '#008009'], \
200
['#00B20D', '#AC32FF'], \
201
['#AC32FF', '#00B20D'], \
202
['#8BFF7A', '#AC32FF'], \
203
['#00588C', '#AC32FF'], \
204
['#AC32FF', '#00588C'], \
205
['#005FE4', '#AC32FF'], \
206
['#AC32FF', '#005FE4'], \
207
['#BCCDFF', '#AC32FF'], \
208
]
209
210
211
def _parse_string(color_string):
212
    if not isinstance(color_string, (str, unicode)):
213
        logging.error('Invalid color string: %r', color_string)
214
        return None
215
216
    if color_string == 'white':
217
        return ['#ffffff', '#414141']
218
    elif color_string == 'insensitive':
219
        return ['#ffffff', '#e2e2e2']
220
221
    splitted = color_string.split(',')
222
    if len(splitted) == 2:
223
        return [splitted[0], splitted[1]]
224
    else:
225
        return None
226
227
228
def is_valid(color_string):
229
    return (_parse_string(color_string) != None)
230
231
232
class XoColor:
233
234
    def __init__(self, color_string=None):
235
        if color_string == None:
236
            randomize = True
237
        elif not is_valid(color_string):
238
            logging.debug('Color string is not valid: %s, '
239
                          'fallback to default', color_string)
240
            client = gconf.client_get_default()
241
            color_string = client.get_string('/desktop/sugar/user/color')
242
            randomize = False
243
        else:
244
            randomize = False
245
246
        if randomize:
247
            n = int(random.random() * (len(colors) - 1))
248
            [self.stroke, self.fill] = colors[n]
249
        else:
250
            [self.stroke, self.fill] = _parse_string(color_string)
251
252
    def __cmp__(self, other):
253
        if isinstance(other, XoColor):
254
            if self.stroke == other.stroke and self.fill == other.fill:
255
                return 0
256
        return -1
257
258
    def get_stroke_color(self):
259
        return self.stroke
260
261
    def get_fill_color(self):
262
        return self.fill
263
264
    def to_string(self):
265
        return '%s,%s' % (self.stroke, self.fill)
266
267
268
if __name__ == '__main__':
269
    import sys
270
    import re
271
272
    f = open(sys.argv[1], 'r')
273
274
    print 'colors = ['
275
276
    for line in f.readlines():
277
        match = re.match(r'fill: ([A-Z0-9]*) stroke: ([A-Z0-9]*)', line)
278
        print "['#%s', '#%s'], \\" % (match.group(2), match.group(1))
279
280
    print ']'
281
282
    f.close()