summaryrefslogtreecommitdiff
path: root/ricky/param/multiselect.py
diff options
context:
space:
mode:
authorpepperpepperpepper <pepper@scannerjammer.com>2015-11-29 17:43:44 -0800
committerpepperpepperpepper <pepper@scannerjammer.com>2015-11-29 17:43:44 -0800
commit9a7bf3bffb2a8459e66b988aaff53611723b5ab4 (patch)
treecc4ef0de15e22f5c6e5f8d2ecf16db0486d7a8ff /ricky/param/multiselect.py
parent10a619b2c7227b2ad214fbb985141b884fbe87fb (diff)
required=0, -e commit message for your changes. Lines starting
Diffstat (limited to 'ricky/param/multiselect.py')
-rw-r--r--ricky/param/multiselect.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/ricky/param/multiselect.py b/ricky/param/multiselect.py
index 21eca78..8da5374 100644
--- a/ricky/param/multiselect.py
+++ b/ricky/param/multiselect.py
@@ -5,25 +5,28 @@ from ricky.param import Param
class MultiSelect(Param):
def __init__(self, **kwargs):
super(MultiSelect, self).__init__(**kwargs)
+ self._options = kwargs.get('options') or []
+ if len(self._options):
+ self._validate_options()
+
+ def options(self):
+ return self._options
+
+ def _validate_options(self):
+ try:
+ pass
+ except Exception:
+ raise ValueError('Unable to validate %s\n:' % self.name)
def value_get(self):
return super(MultiSelect, self).value_get()
def value_set(self, value):
- if not any([value == i['value'] for i in self._selections]) and \
- value is not None:
+ if value not in self._options and value is not None:
raise ValueError
super(MultiSelect, self).value_set(value)
value = property(value_get, value_set)
def randomize(self):
- weights_total = sum(map(lambda x: x["weight"], self.selections()))
- choice = random.randint(0, weights_total)
- position = 0
- for elem in self.selections():
- position += elem["weight"]
- if position >= choice:
- self.value = elem["value"]
- break
-
+ self.value_set(random.choice(self.options))