Bring around both colors, since multiple combinations can have

the same base color.
This commit is contained in:
Marco Pesenti Gritti
2006-09-08 15:09:10 +02:00
parent 2a2554f157
commit 233051875b
5 changed files with 593 additions and 587 deletions
+562 -563
View File
File diff suppressed because it is too large Load Diff
+23 -15
View File
@@ -2,25 +2,33 @@ import random
from sugar.canvas import Colors
def is_valid(fill_color):
return Colors.table.has_key(fill_color)
def _parse_string(color_string):
if color_string == 'white':
return ['#4f4f4f', 'white']
splitted = color_string.split(',')
if len(splitted) == 2:
return [splitted[0], splitted[1]]
else:
return None
def is_valid(color_string):
return (_parse_string(color_string) != None)
class IconColor:
def __init__(self, fill_color=None):
if fill_color == None:
n = int(random.random() * (len(Colors.table) - 1))
fill_color = Colors.table.keys()[n]
def __init__(self, color_string=None):
if color_string == None or not is_valid(color_string):
n = int(random.random() * (len(Colors.colors) - 1))
[self._fill, self._stroke] = Colors.colors[n]
else:
if fill_color[0] == '#':
fill_color = fill_color.upper()
else:
fill_color = fill_color.lower()
if not Colors.table.has_key(fill_color):
raise RuntimeError("Specified fill color %s is not allowed." % fill_color)
self._fill_color = fill_color
[self._fill, self._stroke] = _parse_string(color_string)
def get_stroke_color(self):
return Colors.table[self._fill_color]
return self._stroke
def get_fill_color(self):
return self._fill_color
return self._fill
def to_string(self):
return '%s,%s' % (self._fill, self._stroke)