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.

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