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.

64 lines
1.4 KiB

  1. '''
  2. Created on Dec 23, 2013
  3. @author: Chris
  4. '''
  5. import sys
  6. import wx
  7. from gooey import i18n
  8. class MessagePump(object):
  9. def __init__(self):
  10. # self.queue = queue
  11. self.stdout = sys.stdout
  12. # Overrides stdout's write method
  13. def write(self, text):
  14. raise NotImplementedError
  15. class RuntimeDisplay(wx.Panel):
  16. def __init__(self, parent, **kwargs):
  17. wx.Panel.__init__(self, parent, **kwargs)
  18. self._init_properties()
  19. self._init_components()
  20. self._do_layout()
  21. self._HookStdout()
  22. def _init_properties(self):
  23. self.SetBackgroundColour('#F0F0F0')
  24. def _init_components(self):
  25. self.text = wx.StaticText(self, label=i18n.translate("status"))
  26. self.cmd_textbox = wx.TextCtrl(
  27. self, -1, "",
  28. style=wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH)
  29. def _do_layout(self):
  30. sizer = wx.BoxSizer(wx.VERTICAL)
  31. sizer.AddSpacer(10)
  32. sizer.Add(self.text, 0, wx.LEFT, 30)
  33. sizer.AddSpacer(10)
  34. sizer.Add(self.cmd_textbox, 1, wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, 30)
  35. sizer.AddSpacer(20)
  36. self.SetSizer(sizer)
  37. def _HookStdout(self):
  38. _stdout = sys.stdout
  39. _stdout_write = _stdout.write
  40. sys.stdout = MessagePump()
  41. sys.stdout.write = self.WriteToDisplayBox
  42. def AppendText(self, txt):
  43. self.cmd_textbox.AppendText(txt)
  44. def WriteToDisplayBox(self, txt):
  45. if txt is not '':
  46. self.AppendText(txt)