I'm trying to subclass wx.Process
such that I have a customized process launcher that fires events back to the main thread with data collected from the stdout stream. Is this a good way of doing things?
class BuildProcess(wx.Process):
def __init__(self, cmd, notify=None):
wx.Process.__init__(self, notify)
print "Constructing a build process"
self.Bind(wx.EVT_IDLE, self.on_idle)
self.Redirect()
self.cmd = cmd
self.pid = None
def start(self):
print "Starting the process"
self.pid = wx.Execute(self.cmd, wx.EXEC_ASYNC, self)
print "Started."
def on_idle(self, evt):
print "doing the idle thing..."
stream = self.GetInputStream()
if stream.CanRead():
text = stream.read()
wx.PostEvent(self, BuildEvent(EVT_BUILD_UPDATE, self, data=text))
print text
def OnTerminate(self, *args, **kwargs):
wx.Process.OnTerminate(self, *args, **kwargs)
print "Terminating"
BuildEvent
here is a custom subclass of wx.PyEvent
. The process is starting, running, and terminating correctly, but my on_idle
function is never executing, even though I'm sure I've bound it to the idle event.