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.

40 lines
1.2 KiB

2 years ago
2 years ago
2 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 Slider(TextContainer):
  6. """
  7. An integer input field
  8. """
  9. widget_class = wx.Slider
  10. def getWidget(self, *args, **options):
  11. widget = self.widget_class(self,
  12. minValue=self._options.get('min', 0),
  13. maxValue=self._options.get('max', 100),
  14. style=wx.SL_MIN_MAX_LABELS | wx.SL_VALUE_LABEL)
  15. return widget
  16. def getWidgetValue(self):
  17. return self.widget.GetValue()
  18. def setValue(self, value):
  19. self.widget.SetValue(value)
  20. def formatOutput(self, metatdata, value):
  21. return formatters.general(metatdata, str(value))
  22. def getUiState(self) -> t.FormField:
  23. widget: wx.Slider = self.widget
  24. return t.Slider(
  25. id=self._id,
  26. type=self.widgetInfo['type'],
  27. value=self.getWidgetValue(),
  28. min=widget.GetMin(),
  29. max=widget.GetMax(),
  30. error=self.error.GetLabel() or None,
  31. enabled=self.IsEnabled(),
  32. visible=self.IsShown()
  33. )