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.

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