always copy the options when creating a Selector

as I want to support mutating them after the fact
This commit is contained in:
Michael Hudson-Doyle 2019-07-24 11:27:29 +12:00
parent 4b4c951a81
commit 619a92e252
1 changed files with 10 additions and 7 deletions

View File

@ -79,11 +79,16 @@ class Option:
def __init__(self, val):
if not isinstance(val, tuple):
if not isinstance(val, str):
if isinstance(val, Option):
self.label = val.label
self.enabled = val.enabled
self.value = val.value
elif isinstance(val, str):
self.label = val
self.enabled = True
self.value = val
else:
raise SelectorError("invalid option %r", val)
self.label = val
self.enabled = True
self.value = val
elif len(val) == 1:
self.label = val[0]
self.enabled = True
@ -140,9 +145,7 @@ class Selector(WidgetWrap):
options = []
for opt in opts:
if not isinstance(opt, Option):
opt = Option(opt)
options.append(opt)
options.append(Option(opt))
self.options = options
self._set_index(index)