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

View File

@ -43,7 +43,7 @@ class ShellOwner(object):
def announce(self):
# Create and announce our presence
color = conf.get_profile().get_color()
props = { 'color': color.get_fill_color() }
props = { 'color': color.to_string() }
self._service = self._pservice.register_service(self._nick,
PRESENCE_SERVICE_TYPE, properties=props)
print "Owner '%s' using port %d" % (self._nick, self._service.get_port())

View File

@ -18,9 +18,9 @@ class _Profile:
if cp.has_option('Buddy', 'NickName'):
self._nick_name = cp.get('Buddy', 'NickName')
if cp.has_option('Buddy', 'Color'):
fill_color = cp.get('Buddy', 'Color')
if IconColor.is_valid(fill_color):
self._color = IconColor.IconColor(fill_color)
color = cp.get('Buddy', 'Color')
if IconColor.is_valid(color):
self._color = IconColor.IconColor(color)
def _ensure_dirs(self):
try:
@ -50,7 +50,7 @@ class _Profile:
section = 'Buddy'
cp.add_section(section)
cp.set(section, 'NickName', self._nick_name)
cp.set(section, 'Color', self._color.get_fill_color())
cp.set(section, 'Color', self._color.to_string())
fileobject = open(self._get_config_path(), 'w')
cp.write(fileobject)

File diff suppressed because it is too large Load Diff

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)

View File

@ -2,16 +2,15 @@
import sys
result = 'table = {\n'
result += '\'white\' : \'black\' , \\\n'
result = 'colors = [\n'
hex_file = open(sys.argv[1], 'r')
for line in hex_file.readlines():
[ stroke, fill ] = line.split()
result += '\'#%s\' : \'#%s\', \\\n' % (fill, stroke)
result += '[\'#%s\', \'#%s\'], \\\n' % (fill, stroke)
result += '}'
result += ']'
hex_file.close()