Browse Source

Issue #151 - fixed choices not loading in UI

pull/154/head
chriskiehl 8 years ago
parent
commit
72141f66e6
4 changed files with 44 additions and 28 deletions
  1. 30
      gooey/gui/model.py
  2. 9
      gooey/gui/widgets/components.py
  3. 31
      gooey/gui/widgets/widget_pack.py
  4. 2
      gooey/gui/windows/advanced_config.py

30
gooey/gui/model.py

@ -9,6 +9,9 @@ ArgumentGroup = namedtuple('ArgumentGroup', 'name command required_args optional
class MyWidget(object):
# TODO: Undumbify damn
# TODO: Undumbify _value/value access
def __init__(self, type, title, help, default, nargs, commands, choices):
self.type = type
self.title = title
@ -59,8 +62,8 @@ class MyWidget(object):
return '-' + repeated_args
if self.type == 'Dropdown':
if self._value == self.default:
return ''
if self._value == 'Select Option':
return None
elif self.commands and self._value:
return '{} {}'.format(self.commands[0], quote(self._value))
else:
@ -75,6 +78,29 @@ class MyWidget(object):
def value(self, val):
self._value = val
@classmethod
def from_dict(cls, data):
def maybe_unpack(collection, attr):
# TODO: RadioGroups need to support defaults
try:
if isinstance(collection, list):
return [item[attr] for item in collection]
return collection[attr]
except:
return None
details = data['data']
return cls(
data['type'],
maybe_unpack(details, 'display_name'),
maybe_unpack(details, 'help'),
maybe_unpack(details, 'default'),
maybe_unpack(details, 'nargs'),
maybe_unpack(details, 'commands'),
maybe_unpack(details, 'choices')
)
class States(object):

9
gooey/gui/widgets/components.py

@ -10,7 +10,7 @@ class BaseGuiComponent(object):
widget_class = None
def __init__(self, parent, title, msg):
def __init__(self, parent, title, msg, choices=None):
'''
:param data: field info (title, help, etc..)
:param widget_pack: internal wxWidgets to render
@ -21,6 +21,7 @@ class BaseGuiComponent(object):
# Widgets
self.title = None
self.help_msg = None
self.choices = choices
# Internal WidgetPack set in subclasses
@ -34,7 +35,7 @@ class BaseGuiComponent(object):
self.title = self.format_title(self.panel, title)
self.help_msg = self.format_help_msg(self.panel, msg)
self.help_msg.SetMinSize((0, -1))
core_widget_set = self.widget_pack.build(self.panel, {})
core_widget_set = self.widget_pack.build(self.panel, {}, self.choices)
vertical_container = wx.BoxSizer(wx.VERTICAL)
@ -111,7 +112,7 @@ class BaseGuiComponent(object):
class CheckBox(BaseGuiComponent):
def __init__(self, parent, title, msg):
def __init__(self, parent, title, msg, choices=None):
BaseGuiComponent.__init__(self, parent, title, msg)
def do_layout(self, parent, title, msg):
@ -156,7 +157,7 @@ class CheckBox(BaseGuiComponent):
class RadioGroup(object):
def __init__(self, parent, title, msg):
def __init__(self, parent, title, msg, choices=None):
self.panel = None
self.radio_buttons = []

31
gooey/gui/widgets/widget_pack.py

@ -17,7 +17,7 @@ class WidgetPack(object):
__metaclass__ = ABCMeta
@abstractmethod
def build(self, parent, data):
def build(self, parent, data, choices=None):
pass
def onResize(self, evt):
@ -38,16 +38,14 @@ class WidgetPack(object):
class BaseChooser(WidgetPack):
def __init__(self):
self.button_text = i18n._('browse')
self.option_string = None
self.parent = None
self.widget = None
self.button = None
def build(self, parent, data):
def build(self, parent, data, choices=None):
self.parent = parent
self.option_string = self.get_command(data)
self.widget = wx.TextCtrl(self.parent)
self.widget.AppendText(safe_default(data, ''))
self.widget.AppendText('')
self.widget.SetMinSize((0, -1))
dt = FileDrop(self.widget)
self.widget.SetDropTarget(dt)
@ -121,16 +119,13 @@ class TextInputPayload(WidgetPack):
self.option_string = None
self.no_quoting = no_quoting
def build(self, parent, data):
self.option_string = self.get_command(data)
if self.disable_quoting(data):
self.no_quoting = True
def build(self, parent, data, choices=None):
self.widget = wx.TextCtrl(parent)
dt = FileDrop(self.widget)
self.widget.SetDropTarget(dt)
self.widget.SetMinSize((0, -1))
self.widget.SetDoubleBuffered(True)
self.widget.AppendText(safe_default(data, ''))
self.widget.AppendText('')
return self.widget
def get_value(self):
@ -144,15 +139,12 @@ class DropdownPayload(WidgetPack):
self.option_string = None
self.no_quoting = no_quoting
def build(self, parent, data):
self.option_string = self.get_command(data)
if self.disable_quoting(data):
self.no_quoting = True
def build(self, parent, data, choices=None):
self.widget = wx.ComboBox(
parent=parent,
id=-1,
value=safe_default(data, self.default_value),
choices=[],
value=self.default_value,
choices=[self.default_value] + choices,
style=wx.CB_DROPDOWN
)
return self.widget
@ -161,21 +153,18 @@ class DropdownPayload(WidgetPack):
return self.widget.GetValue()
def set_value(self, text):
# TODO: can we set dropdowns this way?
self.widget.SetValue(text)
class CounterPayload(WidgetPack):
def __init__(self):
self.option_string = None
self.widget = None
def build(self, parent, data):
self.option_string = self.get_command(data)
def build(self, parent, data, choices=None):
self.widget = wx.ComboBox(
parent=parent,
id=-1,
value=safe_default(data, ''),
value='',
choices=map(str, range(1, 11)),
style=wx.CB_DROPDOWN
)

2
gooey/gui/windows/advanced_config.py

@ -47,7 +47,7 @@ class WidgetContainer(wx.Panel):
def populate(self, widgets):
for index, widget in enumerate(widgets):
widget_class = getattr(components, widget.type)
widget_instance = widget_class(self, widget.title, widget.help)
widget_instance = widget_class(self, widget.title, widget.help, widget.choices)
self.widgets.append(widget_instance)
self.layout()

Loading…
Cancel
Save