diff options
author | Daniel Narvaez <dwnarvaez@gmail.com> | 2013-05-02 16:52:59 (GMT) |
---|---|---|
committer | Daniel Narvaez <dwnarvaez@gmail.com> | 2013-05-02 16:52:59 (GMT) |
commit | 6cbc3d1a4813d7e090051f01e400bca0a04a26c2 (patch) | |
tree | 298564637bf9c35d1dded290c662b12f8aacaf0c | |
parent | 79fa03e846d4a816790bb589de3d7ee0ca52520d (diff) |
Improve XOColor fallback logic
We was failing if the value in gconf was None. Also parsing
the string once just to see if it's valid was pretty dumb.
-rw-r--r-- | src/sugar3/graphics/xocolor.py | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/sugar3/graphics/xocolor.py b/src/sugar3/graphics/xocolor.py index 84e93a9..45e2332 100644 --- a/src/sugar3/graphics/xocolor.py +++ b/src/sugar3/graphics/xocolor.py @@ -225,29 +225,23 @@ def _parse_string(color_string): return None -def is_valid(color_string): - return (_parse_string(color_string) != None) - - class XoColor: def __init__(self, color_string=None): - if color_string == None: - randomize = True - elif not is_valid(color_string): - logging.debug('Color string is not valid: %s, ' - 'fallback to default', color_string) + parsed_color = None + + if color_string is None: client = GConf.Client.get_default() color_string = client.get_string('/desktop/sugar/user/color') - randomize = is_valid(color_string) - else: - randomize = False - if randomize: + if color_string is not None: + parsed_color = _parse_string(color_string) + + if parsed_color is None: n = int(random.random() * (len(colors) - 1)) [self.stroke, self.fill] = colors[n] else: - [self.stroke, self.fill] = _parse_string(color_string) + [self.stroke, self.fill] = parsed_color def __cmp__(self, other): if isinstance(other, XoColor): |