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.

76 lines
1.9 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, build_spec, **kwargs):
  18. wx.Panel.__init__(self, parent, **kwargs)
  19. self.build_spec = build_spec
  20. self._init_properties()
  21. self._init_components()
  22. self._do_layout()
  23. # self._HookStdout()
  24. def _init_properties(self):
  25. self.SetBackgroundColour('#F0F0F0')
  26. def _init_components(self):
  27. self.text = wx.StaticText(self, label=i18n._("status"))
  28. self.cmd_textbox = wx.TextCtrl(
  29. self, -1, "",
  30. style=wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH)
  31. if self.build_spec.get('monospace_display'):
  32. pointsize = self.cmd_textbox.GetFont().GetPointSize()
  33. font = wx.Font(pointsize, wx.FONTFAMILY_MODERN,
  34. wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_BOLD, False)
  35. self.cmd_textbox.SetFont(font)
  36. def _do_layout(self):
  37. sizer = wx.BoxSizer(wx.VERTICAL)
  38. sizer.AddSpacer(10)
  39. sizer.Add(self.text, 0, wx.LEFT, 30)
  40. sizer.AddSpacer(10)
  41. sizer.Add(self.cmd_textbox, 1, wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, 30)
  42. sizer.AddSpacer(20)
  43. self.SetSizer(sizer)
  44. self.Bind(EVT_MSG, self.OnMsg)
  45. def _HookStdout(self):
  46. _stdout = sys.stdout
  47. _stdout_write = _stdout.write
  48. sys.stdout = MessagePump()
  49. sys.stdout.write = self.WriteToDisplayBox
  50. def AppendText(self, txt):
  51. self.cmd_textbox.AppendText(txt)
  52. def WriteToDisplayBox(self, txt):
  53. if txt is not '':
  54. self.AppendText(txt)
  55. def OnMsg(self, evt):
  56. pass