Browse Source

Removed thread listener by overwriting stdout's write method. added functions to RuntimeDisplay for updated the textbox

pull/1/head
Chris Kiehl 10 years ago
parent
commit
df49c358c9
3 changed files with 49 additions and 51 deletions
  1. 42
      src/app/dialogs/runtime_display_panel.py
  2. BIN
      src/app/images/image_store.pyc
  3. 58
      src/experiments/command.py

42
src/app/dialogs/runtime_display_panel.py

@ -11,31 +11,15 @@ import threading
from model.i18n import I18N
class MessagePump(object):
def __init__(self, queue):
self.queue = queue
def __init__(self):
# self.queue = queue
self.stdout = sys.stdout
# Overrides stdout's write method
def write(self, text):
if text != '':
self.queue.put(text)
raise NotImplementedError
class Listener(threading.Thread):
def __init__(self, queue, textbox):
threading.Thread.__init__(self)
self.queue = queue
self.update_text = lambda x: textbox.AppendText(x)
def run(self):
while True:
try:
stdout_msg = self.queue.get(timeout=1)
if stdout_msg != '':
self.update_text(stdout_msg)
except Exception as e:
pass # Timeout. Aint nobody care 'bout dat
class RuntimeDisplay(wx.Panel):
def __init__(self, parent, **kwargs):
wx.Panel.__init__(self, parent, **kwargs)
@ -46,11 +30,14 @@ class RuntimeDisplay(wx.Panel):
self._init_components()
self._do_layout()
self.queue = Queue.Queue()
# self.queue = Queue.Queue()
_stdout = sys.stdout
sys.stdout = MessagePump(self.queue)
listener = Listener(self.queue, self.cmd_textbox)
listener.start()
_stdout_write = _stdout.write
sys.stdout = MessagePump()
sys.stdout.write = self.WriteToDisplayBox
# listener = Listener(self.queue, self.cmd_textbox)
# listener.start()
def _init_properties(self):
self.SetBackgroundColour('#F0F0F0')
@ -69,4 +56,13 @@ class RuntimeDisplay(wx.Panel):
sizer.Add(self.cmd_textbox, 1, wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, 30)
sizer.AddSpacer(20)
self.SetSizer(sizer)
def AppendText(self, txt):
self.cmd_textbox.AppendText(txt)
def WriteToDisplayBox(self, txt):
if txt is not '':
self.AppendText(txt)

BIN
src/app/images/image_store.pyc

58
src/experiments/command.py

@ -1,38 +1,40 @@
'''
Created on Jan 7, 2014
@author: Chris
'''
import types
class Fooer(object):
def __init__(self):
self.a=1
self.b=2
self.c=3
def error(self, msg):
print msg
import sys
import time
class Barer(object):
def __init__(self):
self._fooer = Fooer()
def __getattr__(self, a):
return getattr(self._fooer, a)
_time = time.time
class Bazzer(object):
class MessagePump(object):
def __init__(self):
self._f = Fooer()
# self.queue = queue
self.stdout = sys.stdout
self.asdf = []
def error2(self, msg):
print 'HEY! I\'ve been patched!'
b = Barer()
b.error = types.MethodType(error2, b)
b.error('asdf')
# Overrides stdout's write method
def write(self, text):
self.asdf.append((text, _time()))
# if text != '':
# self.queue.put(text)
# self.queue = Queue.Queue()
_stdout = sys.stdout
sys.stdout = MessagePump()
# listener = Listener(self.queue, self.cmd_textbox)
# listener.start()
print 'hello!'
time.sleep(1)
print 'Jello!'
output = sys.stdout.asdf
sys.stdout = _stdout
for i in output:
print i
print _time()
Loading…
Cancel
Save