You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

  1. from gooey.gui.components.widgets.bases import TextContainer
  2. import wx
  3. from gooey.gui import formatters
  4. from gooey.gui.lang.i18n import _
  5. class Dropdown(TextContainer):
  6. def getWidget(self, parent, *args, **options):
  7. default = _('select_option')
  8. return wx.ComboBox(
  9. parent=parent,
  10. id=-1,
  11. value=default,
  12. choices=[default] + self._meta['choices'],
  13. style=wx.CB_DROPDOWN)
  14. def setOptions(self, options):
  15. prevSelection = self.widget.GetSelection()
  16. self.widget.Clear()
  17. for option in [_('select_option')] + options:
  18. self.widget.Append(option)
  19. self.widget.SetSelection(0)
  20. def setValue(self, value):
  21. ## +1 to offset the default placeholder value
  22. index = self._meta['choices'].index(value) + 1
  23. self.widget.SetSelection(index)
  24. def getWidgetValue(self):
  25. value = self.widget.GetValue()
  26. # filter out the extra default option that's
  27. # appended during creation
  28. if value == _('select_option'):
  29. return None
  30. return value
  31. def formatOutput(self, metadata, value):
  32. return formatters.dropdown(metadata, value)