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.

69 lines
1.5 KiB

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