Bring around both colors, since multiple combinations can have
the same base color.
This commit is contained in:
parent
2a2554f157
commit
233051875b
@ -43,7 +43,7 @@ class ShellOwner(object):
|
|||||||
def announce(self):
|
def announce(self):
|
||||||
# Create and announce our presence
|
# Create and announce our presence
|
||||||
color = conf.get_profile().get_color()
|
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,
|
self._service = self._pservice.register_service(self._nick,
|
||||||
PRESENCE_SERVICE_TYPE, properties=props)
|
PRESENCE_SERVICE_TYPE, properties=props)
|
||||||
print "Owner '%s' using port %d" % (self._nick, self._service.get_port())
|
print "Owner '%s' using port %d" % (self._nick, self._service.get_port())
|
||||||
|
@ -18,9 +18,9 @@ class _Profile:
|
|||||||
if cp.has_option('Buddy', 'NickName'):
|
if cp.has_option('Buddy', 'NickName'):
|
||||||
self._nick_name = cp.get('Buddy', 'NickName')
|
self._nick_name = cp.get('Buddy', 'NickName')
|
||||||
if cp.has_option('Buddy', 'Color'):
|
if cp.has_option('Buddy', 'Color'):
|
||||||
fill_color = cp.get('Buddy', 'Color')
|
color = cp.get('Buddy', 'Color')
|
||||||
if IconColor.is_valid(fill_color):
|
if IconColor.is_valid(color):
|
||||||
self._color = IconColor.IconColor(fill_color)
|
self._color = IconColor.IconColor(color)
|
||||||
|
|
||||||
def _ensure_dirs(self):
|
def _ensure_dirs(self):
|
||||||
try:
|
try:
|
||||||
@ -50,7 +50,7 @@ class _Profile:
|
|||||||
section = 'Buddy'
|
section = 'Buddy'
|
||||||
cp.add_section(section)
|
cp.add_section(section)
|
||||||
cp.set(section, 'NickName', self._nick_name)
|
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')
|
fileobject = open(self._get_config_path(), 'w')
|
||||||
cp.write(fileobject)
|
cp.write(fileobject)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -2,25 +2,33 @@ import random
|
|||||||
|
|
||||||
from sugar.canvas import Colors
|
from sugar.canvas import Colors
|
||||||
|
|
||||||
def is_valid(fill_color):
|
def _parse_string(color_string):
|
||||||
return Colors.table.has_key(fill_color)
|
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:
|
class IconColor:
|
||||||
def __init__(self, fill_color=None):
|
def __init__(self, color_string=None):
|
||||||
if fill_color == None:
|
if color_string == None or not is_valid(color_string):
|
||||||
n = int(random.random() * (len(Colors.table) - 1))
|
n = int(random.random() * (len(Colors.colors) - 1))
|
||||||
fill_color = Colors.table.keys()[n]
|
[self._fill, self._stroke] = Colors.colors[n]
|
||||||
else:
|
else:
|
||||||
if fill_color[0] == '#':
|
[self._fill, self._stroke] = _parse_string(color_string)
|
||||||
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
|
|
||||||
|
|
||||||
def get_stroke_color(self):
|
def get_stroke_color(self):
|
||||||
return Colors.table[self._fill_color]
|
return self._stroke
|
||||||
|
|
||||||
def get_fill_color(self):
|
def get_fill_color(self):
|
||||||
return self._fill_color
|
return self._fill
|
||||||
|
|
||||||
|
def to_string(self):
|
||||||
|
return '%s,%s' % (self._fill, self._stroke)
|
||||||
|
|
||||||
|
@ -2,16 +2,15 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
result = 'table = {\n'
|
result = 'colors = [\n'
|
||||||
result += '\'white\' : \'black\' , \\\n'
|
|
||||||
|
|
||||||
hex_file = open(sys.argv[1], 'r')
|
hex_file = open(sys.argv[1], 'r')
|
||||||
|
|
||||||
for line in hex_file.readlines():
|
for line in hex_file.readlines():
|
||||||
[ stroke, fill ] = line.split()
|
[ stroke, fill ] = line.split()
|
||||||
result += '\'#%s\' : \'#%s\', \\\n' % (fill, stroke)
|
result += '[\'#%s\', \'#%s\'], \\\n' % (fill, stroke)
|
||||||
|
|
||||||
result += '}'
|
result += ']'
|
||||||
|
|
||||||
hex_file.close()
|
hex_file.close()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user