X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/19a97bd6f98edc899ee0c3b2f2c4fe4ee8a0082b..258836fa259076b4bda6088fe653218645b2e26d:/wxPython/demo/wxProcess.py?ds=sidebyside diff --git a/wxPython/demo/wxProcess.py b/wxPython/demo/wxProcess.py index 1138651bc6..b9bd6ceb66 100644 --- a/wxPython/demo/wxProcess.py +++ b/wxPython/demo/wxProcess.py @@ -19,7 +19,7 @@ class TestPanel(wxPanel): # Make the controls prompt = wxStaticText(self, -1, 'Command line:') - self.cmd = wxTextCtrl(self, -1, 'python data/echo.py') + self.cmd = wxTextCtrl(self, -1, 'python -u data/echo.py') self.exBtn = wxButton(self, -1, 'Execute') self.out = wxTextCtrl(self, -1, '', style=wxTE_MULTILINE|wxTE_READONLY) @@ -27,9 +27,9 @@ class TestPanel(wxPanel): self.inp = wxTextCtrl(self, -1, '', style=wxTE_PROCESS_ENTER) self.sndBtn = wxButton(self, -1, 'Send') self.termBtn = wxButton(self, -1, 'Close Stream') - self.inp.Enable(false) - self.sndBtn.Enable(false) - self.termBtn.Enable(false) + self.inp.Enable(False) + self.sndBtn.Enable(False) + self.termBtn.Enable(False) # Hook up the events EVT_BUTTON(self, self.exBtn.GetId(), self.OnExecuteBtn) @@ -55,7 +55,7 @@ class TestPanel(wxPanel): sizer.Add(box2, 0, wxEXPAND|wxALL, 10) self.SetSizer(sizer) - self.SetAutoLayout(true) + self.SetAutoLayout(True) def __del__(self): @@ -70,14 +70,14 @@ class TestPanel(wxPanel): self.process = wxProcess(self) self.process.Redirect(); - pid = wxExecute(cmd, false, self.process) + pid = wxExecute(cmd, wxEXEC_ASYNC, self.process) self.log.write('OnExecuteBtn: "%s" pid: %s\n' % (cmd, pid)) - self.inp.Enable(true) - self.sndBtn.Enable(true) - self.termBtn.Enable(true) - self.cmd.Enable(false) - self.exBtn.Enable(false) + self.inp.Enable(True) + self.sndBtn.Enable(True) + self.termBtn.Enable(True) + self.cmd.Enable(False) + self.exBtn.Enable(False) self.inp.SetFocus() @@ -91,19 +91,15 @@ class TestPanel(wxPanel): def OnCloseStream(self, evt): self.log.write('OnCloseStream\n') - print "b4 CloseOutput" + #print "b4 CloseOutput" self.process.CloseOutput() - print "after CloseOutput" + #print "after CloseOutput" def OnIdle(self, evt): if self.process is not None: stream = self.process.GetInputStream() - # Yes, this is weird. For this particular stream, EOF - # simply means that there is no data available to be read, - # not truly the end of file. Also, read() just reads all - # the currently available data, not until the real EOF... - if not stream.eof(): + if stream.CanRead(): text = stream.read() self.out.AppendText(text) @@ -113,17 +109,17 @@ class TestPanel(wxPanel): (evt.GetPid(), evt.GetExitCode())) stream = self.process.GetInputStream() - if not stream.eof(): + if stream.CanRead(): text = stream.read() self.out.AppendText(text) self.process.Destroy() self.process = None - self.inp.Enable(false) - self.sndBtn.Enable(false) - self.termBtn.Enable(false) - self.cmd.Enable(true) - self.exBtn.Enable(true) + self.inp.Enable(False) + self.sndBtn.Enable(False) + self.termBtn.Enable(False) + self.cmd.Enable(True) + self.exBtn.Enable(True) #---------------------------------------------------------------------- @@ -156,3 +152,12 @@ child process to exit its main loop. """ + + + + + +if __name__ == '__main__': + import sys,os + import run + run.main(['', os.path.basename(sys.argv[0])])