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.

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