diff options
Diffstat (limited to 'ricky/param/color.py')
| -rw-r--r-- | ricky/param/color.py | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/ricky/param/color.py b/ricky/param/color.py index b331fb9..e192cba 100644 --- a/ricky/param/color.py +++ b/ricky/param/color.py @@ -1,30 +1,39 @@ from ricky.param.multiselect import MultiSelect import random + + class Color(MultiSelect): def __init__(self, **kwargs): - super(Color, self).__init__(**kwargs) + super(Color, self).__init__(**kwargs) @classmethod - def from_rgb(cls, r,g,b): - return cls(value="rgb({},{},{})".format(r,g,b)) + def from_rgb(cls, r, g, b): + return cls(value="rgb({},{},{})".format(r, g, b)) @property def value(self): - return super(MultiSelect, self).value_get() + return super(MultiSelect, self).value_get() + @value.setter def value(self, value): - self._value = value - if not self._value is None: - self.is_ready = 1 - self.set_by_user = 1 + self._value = value + if self._value is not None: + self.is_ready = 1 + self.set_by_user = 1 def randomize(self): - weights_total = sum(map(lambda x: x["weight"], self.options())) + (255 * 255 * 255) - choice = random.randint(0, weights_total) - position = 0 - for elem in self.options(): - position += elem["weight"] - if position >= choice: - self.value = elem["value"] - return - self.value = "rgb({},{},{})".format( random.randint(0,255), random.randint(0,255), random.randint(0,255)) + weights_total = sum( + map(lambda x: x["weight"], self.options()) + ) + (255 * 255 * 255) + choice = random.randint(0, weights_total) + position = 0 + for elem in self.options(): + position += elem["weight"] + if position >= choice: + self.value = elem["value"] + return + self.value = "rgb(%s,%s,%s)" % ( + random.randint(0, 255), + random.randint(0, 255), + random.randint(0, 255) + ) |
