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.

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