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.

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