Ticket #1592: two-axis-xocolor.patch

File two-axis-xocolor.patch, 1.8 KB (added by alsroot, 11 years ago)
  • src/sugar/graphics/xocolor.py

    diff --git a/src/sugar/graphics/xocolor.py b/src/sugar/graphics/xocolor.py
    index fd329cb..82e2b53 100644
    a b  
    11# Copyright (C) 2006-2007 Red Hat, Inc.
     2# Copyright (C) 2008-2009 Sugar Labs
    23#
    34# This library is free software; you can redistribute it and/or
    45# modify it under the terms of the GNU Lesser General Public
    colors = [ 
    207208['#BCCDFF', '#AC32FF'], \
    208209]
    209210
     211strokes = list(set([i[0] for i in colors]))
     212fills = list(set([i[1] for i in colors]))
     213
    210214
    211215def _parse_string(color_string):
    212216    if color_string == 'white':
    class XoColor: 
    261265        return '%s,%s' % (self.stroke, self.fill)
    262266
    263267
     268class _PartColor(object):
     269
     270    def __init__(self, color_range, color):
     271        self._range = color_range
     272        if color in self._range:
     273            self._index = self._range.index(color)
     274        else:
     275            self._index = random.randint(0, len(self._range) - 1)
     276        self.value = self._range[self._index]
     277
     278    def get_next(self):
     279        return self._range[self._get_next_index(+1)]
     280
     281    def get_prev(self):
     282        return self._range[self._get_next_index(-1)]
     283
     284    def next(self, delta):
     285        self._index = self._get_next_index(delta)
     286        self.value = self._range[self._index]
     287
     288    def _get_next_index(self, delta):
     289        if self._index + delta < 0:
     290            return len(self._range) - 1
     291        elif self._index + delta >= len(self._range):
     292            return 0
     293        else:
     294            return self._index + delta
     295
     296
     297class StrokeColor(_PartColor):
     298
     299    def __init__(self, color=None):
     300        _PartColor.__init__(self, strokes, color)
     301
     302
     303class FillColor(_PartColor):
     304
     305    def __init__(self, color=None):
     306        _PartColor.__init__(self, fills, color)
     307
     308
    264309if __name__ == "__main__":
    265310    import sys
    266311    import re