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.

109 lines
3.2 KiB

  1. """
  2. Created on Dec 28, 2013
  3. @author: Chris
  4. """
  5. import wx
  6. from wx.lib.scrolledpanel import ScrolledPanel
  7. from gooey import i18n
  8. from gooey.gui.component_factory import ComponentFactory
  9. from gooey.gui.option_reader import OptionReader
  10. import styling
  11. PADDING = 10
  12. class AdvancedConfigPanel(ScrolledPanel, OptionReader):
  13. """
  14. Abstract class for the Footer panels.
  15. """
  16. def __init__(self, parent, action_groups=None, **kwargs):
  17. ScrolledPanel.__init__(self, parent, **kwargs)
  18. self.SetupScrolling()
  19. self._action_groups = action_groups
  20. self._positionals = len(action_groups._positionals) > 0
  21. self.components = ComponentFactory(action_groups)
  22. self._msg_req_args = None
  23. self._msg_opt_args = None
  24. self._controller = None
  25. self._init_components()
  26. self._do_layout()
  27. self.Bind(wx.EVT_SIZE, self.OnResize)
  28. def _init_components(self):
  29. self._msg_req_args = (styling.H1(self, i18n.translate("required_args_msg"))
  30. if self._positionals else None)
  31. self._msg_opt_args = styling.H1(self, i18n.translate("optional_args_msg"))
  32. def _do_layout(self):
  33. STD_LAYOUT = (0, wx.LEFT | wx.RIGHT | wx.EXPAND, PADDING)
  34. container = wx.BoxSizer(wx.VERTICAL)
  35. container.AddSpacer(15)
  36. if self._positionals:
  37. container.Add(self._msg_req_args, 0, wx.LEFT | wx.RIGHT, PADDING)
  38. container.AddSpacer(5)
  39. container.Add(styling.HorizontalRule(self), *STD_LAYOUT)
  40. container.AddSpacer(20)
  41. self.AddWidgets(container, self.components.required_args, add_space=True)
  42. container.AddSpacer(10)
  43. container.AddSpacer(10)
  44. container.Add(self._msg_opt_args, 0, wx.LEFT | wx.RIGHT, PADDING)
  45. container.AddSpacer(5)
  46. container.Add(styling.HorizontalRule(self), *STD_LAYOUT)
  47. container.AddSpacer(20)
  48. flag_grids = self.CreateComponentGrid(self.components.flags, cols=3, vgap=15)
  49. general_opts_grid = self.CreateComponentGrid(self.components.general_options)
  50. container.Add(general_opts_grid, *STD_LAYOUT)
  51. container.AddSpacer(30)
  52. container.Add(flag_grids, *STD_LAYOUT)
  53. self.SetSizer(container)
  54. def AddWidgets(self, sizer, components, add_space=False, padding=PADDING):
  55. for component in components:
  56. widget_group = component.Build(parent=self)
  57. sizer.Add(widget_group, 0, wx.LEFT | wx.RIGHT | wx.EXPAND, padding)
  58. if add_space:
  59. sizer.AddSpacer(8)
  60. def CreateComponentGrid(self, components, cols=2, vgap=10):
  61. gridsizer = wx.GridSizer(rows=0, cols=cols, vgap=vgap, hgap=4)
  62. self.AddWidgets(gridsizer, components)
  63. return gridsizer
  64. def OnResize(self, evt):
  65. for component in self.components:
  66. component.Update(evt.m_size)
  67. evt.Skip()
  68. def RegisterController(self, controller):
  69. if self._controller is None:
  70. self._controller = controller
  71. def GetOptions(self):
  72. """
  73. returns the collective values from all of the
  74. widgets contained in the panel"""
  75. values = [c.GetValue()
  76. for c in self.components
  77. if c.GetValue() is not None]
  78. return ' '.join(values)
  79. if __name__ == '__main__':
  80. pass