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.

115 lines
2.7 KiB

  1. '''
  2. Created on Dec 8, 2013
  3. @author: Chris
  4. '''
  5. import os
  6. import sys
  7. import threading
  8. import wx
  9. from app.dialogs.controller import Controller
  10. from app.images import image_store
  11. from app.dialogs.header import FrameHeader
  12. from app.dialogs.basic_config_panel import RuntimeDisplay
  13. from app.dialogs.footer import Footer
  14. from gooey.gui.message_event import EVT_MSG
  15. class MessagePump(object):
  16. def __init__(self, queue):
  17. self.queue = queue
  18. self.stdout = sys.stdout
  19. # Overrides stdout's write method
  20. def write(self, text):
  21. if text != '':
  22. self.queue.put(text)
  23. class Listener(threading.Thread):
  24. def __init__(self, queue, textbox):
  25. threading.Thread.__init__(self)
  26. self.queue = queue
  27. self.update_text = lambda x: textbox.AppendText(x)
  28. def run(self):
  29. while True:
  30. try:
  31. stdout_msg = self.queue.get(timeout=1)
  32. if stdout_msg != '':
  33. self.update_text(stdout_msg)
  34. except Exception as e:
  35. pass # Timeout. Aint nobody care 'bout dat
  36. class MainWindow(wx.Frame):
  37. def __init__(self, queue, payload=None):
  38. wx.Frame.__init__(
  39. self,
  40. parent=None,
  41. id=-1,
  42. title=os.path.basename(__file__),
  43. size=(640, 480)
  44. )
  45. self._controller = Controller()
  46. self._init_properties()
  47. self._init_components()
  48. self._do_layout()
  49. self.queue = queue
  50. # the client's main function
  51. self._payload = payload
  52. _stdout = sys.stdout
  53. sys.stdout = MessagePump(queue)
  54. listener = Listener(queue, self.config_panel.cmd_textbox)
  55. listener.start()
  56. def _init_properties(self):
  57. self.SetMinSize((400, 300))
  58. self.icon = wx.Icon(image_store.icon, wx.BITMAP_TYPE_ICO)
  59. self.SetIcon(self.icon)
  60. def _init_components(self):
  61. # init gui
  62. self.head_panel = FrameHeader(image_path=image_store.computer3, parent=self, size=(30, 90))
  63. self.config_panel = RuntimeDisplay(parent=self)
  64. self.foot_panel = Footer(self, self._controller)
  65. def _do_layout(self):
  66. sizer = wx.BoxSizer(wx.VERTICAL)
  67. sizer.Add(self.head_panel, 0, wx.EXPAND)
  68. self._draw_horizontal_line(sizer)
  69. sizer.Add(self.config_panel, 1, wx.EXPAND)
  70. self._draw_horizontal_line(sizer)
  71. sizer.Add(self.foot_panel, 0, wx.EXPAND)
  72. self.SetSizer(sizer)
  73. self.Bind(EVT_MSG, self.OnMsg)
  74. def _init_panels(self):
  75. self._frame_header = FrameHeader
  76. self._basic_config_body = None
  77. self._adv_config_body = None
  78. self._config_footer = None
  79. self._output_footer = None
  80. def _draw_horizontal_line(self, sizer):
  81. line = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL)
  82. line.SetSize((10, 10))
  83. sizer.Add(line, 0, wx.EXPAND)