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.

117 lines
3.3 KiB

  1. '''
  2. Created on Jan 19, 2014
  3. @author: Chris
  4. '''
  5. import os
  6. import sys
  7. import wx
  8. from gooey.gui.controller import Controller
  9. from gooey.gui.lang import i18n
  10. from gooey.gui.windows.runtime_display_panel import RuntimeDisplay
  11. from gooey.gui import styling, image_repository
  12. from gooey.gui.windows import footer, header
  13. class BaseWindow(wx.Frame):
  14. def __init__(self, BodyPanel, build_spec, params):
  15. wx.Frame.__init__(self, parent=None, id=-1)
  16. self._params = params
  17. self.build_spec = build_spec
  18. self._controller = None
  19. # Components
  20. self.icon = None
  21. self.head_panel = None
  22. self.config_panel = None
  23. self.runtime_display = None
  24. self.foot_panel = None
  25. self.panels = None
  26. self._init_properties()
  27. self._init_components(BodyPanel)
  28. self._do_layout()
  29. self._init_controller()
  30. self.registerControllers()
  31. self.Bind(wx.EVT_SIZE, self.onResize)
  32. def _init_properties(self):
  33. if not self._params['program_name']:
  34. title = os.path.basename(sys.argv[0].replace('.py', ''))
  35. else:
  36. title = self._params['program_name']
  37. self.SetTitle(title)
  38. self.SetSize(self.build_spec['default_size'])
  39. # self.SetMinSize((400, 300))
  40. self.icon = wx.Icon(image_repository.icon, wx.BITMAP_TYPE_ICO)
  41. self.SetIcon(self.icon)
  42. def _init_components(self, BodyPanel):
  43. # init gui
  44. _desc = self.build_spec['program_description']
  45. self.head_panel = header.FrameHeader(
  46. heading=i18n.translate("settings_title"),
  47. subheading=_desc or '',
  48. parent=self)
  49. self.config_panel = BodyPanel(self)
  50. self.runtime_display = RuntimeDisplay(self)
  51. self.foot_panel = footer.Footer(self, self._controller)
  52. self.panels = [self.head_panel, self.config_panel, self.foot_panel]
  53. def _do_layout(self):
  54. sizer = wx.BoxSizer(wx.VERTICAL)
  55. sizer.Add(self.head_panel, 0, wx.EXPAND)
  56. sizer.Add(styling.HorizontalRule(self), 0, wx.EXPAND)
  57. sizer.Add(self.config_panel, 1, wx.EXPAND)
  58. self.runtime_display.Hide()
  59. sizer.Add(self.runtime_display, 1, wx.EXPAND)
  60. sizer.Add(styling.HorizontalRule(self), 0, wx.EXPAND)
  61. sizer.Add(self.foot_panel, 0, wx.EXPAND)
  62. self.SetSizer(sizer)
  63. def _init_controller(self):
  64. self._controller = Controller(base_frame=self, build_spec=self.build_spec)
  65. def registerControllers(self):
  66. for panel in self.panels:
  67. panel.RegisterController(self._controller)
  68. def GetOptions(self):
  69. return self.config_panel.GetOptions()
  70. def GetRequiredArgs(self):
  71. return self.config_panel.GetRequiredArgs()
  72. def GetOptionalArgs(self):
  73. return self.config_panel.GetOptionalArgs()
  74. def NextPage(self):
  75. self.head_panel.NextPage()
  76. self.foot_panel.NextPage()
  77. self.config_panel.Hide()
  78. self.runtime_display.Show()
  79. self.Layout()
  80. # def AttachPayload(self, payload):
  81. # self._payload = payload
  82. def ManualStart(self):
  83. self._controller.ManualStart()
  84. def onResize(self, evt):
  85. evt.Skip()
  86. def PublishConsoleMsg(self, text):
  87. self.runtime_display.cmd_textbox.AppendText(text)
  88. # evt = MessageEvent(message=text)
  89. # self.GetEventHandler().ProcessEvent(evt)
  90. # wx.PostEvent(self.runtime_display, evt)
  91. if __name__ == '__main__':
  92. pass