wx.Process
stdout ストリームから収集されたデータを使用して、イベントをメイン スレッドに戻すカスタマイズされたプロセス ランチャーがあるようにサブクラス化しようとしています。これは物事を行う良い方法ですか?
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
これは のカスタム サブクラスですwx.PyEvent
。プロセスは正しく開始、実行、および終了していon_idle
ますが、idle イベントにバインドしたはずなのに、関数が実行されません。