Added wrappers for wxInputStream and the wxFileSystem family of

classes, contributed by Joerg Baumann

Added wxProcess, including ability to get streams for the child
process's stdio.

Updated the demo


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@8566 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2000-10-16 02:16:54 +00:00
parent ec76d0c268
commit 1f4952e59d
32 changed files with 5704 additions and 76 deletions

View File

@@ -40,19 +40,12 @@ demo item so you can learn how to use the classes yourself.</p>
</html>
'''
def __init__(self, parent):
wxDialog.__init__(self, parent, -1, 'About the wxPython demo',
size=wxSize(420, 380))
self.html = wxHtmlWindow(self, -1)
self.html.SetPage(self.text % wx.__version__)
self.SetAutoLayout(true)
lc = wxLayoutConstraints()
lc.top.SameAs(self, wxTop, 5)
lc.left.SameAs(self, wxLeft, 5)
lc.bottom.SameAs(self, wxBottom, 5)
lc.right.SameAs(self, wxRight, 5)
self.html.SetConstraints(lc)
self.Layout()
wxDialog.__init__(self, parent, -1, 'About the wxPython demo',)
html = wxHtmlWindow(self, -1, size=(420, -1))
html.SetPage(self.text % wx.__version__)
ir = html.GetInternalRepresentation()
html.SetSize( (ir.GetWidth(), ir.GetHeight()) )
self.SetClientSize(html.GetSize())
self.CentreOnParent(wxBOTH)
#---------------------------------------------------------------------------

View File

@@ -20,8 +20,8 @@ from wxPython.html import wxHtmlWindow
_treeList = [
#('New since last release', ['PyShellWindow',
# ]),
('New since last release', ['wxProcess',
]),
('Managed Windows', ['wxFrame', 'wxDialog', 'wxMiniFrame']),

View File

@@ -0,0 +1,25 @@
"""
This is a simple little echo program that is used by the wxProcess
demo. It reads lines from stdin and echos them back to stdout, until
there is an EOF on stdin.
Enter text in the field below to send to the stdin of the echo
process. Clicking on 'Close Stream' will close the stream in the
demo, and then echo.py should terminate too...
"""
import sys
sys.stdout.write( __doc__)
sys.stdout.flush()
line = sys.stdin.readline()
while line:
line = line[:-1]
sys.stdout.write('\nYou typed "%s"\n' % line)
sys.stdout.flush()
line = sys.stdin.readline()

132
wxPython/demo/wxProcess.py Normal file
View File

@@ -0,0 +1,132 @@
from wxPython.wx import *
#----------------------------------------------------------------------
class TestPanel(wxPanel):
def __init__(self, parent, ID, log):
wxPanel.__init__(self, parent, ID)
self.log = log
self.process = None
EVT_IDLE(self, self.OnIdle)
# We can either derive from wxProcess and override OnTerminate
# or we can let wxProcess send this window an event that is
# caught in the normal way...
EVT_END_PROCESS(self, -1, self.OnProcessEnded)
# Make the controls
prompt = wxStaticText(self, -1, 'Command line:')
self.cmd = wxTextCtrl(self, -1, 'python data/echo.py')
self.exBtn = wxButton(self, -1, 'Execute')
self.out = wxTextCtrl(self, -1, '', style=wxTE_MULTILINE|wxTE_READONLY)
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)
# Hook up the events
EVT_BUTTON(self, self.exBtn.GetId(), self.OnExecuteBtn)
EVT_BUTTON(self, self.sndBtn.GetId(), self.OnSendText)
EVT_BUTTON(self, self.termBtn.GetId(), self.OnCloseStream)
EVT_TEXT_ENTER(self, self.inp.GetId(), self.OnSendText)
# Do the layout
box1 = wxBoxSizer(wxHORIZONTAL)
box1.Add(prompt, 0, wxALIGN_CENTER)
box1.Add(self.cmd, 1, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5)
box1.Add(self.exBtn, 0)
box2 = wxBoxSizer(wxHORIZONTAL)
box2.Add(self.inp, 1, wxALIGN_CENTER)
box2.Add(self.sndBtn, 0, wxLEFT, 5)
box2.Add(self.termBtn, 0, wxLEFT, 5)
sizer = wxBoxSizer(wxVERTICAL)
sizer.Add(box1, 0, wxEXPAND|wxALL, 10)
sizer.Add(self.out, 1, wxEXPAND|wxALL, 10)
sizer.Add(box2, 0, wxEXPAND|wxALL, 10)
self.SetSizer(sizer)
self.SetAutoLayout(true)
def __del__(self):
if self.process is not None:
self.process.Detach()
self.process.CloseOutput()
def OnExecuteBtn(self, evt):
cmd = self.cmd.GetValue()
self.process = wxProcess(self)
self.process.Redirect();
pid = wxExecute(cmd, false, 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.SetFocus()
def OnSendText(self, evt):
text = self.inp.GetValue()
self.inp.SetValue('')
self.log.write('OnSendText: "%s"\n' % text)
self.process.GetOutputStream().write(text + '\n')
def OnCloseStream(self, evt):
self.log.write('OnCloseStream\n')
self.process.CloseOutput()
def OnIdle(self, evt):
if self.process is not None:
st = self.process.GetInputStream()
if not st.eof():
text = st.read()
self.out.AppendText(text)
def OnProcessEnded(self, evt):
self.log.write('OnProcessEnded, pid:%s, exitCode: %s\n' %
(evt.GetPid(), evt.GetExitCode()))
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)
#----------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, -1, log)
return win
#----------------------------------------------------------------------
overview = """\
<html><body>
<h2>wxProcess</h2>
blah blah blah...
</body><html>
"""