This recipe takes a number of the concepts put forth earlier in this chapter, to create an OutputWindow
component that can be used to capture console output from a subprocess and redirect it to a text display in an application. It will use Thread
s and Timer
s to implement a high-performance solution to this task, so let's get started and take a look at the code.
Note
When run on Windows, this recipe makes use of the pywin32 extension module.(http://sourceforge.net/projects/pywin32/)
In this recipe, we will create two classes. The first will be a worker thread class that will run the subprocess
and report its output to the GUI. The second will be the GUI component that makes use of the worker thread and displays its output:
import wx import wx.stc as stc import threading import subprocess
The ProcessThread
class will run a subprocess
and read the process's output from its output pipe, and then pass the data back to the thread's parent
object:
class ProcessThread...