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.

103 lines
3.0 KiB

  1. import wx
  2. from gooey.gui import formatters
  3. from gooey.gui.components.widgets.bases import TextContainer
  4. from gooey.gui.lang.i18n import _
  5. from gooey.gui.util import wx_util
  6. class CheckBox(TextContainer):
  7. widget_class = wx.CheckBox
  8. def arrange(self, *args, **kwargs):
  9. wx_util.make_bold(self.label)
  10. wx_util.withColor(self.label, self._options['label_color'])
  11. wx_util.withColor(self.help_text, self._options['help_color'])
  12. wx_util.withColor(self.error, self._options['error_color'])
  13. self.error.Hide()
  14. self.help_text.SetMinSize((0,-1))
  15. layout = wx.BoxSizer(wx.VERTICAL)
  16. layout.Add(self.label)
  17. layout.AddSpacer(2)
  18. layout.AddStretchSpacer(1)
  19. if self.help_text:
  20. hsizer = wx.BoxSizer(wx.HORIZONTAL)
  21. hsizer.Add(self.widget, 0)
  22. hsizer.Add(self.help_text, 1)
  23. layout.Add(hsizer, 1, wx.EXPAND)
  24. layout.AddSpacer(2)
  25. else:
  26. layout.Add(self.widget, 0, wx.EXPAND)
  27. layout.AddStretchSpacer(1)
  28. return layout
  29. def setValue(self, value):
  30. self.widget.SetValue(value)
  31. def getWidgetValue(self):
  32. return self.widget.GetValue()
  33. def formatOutput(self, metatdata, value):
  34. return formatters.checkbox(metatdata, value)
  35. def hideInput(self):
  36. self.widget.Hide()
  37. class BlockCheckbox(CheckBox):
  38. """
  39. A block style layout which places the help text in the normal
  40. location rather than inline next to the checkbox. A replacement label
  41. called `block_label` is shown next to the checkbox control.
  42. +-----------------+
  43. |label |
  44. |help_text |
  45. |[ ] block_label |
  46. +-----------------+
  47. This option tends to look better when there is a large amount of
  48. help text.
  49. """
  50. def arrange(self, *args, **kwargs):
  51. wx_util.make_bold(self.label)
  52. wx_util.withColor(self.label, self._options['label_color'])
  53. wx_util.withColor(self.help_text, self._options['help_color'])
  54. wx_util.withColor(self.error, self._options['error_color'])
  55. self.error.Hide()
  56. self.help_text.SetMinSize((0,-1))
  57. layout = wx.BoxSizer(wx.VERTICAL)
  58. if self._options.get('show_label', True):
  59. layout.Add(self.label, 0, wx.EXPAND)
  60. else:
  61. layout.AddStretchSpacer(1)
  62. layout.AddSpacer(2)
  63. if self.help_text and self._options.get('show_help', True):
  64. layout.Add(self.help_text, 1, wx.EXPAND)
  65. layout.AddSpacer(2)
  66. else:
  67. layout.AddStretchSpacer(1)
  68. layout.AddSpacer(2)
  69. block_label = self._options.get('checkbox_label', _('checkbox_label'))
  70. hsizer = wx.BoxSizer(wx.HORIZONTAL)
  71. hsizer.Add(self.widget, 0)
  72. hsizer.Add(wx.StaticText(self, label=block_label), 1)
  73. layout.Add(hsizer, 1, wx.EXPAND)
  74. layout.AddSpacer(2)
  75. return layout