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.

90 lines
2.7 KiB

  1. from collections import OrderedDict
  2. import wx
  3. from gooey.gui.pubsub import pub
  4. from gooey.gui import events
  5. from gooey.gui.windows.advanced_config import ConfigPanel
  6. from gooey.gui.windows.sidebar import Sidebar
  7. from gooey.gui.util import wx_util
  8. basic_config = {
  9. 'required': [{
  10. 'type': 'TextField',
  11. 'data': {
  12. 'display_name': 'Enter Commands',
  13. 'help': 'Enter command line arguments',
  14. 'nargs': '',
  15. 'commands': '',
  16. 'choices': [],
  17. }
  18. }],
  19. 'optional': []
  20. }
  21. class FlatLayout(wx.Panel):
  22. def __init__(self, *args, **kwargs):
  23. self._build_spec = kwargs.pop('build_spec')
  24. super(FlatLayout, self).__init__(*args, **kwargs)
  25. self.SetDoubleBuffered(True)
  26. self.main_content = ConfigPanel(self, widgets=self._build_spec['widgets'], opt_cols=self._build_spec['num_optional_cols'])
  27. sizer = wx.BoxSizer(wx.HORIZONTAL)
  28. sizer.Add(self.main_content, 3, wx.EXPAND)
  29. self.SetSizer(sizer)
  30. def GetOptions(self):
  31. return self.main_content.GetOptions()
  32. def GetRequiredArgs(self):
  33. return self.main_content.GetRequiredArgs()
  34. class ColumnLayout(wx.Panel):
  35. def __init__(self, *args, **kwargs):
  36. self._build_spec = kwargs.pop('build_spec')
  37. super(ColumnLayout, self).__init__(*args, **kwargs)
  38. self.SetDoubleBuffered(True)
  39. self.sidebar = Sidebar(self, contents=self._build_spec['widgets'].keys())
  40. self.config_panels = self.build_panels(self._build_spec)
  41. self.active_panel = self.config_panels.keys()[0]
  42. self.config_panels[self.active_panel].Show()
  43. sizer = wx.BoxSizer(wx.HORIZONTAL)
  44. sizer.Add(self.sidebar, 1, wx.EXPAND)
  45. sizer.Add(wx_util.vertical_rule(self), 0, wx.EXPAND)
  46. for panel in self.config_panels.values():
  47. sizer.Add(panel, 3, wx.EXPAND)
  48. self.SetSizer(sizer)
  49. pub.subscribe(self.load_view, events.PANEL_CHANGE)
  50. def load_view(self, view_name):
  51. self.config_panels[self.active_panel].Hide()
  52. self.config_panels[view_name].Show()
  53. self.active_panel = view_name
  54. self.Layout()
  55. def build_panels(self, build_spec):
  56. panels = OrderedDict()
  57. for panel_name in self._build_spec['widgets'].keys():
  58. panel = ConfigPanel(self, widgets=self._build_spec['widgets'][panel_name], opt_cols=self._build_spec['num_optional_cols'], title=panel_name.upper())
  59. panels[panel_name] = panel
  60. panel.Hide()
  61. return panels
  62. def GetOptions(self):
  63. return '{} {}'.format(self.active_panel, self.config_panels[self.active_panel].GetOptions())
  64. def GetRequiredArgs(self):
  65. return self.config_panels[self.active_panel].GetRequiredArgs()
  66. def get_layout_builder(layout_type):
  67. if layout_type == 'column':
  68. return