]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_process.i
reSWIGged
[wxWidgets.git] / wxPython / src / _process.i
CommitLineData
d14a1e28
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: _process.i
3// Purpose: SWIG interface stuff for wxProcess and wxExecute
4//
5// Author: Robin Dunn
6//
7// Created: 18-June-1999
8// RCS-ID: $Id$
9// Copyright: (c) 2003 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13// Not a %module
14
15
16//---------------------------------------------------------------------------
17%newgroup
18
19%{
81f5af11 20%}
d14a1e28
RD
21
22//---------------------------------------------------------------------------
23
24enum
25{
26 // no redirection
27 wxPROCESS_DEFAULT = 0,
28
29 // redirect the IO of the child process
30 wxPROCESS_REDIRECT = 1
31};
32
33enum wxKillError
34{
35 wxKILL_OK, // no error
36 wxKILL_BAD_SIGNAL, // no such signal
37 wxKILL_ACCESS_DENIED, // permission denied
38 wxKILL_NO_PROCESS, // no such process
39 wxKILL_ERROR // another, unspecified error
40};
41
c1718b2c
RD
42enum wxKillFlags
43{
44 wxKILL_NOCHILDREN = 0, // don't kill children
45 wxKILL_CHILDREN = 1 // kill children
46};
47
48
d14a1e28
RD
49enum wxSignal
50{
51 wxSIGNONE = 0, // verify if the process exists under Unix
52 wxSIGHUP,
53 wxSIGINT,
54 wxSIGQUIT,
55 wxSIGILL,
56 wxSIGTRAP,
57 wxSIGABRT,
58 wxSIGIOT = wxSIGABRT, // another name
59 wxSIGEMT,
60 wxSIGFPE,
61 wxSIGKILL,
62 wxSIGBUS,
63 wxSIGSEGV,
64 wxSIGSYS,
65 wxSIGPIPE,
66 wxSIGALRM,
67 wxSIGTERM
68
69 // further signals are different in meaning between different Unix systems
70};
71
72
73//---------------------------------------------------------------------------
74
75
76%{
77IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
78%}
79
80
1b8c7ba6
RD
81%rename(Process) wxPyProcess;
82class wxPyProcess : public wxEvtHandler {
d14a1e28
RD
83public:
84 // kill the process with the given PID
c1718b2c
RD
85 static wxKillError Kill(int pid,
86 wxSignal sig = wxSIGTERM,
87 int flags = wxKILL_NOCHILDREN);
d14a1e28
RD
88
89 // test if the given process exists
90 static bool Exists(int pid);
91
92 // this function replaces the standard popen() one: it launches a process
93 // asynchronously and allows the caller to get the streams connected to its
94 // std{in|out|err}
95 //
96 // on error NULL is returned, in any case the process object will be
97 // deleted automatically when the process terminates and should *not* be
98 // deleted by the caller
99 static wxPyProcess *Open(const wxString& cmd, int flags = wxEXEC_ASYNC);
100
101
c25f90f6 102 %pythonAppend wxPyProcess setCallbackInfo(Process) "; self.this.own(False)"
d14a1e28 103 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
8f514ab4
RD
104 ~wxPyProcess();
105
81f5af11
RD
106 void _setCallbackInfo(PyObject* self, PyObject* _class);
107
8f514ab4
RD
108
109 DocDeclStr(
110 long , GetPid() const,
111 "get the process ID of the process executed by Open()", "");
d14a1e28 112
d14a1e28 113
a7a01418
RD
114 void OnTerminate(int pid, int status);
115 %MAKE_BASE_FUNC(Process, OnTerminate);
81f5af11 116
d14a1e28
RD
117 // call Redirect before passing the object to wxExecute() to redirect the
118 // launched process stdin/stdout, then use GetInputStream() and
119 // GetOutputStream() to get access to them
120 void Redirect();
121 bool IsRedirected();
122
81f5af11 123
d14a1e28
RD
124 // detach from the parent - should be called by the parent if it's deleted
125 // before the process it started terminates
126 void Detach();
127
128 wxInputStream *GetInputStream();
129 wxInputStream *GetErrorStream();
130 wxOutputStream *GetOutputStream();
131
132 void CloseOutput();
133
dd9f7fea 134 // return True if the child process stdout is not closed
d14a1e28
RD
135 bool IsInputOpened() const;
136
dd9f7fea 137 // return True if any input is available on the child process stdout/err
d14a1e28
RD
138 bool IsInputAvailable() const;
139 bool IsErrorAvailable() const;
7012bb9f
RD
140
141 %property(ErrorStream, GetErrorStream, doc="See `GetErrorStream`");
142 %property(InputStream, GetInputStream, doc="See `GetInputStream`");
143 %property(OutputStream, GetOutputStream, doc="See `GetOutputStream`");
144
145 %property(InputOpened, IsInputOpened);
146 %property(InputAvailable, IsInputAvailable);
147 %property(ErrorAvailable, IsErrorAvailable);
d14a1e28
RD
148};
149
150//---------------------------------------------------------------------------
151
152
153class wxProcessEvent : public wxEvent {
154public:
155 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
156 int GetPid();
157 int GetExitCode();
158 int m_pid, m_exitcode;
81f5af11 159
7012bb9f
RD
160 %property(ExitCode, GetExitCode, doc="See `GetExitCode`");
161 %property(Pid, GetPid, doc="See `GetPid`");
d14a1e28
RD
162};
163
164
165%constant wxEventType wxEVT_END_PROCESS;
166
167%pythoncode {
168EVT_END_PROCESS = wx.PyEventBinder( wxEVT_END_PROCESS, 1 )
169}
170
171//---------------------------------------------------------------------------
172
173enum
174{
175 // execute the process asynchronously
176 wxEXEC_ASYNC = 0,
177
178 // execute it synchronously, i.e. wait until it finishes
179 wxEXEC_SYNC = 1,
180
181 // under Windows, don't hide the child even if it's IO is redirected (this
182 // is done by default)
183 wxEXEC_NOHIDE = 2,
184
185 // under Unix, if the process is the group leader then killing -pid kills
186 // all children as well as pid
9c7e3e86
RD
187 wxEXEC_MAKE_GROUP_LEADER = 4,
188
189 // by default synchronous execution disables all program windows to avoid
190 // that the user interacts with the program while the child process is
191 // running, you can use this flag to prevent this from happening
81f5af11 192 wxEXEC_NODISABLE = 8
d14a1e28
RD
193};
194
195
ab1f7d2a
RD
196MustHaveApp(wxExecute);
197
d14a1e28
RD
198long wxExecute(const wxString& command,
199 int flags = wxEXEC_ASYNC,
200 wxPyProcess *process = NULL);
201
202
c1718b2c
RD
203
204%typemap(in,numinputs=0) wxKillError* rc ( wxKillError temp ) { $1 = &temp; }
81f5af11 205%typemap(argout) wxKillError* rc
c1718b2c
RD
206{
207 PyObject* o;
208 o = PyInt_FromLong((long) (*$1));
214c4fbe 209#if SWIG_VERSION < 0x010328
c1718b2c 210 $result = t_output_helper($result, o);
214c4fbe
RD
211#else
212 $result = SWIG_Python_AppendOutput($result, o);
213#endif
c1718b2c
RD
214}
215
216int wxKill(long pid, wxSignal sig = wxSIGTERM, wxKillError* rc, int flags = wxKILL_NOCHILDREN);
217
218
d14a1e28
RD
219//---------------------------------------------------------------------------
220%init %{
221 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
222%}
223//---------------------------------------------------------------------------