author | lbessard |
Fri, 16 Nov 2007 17:40:18 +0100 | |
changeset 70 | 2767bc85aa9a |
parent 48 | 6b30cfee163e |
child 79 | ae06c2da83f7 |
permissions | -rw-r--r-- |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
3 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
4 |
#This file is part of Beremiz, a Integrated Development Environment for |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
5 |
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
6 |
# |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
8 |
# |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
9 |
#See COPYING file for copyrights details. |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
10 |
# |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
11 |
#This library is free software; you can redistribute it and/or |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
12 |
#modify it under the terms of the GNU General Public |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
13 |
#License as published by the Free Software Foundation; either |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
15 |
# |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
16 |
#This library is distributed in the hope that it will be useful, |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
19 |
#General Public License for more details. |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
20 |
# |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
21 |
#You should have received a copy of the GNU General Public |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
22 |
#License along with this library; if not, write to the Free Software |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
24 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
25 |
# |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
26 |
# based on wxPopen.py from boa-constructor |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
27 |
# |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
28 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
29 |
import time |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
30 |
from StringIO import StringIO |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
31 |
|
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
32 |
import wx |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
33 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
34 |
class ProcessRunnerMix: |
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
35 |
|
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
36 |
if wx.VERSION < (2, 6, 0): |
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
37 |
def Bind(self, event, function, id = None): |
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
38 |
if id is not None: |
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
39 |
event(self, id, function) |
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
40 |
else: |
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
41 |
event(self, function) |
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
42 |
|
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
43 |
def __init__(self, input, handler=None): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
44 |
if handler is None: |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
45 |
handler = self |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
46 |
self.handler = handler |
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
47 |
handler.Bind(wx.EVT_MENU, self.OnIdle) |
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
48 |
handler.Bind(wx.EVT_END_PROCESS, self.OnProcessEnded, id=-1) |
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
49 |
|
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
50 |
input.reverse() # so we can pop |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
51 |
self.input = input |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
52 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
53 |
self.reset() |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
54 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
55 |
def reset(self): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
56 |
self.process = None |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
57 |
self.pid = -1 |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
58 |
self.output = [] |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
59 |
self.errors = [] |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
60 |
self.inputStream = None |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
61 |
self.errorStream = None |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
62 |
self.outputStream = None |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
63 |
self.outputFunc = None |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
64 |
self.errorsFunc = None |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
65 |
self.finishedFunc = None |
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
66 |
self.finished = False |
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
67 |
self.responded = False |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
68 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
69 |
def execute(self, cmd): |
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
70 |
self.process = wx.Process(self.handler) |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
71 |
self.process.Redirect() |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
72 |
|
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
73 |
self.pid = wx.Execute(cmd, wx.EXEC_NOHIDE, self.process) |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
74 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
75 |
self.inputStream = self.process.GetOutputStream() |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
76 |
self.errorStream = self.process.GetErrorStream() |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
77 |
self.outputStream = self.process.GetInputStream() |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
78 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
79 |
#self.OnIdle() |
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
80 |
wx.WakeUpIdle() |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
81 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
82 |
def setCallbacks(self, output, errors, finished): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
83 |
self.outputFunc = output |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
84 |
self.errorsFunc = errors |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
85 |
self.finishedFunc = finished |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
86 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
87 |
def detach(self): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
88 |
if self.process is not None: |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
89 |
self.process.CloseOutput() |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
90 |
self.process.Detach() |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
91 |
self.process = None |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
92 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
93 |
def kill(self): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
94 |
if self.process is not None: |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
95 |
self.process.CloseOutput() |
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
96 |
if wx.Process_Kill(self.pid, wx.SIGTERM) != wx.KILL_OK: |
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
97 |
wx.Process_Kill(self.pid, wx.SIGKILL) |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
98 |
self.process = None |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
99 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
100 |
def updateStream(self, stream, data): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
101 |
if stream and stream.CanRead(): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
102 |
if not self.responded: |
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
103 |
self.responded = True |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
104 |
text = stream.read() |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
105 |
data.append(text) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
106 |
return text |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
107 |
else: |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
108 |
return None |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
109 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
110 |
def updateInpStream(self, stream, input): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
111 |
if stream and input: |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
112 |
line = input.pop() |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
113 |
stream.write(line) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
114 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
115 |
def updateErrStream(self, stream, data): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
116 |
return self.updateStream(stream, data) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
117 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
118 |
def updateOutStream(self, stream, data): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
119 |
return self.updateStream(stream, data) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
120 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
121 |
def OnIdle(self, event=None): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
122 |
if self.process is not None: |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
123 |
self.updateInpStream(self.inputStream, self.input) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
124 |
e = self.updateErrStream(self.errorStream, self.errors) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
125 |
if e is not None and self.errorsFunc is not None: |
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
126 |
wx.CallAfter(self.errorsFunc, e) |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
127 |
o = self.updateOutStream(self.outputStream, self.output) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
128 |
if o is not None and self.outputFunc is not None: |
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
129 |
wx.CallAfter(self.outputFunc, o) |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
130 |
|
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
131 |
#wx.WakeUpIdle() |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
132 |
#time.sleep(0.001) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
133 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
134 |
def OnProcessEnded(self, event): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
135 |
self.OnIdle() |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
136 |
pid,exitcode = event.GetPid(), event.GetExitCode() |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
137 |
if self.process: |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
138 |
self.process.Destroy() |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
139 |
self.process = None |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
140 |
|
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
141 |
self.finished = True |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
142 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
143 |
# XXX doesn't work ??? |
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
144 |
#self.handler.Disconnect(-1, wx.EVT_IDLE) |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
145 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
146 |
if self.finishedFunc: |
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
147 |
wx.CallAfter(self.finishedFunc, pid, exitcode) |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
148 |
|
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
149 |
class ProcessRunner(wx.EvtHandler, ProcessRunnerMix): |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
150 |
def __init__(self, input): |
70
2767bc85aa9a
Improve wxPopen to be compatible with wx2.6 and higher
lbessard
parents:
48
diff
changeset
|
151 |
wx.EvtHandler.__init__(self) |
48
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
152 |
ProcessRunnerMix.__init__(self, input) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
153 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
154 |
def wxPopen3(cmd, input, output, errors, finish, handler=None): |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
155 |
p = ProcessRunnerMix(input, handler) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
156 |
p.setCallbacks(output, errors, finish) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
157 |
p.execute(cmd) |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
158 |
return p |
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
159 |
|
6b30cfee163e
Enhanced and really multi-platform process logging. Use wxProcess and wxExecute instead of python popen3 (unix only).
etisserant
parents:
diff
changeset
|
160 |