sugar-toolkit-gtk3/sugar/canvas/IconColor.py

27 lines
685 B
Python
Raw Normal View History

2006-08-23 21:03:17 +02:00
import random
2006-09-08 13:53:55 +02:00
from sugar.canvas import Colors
def is_valid(fill_color):
return Colors.table.has_key(fill_color)
2006-08-23 21:03:17 +02:00
2006-09-08 13:53:55 +02:00
class IconColor:
2006-08-23 21:03:17 +02:00
def __init__(self, fill_color=None):
if fill_color == None:
2006-09-08 13:53:55 +02:00
n = int(random.random() * (len(Colors.table) - 1))
fill_color = Colors.table.keys()[n]
else:
if fill_color[0] == '#':
fill_color = fill_color.upper()
else:
fill_color = fill_color.lower()
2006-09-08 13:53:55 +02:00
if not Colors.table.has_key(fill_color):
raise RuntimeError("Specified fill color %s is not allowed." % fill_color)
2006-08-23 21:03:17 +02:00
self._fill_color = fill_color
def get_stroke_color(self):
2006-09-08 13:53:55 +02:00
return Colors.table[self._fill_color]
2006-08-23 21:03:17 +02:00
def get_fill_color(self):
return self._fill_color