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.

54 lines
1.8 KiB

3 years ago
3 years ago
3 years ago
  1. import wx # type: ignore
  2. from gooey.gui import formatters
  3. from gooey.gui.components.widgets.bases import TextContainer
  4. from gooey.python_bindings import types as t
  5. class Listbox(TextContainer):
  6. def getWidget(self, parent, *args, **options):
  7. height = self._options.get('height', 60)
  8. return wx.ListBox(
  9. parent=parent,
  10. choices=self._meta['choices'],
  11. size=(-1, height),
  12. style=wx.LB_MULTIPLE
  13. )
  14. def setOptions(self, options):
  15. self.widget.Clear()
  16. for option in options:
  17. self.widget.Append(option)
  18. def setValue(self, values):
  19. for string in values:
  20. self.widget.SetStringSelection(string)
  21. def getWidgetValue(self):
  22. return [self.widget.GetString(index)
  23. for index in self.widget.GetSelections()]
  24. def formatOutput(self, metadata, value):
  25. return formatters.listbox(metadata, value)
  26. def getUiState(self) -> t.FormField:
  27. widget: wx.ComboBox = self.widget
  28. return t.Listbox(
  29. id=self._id,
  30. type=self.widgetInfo['type'],
  31. selected=self.getWidgetValue(),
  32. choices=self._meta['choices'],
  33. error=self.error.GetLabel() or None,
  34. enabled=self.IsEnabled(),
  35. visible=self.IsShown()
  36. )
  37. def syncUiState(self, state: t.Listbox): # type: ignore
  38. widget: wx.ComboBox = self.widget
  39. widget.Clear()
  40. widget.AppendItems(state.get('choices', []))
  41. for string in state['selected']:
  42. widget.SetStringSelection(string)
  43. self.error.SetLabel(state['error'] or '')
  44. self.error.Show(state['error'] is not None and state['error'] is not '')