]>
Commit | Line | Data |
---|---|---|
7bf85405 RD |
1 | #---------------------------------------------------------------------------- |
2 | # Name: _extra.py | |
3 | # Purpose: This file is appended to the shadow class file generated | |
4 | # by SWIG. We add some unSWIGable things here. | |
5 | # | |
6 | # Author: Robin Dunn | |
7 | # | |
8 | # Created: 6/30/97 | |
9 | # RCS-ID: $Id$ | |
10 | # Copyright: (c) 1998 by Total Control Software | |
11 | # Licence: wxWindows license | |
12 | #---------------------------------------------------------------------------- | |
13 | ||
14 | import sys | |
15 | ||
16 | #---------------------------------------------------------------------- | |
17 | # This gives this module's dictionary to the C++ extension code... | |
18 | ||
19 | _wxSetDictionary(vars()) | |
20 | ||
21 | ||
22 | #---------------------------------------------------------------------- | |
23 | #---------------------------------------------------------------------- | |
24 | # Helper function to link python methods to wxWindows virtual | |
25 | # functions by name. | |
26 | ||
27 | def _checkForCallback(obj, name, event, theID=-1): | |
28 | try: cb = getattr(obj, name) | |
29 | except: pass | |
30 | else: obj.Connect(theID, -1, event, cb) | |
31 | ||
f6bcfd97 BP |
32 | ## def _StdWindowCallbacks(win): |
33 | ## _checkForCallback(win, "OnChar", wxEVT_CHAR) | |
34 | ## _checkForCallback(win, "OnSize", wxEVT_SIZE) | |
35 | ## _checkForCallback(win, "OnEraseBackground", wxEVT_ERASE_BACKGROUND) | |
36 | ## _checkForCallback(win, "OnSysColourChanged", wxEVT_SYS_COLOUR_CHANGED) | |
37 | ## _checkForCallback(win, "OnInitDialog", wxEVT_INIT_DIALOG) | |
38 | ## _checkForCallback(win, "OnPaint", wxEVT_PAINT) | |
39 | ## _checkForCallback(win, "OnIdle", wxEVT_IDLE) | |
40 | ||
41 | ||
42 | ## def _StdFrameCallbacks(win): | |
43 | ## _StdWindowCallbacks(win) | |
44 | ## _checkForCallback(win, "OnActivate", wxEVT_ACTIVATE) | |
45 | ## _checkForCallback(win, "OnMenuHighlight", wxEVT_MENU_HIGHLIGHT) | |
46 | ## _checkForCallback(win, "OnCloseWindow", wxEVT_CLOSE_WINDOW) | |
47 | ||
48 | ||
49 | ## def _StdDialogCallbacks(win): | |
50 | ## _StdWindowCallbacks(win) | |
51 | ## _checkForCallback(win, "OnOk", wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK) | |
52 | ## _checkForCallback(win, "OnApply", wxEVT_COMMAND_BUTTON_CLICKED, wxID_APPLY) | |
53 | ## _checkForCallback(win, "OnCancel", wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL) | |
54 | ## _checkForCallback(win, "OnCloseWindow", wxEVT_CLOSE_WINDOW) | |
55 | ## _checkForCallback(win, "OnCharHook", wxEVT_CHAR_HOOK) | |
56 | ||
57 | ||
58 | ## def _StdOnScrollCallbacks(win): | |
59 | ## try: cb = getattr(win, "OnScroll") | |
60 | ## except: pass | |
61 | ## else: EVT_SCROLL(win, cb) | |
7bf85405 RD |
62 | |
63 | ||
64 | ||
65 | #---------------------------------------------------------------------- | |
66 | #---------------------------------------------------------------------- | |
67 | # functions that look and act like the C++ Macros of the same name | |
68 | ||
69 | ||
70 | # Miscellaneous | |
71 | def EVT_SIZE(win, func): | |
72 | win.Connect(-1, -1, wxEVT_SIZE, func) | |
73 | ||
74 | def EVT_MOVE(win, func): | |
75 | win.Connect(-1, -1, wxEVT_MOVE, func) | |
76 | ||
77 | def EVT_CLOSE(win, func): | |
78 | win.Connect(-1, -1, wxEVT_CLOSE_WINDOW, func) | |
79 | ||
80 | def EVT_PAINT(win, func): | |
81 | win.Connect(-1, -1, wxEVT_PAINT, func) | |
82 | ||
83 | def EVT_ERASE_BACKGROUND(win, func): | |
84 | win.Connect(-1, -1, wxEVT_ERASE_BACKGROUND, func) | |
85 | ||
86 | def EVT_CHAR(win, func): | |
87 | win.Connect(-1, -1, wxEVT_CHAR, func) | |
88 | ||
89 | def EVT_CHAR_HOOK(win, func): | |
90 | win.Connect(-1, -1, wxEVT_CHAR_HOOK, func) | |
91 | ||
8bf5d46e RD |
92 | def EVT_KEY_DOWN(win, func): |
93 | win.Connect(-1, -1, wxEVT_KEY_DOWN, func) | |
94 | ||
95 | def EVT_KEY_UP(win, func): | |
96 | win.Connect(-1, -1, wxEVT_KEY_UP, func) | |
97 | ||
7bf85405 RD |
98 | def EVT_MENU_HIGHLIGHT(win, id, func): |
99 | win.Connect(id, -1, wxEVT_MENU_HIGHLIGHT, func) | |
100 | ||
101 | def EVT_MENU_HIGHLIGHT_ALL(win, func): | |
102 | win.Connect(-1, -1, wxEVT_MENU_HIGHLIGHT, func) | |
103 | ||
104 | def EVT_SET_FOCUS(win, func): | |
105 | win.Connect(-1, -1, wxEVT_SET_FOCUS, func) | |
106 | ||
107 | def EVT_KILL_FOCUS(win, func): | |
108 | win.Connect(-1, -1, wxEVT_KILL_FOCUS, func) | |
109 | ||
110 | def EVT_ACTIVATE(win, func): | |
111 | win.Connect(-1, -1, wxEVT_ACTIVATE, func) | |
112 | ||
113 | def EVT_ACTIVATE_APP(win, func): | |
114 | win.Connect(-1, -1, wxEVT_ACTIVATE_APP, func) | |
115 | ||
116 | def EVT_END_SESSION(win, func): | |
117 | win.Connect(-1, -1, wxEVT_END_SESSION, func) | |
118 | ||
119 | def EVT_QUERY_END_SESSION(win, func): | |
120 | win.Connect(-1, -1, wxEVT_QUERY_END_SESSION, func) | |
121 | ||
122 | def EVT_DROP_FILES(win, func): | |
123 | win.Connect(-1, -1, wxEVT_DROP_FILES, func) | |
124 | ||
125 | def EVT_INIT_DIALOG(win, func): | |
126 | win.Connect(-1, -1, wxEVT_INIT_DIALOG, func) | |
127 | ||
128 | def EVT_SYS_COLOUR_CHANGED(win, func): | |
129 | win.Connect(-1, -1, wxEVT_SYS_COLOUR_CHANGED, func) | |
130 | ||
131 | def EVT_SHOW(win, func): | |
132 | win.Connect(-1, -1, wxEVT_SHOW, func) | |
133 | ||
134 | def EVT_MAXIMIZE(win, func): | |
135 | win.Connect(-1, -1, wxEVT_MAXIMIZE, func) | |
136 | ||
137 | def EVT_ICONIZE(win, func): | |
138 | win.Connect(-1, -1, wxEVT_ICONIZE, func) | |
139 | ||
140 | def EVT_NAVIGATION_KEY(win, func): | |
141 | win.Connect(-1, -1, wxEVT_NAVIGATION_KEY, func) | |
142 | ||
3af4e610 RD |
143 | def EVT_PALETTE_CHANGED(win, func): |
144 | win.Connect(-1, -1, wxEVT_PALETTE_CHANGED, func) | |
145 | ||
146 | def EVT_QUERY_NEW_PALETTE(win, func): | |
147 | win.Connect(-1, -1, wxEVT_QUERY_NEW_PALETTE, func) | |
148 | ||
149 | def EVT_WINDOW_CREATE(win, func): | |
54b96882 | 150 | win.Connect(-1, -1, wxEVT_CREATE, func) |
3af4e610 RD |
151 | |
152 | def EVT_WINDOW_DESTROY(win, func): | |
54b96882 | 153 | win.Connect(-1, -1, wxEVT_DESTROY, func) |
3af4e610 RD |
154 | |
155 | ||
156 | ||
cf694132 RD |
157 | def EVT_IDLE(win, func): |
158 | win.Connect(-1, -1, wxEVT_IDLE, func) | |
159 | ||
bb0054cd RD |
160 | def EVT_UPDATE_UI(win, id, func): |
161 | win.Connect(id, -1, wxEVT_UPDATE_UI, func) | |
162 | ||
eb715945 RD |
163 | def EVT_UPDATE_UI_RANGE(win, id, id2, func): |
164 | win.Connect(id, id2, wxEVT_UPDATE_UI, func) | |
165 | ||
7bf85405 RD |
166 | |
167 | # Mouse Events | |
168 | def EVT_LEFT_DOWN(win, func): | |
169 | win.Connect(-1, -1, wxEVT_LEFT_DOWN, func) | |
170 | ||
171 | def EVT_LEFT_UP(win, func): | |
172 | win.Connect(-1, -1, wxEVT_LEFT_UP, func) | |
173 | ||
174 | def EVT_MIDDLE_DOWN(win, func): | |
175 | win.Connect(-1, -1, wxEVT_MIDDLE_DOWN, func) | |
176 | ||
177 | def EVT_MIDDLE_UP(win, func): | |
178 | win.Connect(-1, -1, wxEVT_MIDDLE_UP, func) | |
179 | ||
180 | def EVT_RIGHT_DOWN(win, func): | |
181 | win.Connect(-1, -1, wxEVT_RIGHT_DOWN, func) | |
182 | ||
183 | def EVT_RIGHT_UP(win, func): | |
184 | win.Connect(-1, -1, wxEVT_RIGHT_UP, func) | |
185 | ||
186 | def EVT_MOTION(win, func): | |
187 | win.Connect(-1, -1, wxEVT_MOTION, func) | |
188 | ||
189 | def EVT_LEFT_DCLICK(win, func): | |
190 | win.Connect(-1, -1, wxEVT_LEFT_DCLICK, func) | |
191 | ||
192 | def EVT_MIDDLE_DCLICK(win, func): | |
193 | win.Connect(-1, -1, wxEVT_MIDDLE_DCLICK, func) | |
194 | ||
195 | def EVT_RIGHT_DCLICK(win, func): | |
196 | win.Connect(-1, -1, wxEVT_RIGHT_DCLICK, func) | |
197 | ||
198 | def EVT_LEAVE_WINDOW(win, func): | |
199 | win.Connect(-1, -1, wxEVT_LEAVE_WINDOW, func) | |
200 | ||
201 | def EVT_ENTER_WINDOW(win, func): | |
202 | win.Connect(-1, -1, wxEVT_ENTER_WINDOW, func) | |
203 | ||
204 | ||
205 | # all mouse events | |
206 | def EVT_MOUSE_EVENTS(win, func): | |
207 | win.Connect(-1, -1, wxEVT_LEFT_DOWN, func) | |
208 | win.Connect(-1, -1, wxEVT_LEFT_UP, func) | |
209 | win.Connect(-1, -1, wxEVT_MIDDLE_DOWN, func) | |
210 | win.Connect(-1, -1, wxEVT_MIDDLE_UP, func) | |
211 | win.Connect(-1, -1, wxEVT_RIGHT_DOWN, func) | |
212 | win.Connect(-1, -1, wxEVT_RIGHT_UP, func) | |
213 | win.Connect(-1, -1, wxEVT_MOTION, func) | |
214 | win.Connect(-1, -1, wxEVT_LEFT_DCLICK, func) | |
215 | win.Connect(-1, -1, wxEVT_MIDDLE_DCLICK, func) | |
216 | win.Connect(-1, -1, wxEVT_RIGHT_DCLICK, func) | |
217 | win.Connect(-1, -1, wxEVT_LEAVE_WINDOW, func) | |
218 | win.Connect(-1, -1, wxEVT_ENTER_WINDOW, func) | |
219 | ||
220 | # EVT_COMMAND | |
221 | def EVT_COMMAND(win, id, cmd, func): | |
222 | win.Connect(id, -1, cmd, func) | |
223 | ||
224 | def EVT_COMMAND_RANGE(win, id1, id2, cmd, func): | |
225 | win.Connect(id1, id2, cmd, func) | |
226 | ||
26b9cf27 | 227 | |
7bf85405 RD |
228 | # Scrolling |
229 | def EVT_SCROLL(win, func): | |
230 | win.Connect(-1, -1, wxEVT_SCROLL_TOP, func) | |
231 | win.Connect(-1, -1, wxEVT_SCROLL_BOTTOM, func) | |
232 | win.Connect(-1, -1, wxEVT_SCROLL_LINEUP, func) | |
233 | win.Connect(-1, -1, wxEVT_SCROLL_LINEDOWN, func) | |
234 | win.Connect(-1, -1, wxEVT_SCROLL_PAGEUP, func) | |
235 | win.Connect(-1, -1, wxEVT_SCROLL_PAGEDOWN, func) | |
236 | win.Connect(-1, -1, wxEVT_SCROLL_THUMBTRACK,func) | |
26b9cf27 | 237 | win.Connect(-1, -1, wxEVT_SCROLL_THUMBRELEASE,func) |
7bf85405 RD |
238 | |
239 | def EVT_SCROLL_TOP(win, func): | |
240 | win.Connect(-1, -1, wxEVT_SCROLL_TOP, func) | |
241 | ||
242 | def EVT_SCROLL_BOTTOM(win, func): | |
243 | win.Connect(-1, -1, wxEVT_SCROLL_BOTTOM, func) | |
244 | ||
245 | def EVT_SCROLL_LINEUP(win, func): | |
246 | win.Connect(-1, -1, wxEVT_SCROLL_LINEUP, func) | |
247 | ||
248 | def EVT_SCROLL_LINEDOWN(win, func): | |
249 | win.Connect(-1, -1, wxEVT_SCROLL_LINEDOWN, func) | |
250 | ||
251 | def EVT_SCROLL_PAGEUP(win, func): | |
252 | win.Connect(-1, -1, wxEVT_SCROLL_PAGEUP, func) | |
253 | ||
254 | def EVT_SCROLL_PAGEDOWN(win, func): | |
255 | win.Connect(-1, -1, wxEVT_SCROLL_PAGEDOWN, func) | |
256 | ||
257 | def EVT_SCROLL_THUMBTRACK(win, func): | |
258 | win.Connect(-1, -1, wxEVT_SCROLL_THUMBTRACK, func) | |
259 | ||
26b9cf27 RD |
260 | def EVT_SCROLL_THUMBRELEASE(win, func): |
261 | win.Connect(-1, -1, wxEVT_SCROLL_THUMBRELEASE, func) | |
262 | ||
7bf85405 RD |
263 | |
264 | ||
265 | # Scrolling, with an id | |
266 | def EVT_COMMAND_SCROLL(win, id, func): | |
267 | win.Connect(id, -1, wxEVT_SCROLL_TOP, func) | |
268 | win.Connect(id, -1, wxEVT_SCROLL_BOTTOM, func) | |
269 | win.Connect(id, -1, wxEVT_SCROLL_LINEUP, func) | |
270 | win.Connect(id, -1, wxEVT_SCROLL_LINEDOWN, func) | |
271 | win.Connect(id, -1, wxEVT_SCROLL_PAGEUP, func) | |
272 | win.Connect(id, -1, wxEVT_SCROLL_PAGEDOWN, func) | |
273 | win.Connect(id, -1, wxEVT_SCROLL_THUMBTRACK,func) | |
26b9cf27 | 274 | win.Connect(id, -1, wxEVT_SCROLL_THUMBRELEASE,func) |
7bf85405 RD |
275 | |
276 | def EVT_COMMAND_SCROLL_TOP(win, id, func): | |
277 | win.Connect(id, -1, wxEVT_SCROLL_TOP, func) | |
278 | ||
279 | def EVT_COMMAND_SCROLL_BOTTOM(win, id, func): | |
280 | win.Connect(id, -1, wxEVT_SCROLL_BOTTOM, func) | |
281 | ||
282 | def EVT_COMMAND_SCROLL_LINEUP(win, id, func): | |
283 | win.Connect(id, -1, wxEVT_SCROLL_LINEUP, func) | |
284 | ||
285 | def EVT_COMMAND_SCROLL_LINEDOWN(win, id, func): | |
286 | win.Connect(id, -1, wxEVT_SCROLL_LINEDOWN, func) | |
287 | ||
288 | def EVT_COMMAND_SCROLL_PAGEUP(win, id, func): | |
289 | win.Connect(id, -1, wxEVT_SCROLL_PAGEUP, func) | |
290 | ||
291 | def EVT_COMMAND_SCROLL_PAGEDOWN(win, id, func): | |
292 | win.Connect(id, -1, wxEVT_SCROLL_PAGEDOWN, func) | |
293 | ||
294 | def EVT_COMMAND_SCROLL_THUMBTRACK(win, id, func): | |
295 | win.Connect(id, -1, wxEVT_SCROLL_THUMBTRACK, func) | |
296 | ||
26b9cf27 RD |
297 | def EVT_COMMAND_SCROLL_THUMBRELEASE(win, id, func): |
298 | win.Connect(id, -1, wxEVT_SCROLL_THUMBRELEASE, func) | |
299 | ||
d426c97e RD |
300 | #--- |
301 | def EVT_SCROLLWIN(win, func): | |
26b9cf27 RD |
302 | win.Connect(-1, -1, wxEVT_SCROLLWIN_TOP, func) |
303 | win.Connect(-1, -1, wxEVT_SCROLLWIN_BOTTOM, func) | |
304 | win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEUP, func) | |
305 | win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEDOWN, func) | |
306 | win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEUP, func) | |
307 | win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEDOWN, func) | |
308 | win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBTRACK, func) | |
309 | win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBRELEASE,func) | |
d426c97e RD |
310 | |
311 | def EVT_SCROLLWIN_TOP(win, func): | |
312 | win.Connect(-1, -1, wxEVT_SCROLLWIN_TOP, func) | |
313 | ||
314 | def EVT_SCROLLWIN_BOTTOM(win, func): | |
315 | win.Connect(-1, -1, wxEVT_SCROLLWIN_BOTTOM, func) | |
316 | ||
317 | def EVT_SCROLLWIN_LINEUP(win, func): | |
318 | win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEUP, func) | |
319 | ||
320 | def EVT_SCROLLWIN_LINEDOWN(win, func): | |
321 | win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEDOWN, func) | |
322 | ||
323 | def EVT_SCROLLWIN_PAGEUP(win, func): | |
324 | win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEUP, func) | |
325 | ||
326 | def EVT_SCROLLWIN_PAGEDOWN(win, func): | |
327 | win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEDOWN, func) | |
328 | ||
329 | def EVT_SCROLLWIN_THUMBTRACK(win, func): | |
330 | win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBTRACK, func) | |
331 | ||
26b9cf27 RD |
332 | def EVT_SCROLLWIN_THUMBRELEASE(win, func): |
333 | win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBRELEASE, func) | |
334 | ||
d426c97e RD |
335 | |
336 | ||
337 | # Scrolling, with an id | |
338 | def EVT_COMMAND_SCROLLWIN(win, id, func): | |
26b9cf27 RD |
339 | win.Connect(id, -1, wxEVT_SCROLLWIN_TOP, func) |
340 | win.Connect(id, -1, wxEVT_SCROLLWIN_BOTTOM, func) | |
341 | win.Connect(id, -1, wxEVT_SCROLLWIN_LINEUP, func) | |
342 | win.Connect(id, -1, wxEVT_SCROLLWIN_LINEDOWN, func) | |
343 | win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEUP, func) | |
344 | win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEDOWN, func) | |
345 | win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBTRACK, func) | |
346 | win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBRELEASE,func) | |
d426c97e RD |
347 | |
348 | def EVT_COMMAND_SCROLLWIN_TOP(win, id, func): | |
349 | win.Connect(id, -1, wxEVT_SCROLLWIN_TOP, func) | |
350 | ||
351 | def EVT_COMMAND_SCROLLWIN_BOTTOM(win, id, func): | |
352 | win.Connect(id, -1, wxEVT_SCROLLWIN_BOTTOM, func) | |
353 | ||
354 | def EVT_COMMAND_SCROLLWIN_LINEUP(win, id, func): | |
355 | win.Connect(id, -1, wxEVT_SCROLLWIN_LINEUP, func) | |
356 | ||
357 | def EVT_COMMAND_SCROLLWIN_LINEDOWN(win, id, func): | |
358 | win.Connect(id, -1, wxEVT_SCROLLWIN_LINEDOWN, func) | |
359 | ||
360 | def EVT_COMMAND_SCROLLWIN_PAGEUP(win, id, func): | |
361 | win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEUP, func) | |
362 | ||
363 | def EVT_COMMAND_SCROLLWIN_PAGEDOWN(win, id, func): | |
364 | win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEDOWN, func) | |
365 | ||
366 | def EVT_COMMAND_SCROLLWIN_THUMBTRACK(win, id, func): | |
367 | win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBTRACK, func) | |
7bf85405 | 368 | |
26b9cf27 RD |
369 | def EVT_COMMAND_SCROLLWIN_THUMBRELEASE(win, id, func): |
370 | win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBRELEASE, func) | |
371 | ||
372 | ||
7bf85405 RD |
373 | # Convenience commands |
374 | def EVT_BUTTON(win, id, func): | |
375 | win.Connect(id, -1, wxEVT_COMMAND_BUTTON_CLICKED, func) | |
376 | ||
377 | def EVT_CHECKBOX(win, id, func): | |
378 | win.Connect(id, -1, wxEVT_COMMAND_CHECKBOX_CLICKED, func) | |
379 | ||
380 | def EVT_CHOICE(win, id, func): | |
381 | win.Connect(id, -1, wxEVT_COMMAND_CHOICE_SELECTED, func) | |
382 | ||
383 | def EVT_LISTBOX(win, id, func): | |
384 | win.Connect(id, -1, wxEVT_COMMAND_LISTBOX_SELECTED, func) | |
385 | ||
386 | def EVT_LISTBOX_DCLICK(win, id, func): | |
387 | win.Connect(id, -1, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, func) | |
388 | ||
389 | def EVT_TEXT(win, id, func): | |
390 | win.Connect(id, -1, wxEVT_COMMAND_TEXT_UPDATED, func) | |
391 | ||
392 | def EVT_TEXT_ENTER(win, id, func): | |
393 | win.Connect(id, -1, wxEVT_COMMAND_TEXT_ENTER, func) | |
394 | ||
395 | def EVT_MENU(win, id, func): | |
396 | win.Connect(id, -1, wxEVT_COMMAND_MENU_SELECTED, func) | |
397 | ||
398 | def EVT_MENU_RANGE(win, id1, id2, func): | |
399 | win.Connect(id1, id2, wxEVT_COMMAND_MENU_SELECTED, func) | |
400 | ||
401 | def EVT_SLIDER(win, id, func): | |
402 | win.Connect(id, -1, wxEVT_COMMAND_SLIDER_UPDATED, func) | |
403 | ||
404 | def EVT_RADIOBOX(win, id, func): | |
405 | win.Connect(id, -1, wxEVT_COMMAND_RADIOBOX_SELECTED, func) | |
406 | ||
407 | def EVT_RADIOBUTTON(win, id, func): | |
408 | win.Connect(id, -1, wxEVT_COMMAND_RADIOBUTTON_SELECTED, func) | |
409 | ||
410 | def EVT_VLBOX(win, id, func): | |
411 | win.Connect(id, -1, wxEVT_COMMAND_VLBOX_SELECTED, func) | |
412 | ||
413 | def EVT_COMBOBOX(win, id, func): | |
414 | win.Connect(id, -1, wxEVT_COMMAND_COMBOBOX_SELECTED, func) | |
415 | ||
416 | def EVT_TOOL(win, id, func): | |
417 | win.Connect(id, -1, wxEVT_COMMAND_TOOL_CLICKED, func) | |
418 | ||
3af4e610 RD |
419 | def EVT_TOOL_RANGE(win, id, id2, func): |
420 | win.Connect(id, id2, wxEVT_COMMAND_TOOL_CLICKED, func) | |
421 | ||
7bf85405 RD |
422 | def EVT_TOOL_RCLICKED(win, id, func): |
423 | win.Connect(id, -1, wxEVT_COMMAND_TOOL_RCLICKED, func) | |
424 | ||
3af4e610 RD |
425 | def EVT_TOOL_RCLICKED_RANGE(win, id, id2, func): |
426 | win.Connect(id, id2, wxEVT_COMMAND_TOOL_RCLICKED, func) | |
427 | ||
7bf85405 RD |
428 | def EVT_TOOL_ENTER(win, id, func): |
429 | win.Connect(id, -1, wxEVT_COMMAND_TOOL_ENTER, func) | |
430 | ||
431 | def EVT_CHECKLISTBOX(win, id, func): | |
432 | win.Connect(id, -1, wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, func) | |
433 | ||
3af4e610 RD |
434 | def EVT_SPINCTRL(win, id, func): |
435 | win.Connect(id, -1, wxEVT_COMMAND_SPINCTRL_UPDATED, func) | |
436 | ||
437 | ||
7bf85405 RD |
438 | |
439 | # Generic command events | |
440 | ||
441 | def EVT_COMMAND_LEFT_CLICK(win, id, func): | |
442 | win.Connect(id, -1, wxEVT_COMMAND_LEFT_CLICK, func) | |
443 | ||
444 | def EVT_COMMAND_LEFT_DCLICK(win, id, func): | |
445 | win.Connect(id, -1, wxEVT_COMMAND_LEFT_DCLICK, func) | |
446 | ||
447 | def EVT_COMMAND_RIGHT_CLICK(win, id, func): | |
448 | win.Connect(id, -1, wxEVT_COMMAND_RIGHT_CLICK, func) | |
449 | ||
450 | def EVT_COMMAND_RIGHT_DCLICK(win, id, func): | |
451 | win.Connect(id, -1, wxEVT_COMMAND_RIGHT_DCLICK, func) | |
452 | ||
453 | def EVT_COMMAND_SET_FOCUS(win, id, func): | |
454 | win.Connect(id, -1, wxEVT_COMMAND_SET_FOCUS, func) | |
455 | ||
456 | def EVT_COMMAND_KILL_FOCUS(win, id, func): | |
457 | win.Connect(id, -1, wxEVT_COMMAND_KILL_FOCUS, func) | |
458 | ||
459 | def EVT_COMMAND_ENTER(win, id, func): | |
460 | win.Connect(id, -1, wxEVT_COMMAND_ENTER, func) | |
461 | ||
462 | ||
d5c9047a | 463 | # wxNotebook events |
7bf85405 RD |
464 | def EVT_NOTEBOOK_PAGE_CHANGED(win, id, func): |
465 | win.Connect(id, -1, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, func) | |
466 | ||
467 | def EVT_NOTEBOOK_PAGE_CHANGING(win, id, func): | |
468 | win.Connect(id, -1, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, func) | |
469 | ||
470 | ||
b639c3c5 | 471 | # wxTreeCtrl events |
d5c9047a | 472 | def EVT_TREE_BEGIN_DRAG(win, id, func): |
4d1d77e8 | 473 | win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func) |
d5c9047a RD |
474 | |
475 | def EVT_TREE_BEGIN_RDRAG(win, id, func): | |
4d1d77e8 | 476 | win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func) |
d5c9047a RD |
477 | |
478 | def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func): | |
4d1d77e8 | 479 | win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func) |
d5c9047a RD |
480 | |
481 | def EVT_TREE_END_LABEL_EDIT(win, id, func): | |
4d1d77e8 | 482 | win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func) |
d5c9047a RD |
483 | |
484 | def EVT_TREE_GET_INFO(win, id, func): | |
4d1d77e8 | 485 | win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func) |
d5c9047a RD |
486 | |
487 | def EVT_TREE_SET_INFO(win, id, func): | |
4d1d77e8 | 488 | win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func) |
d5c9047a RD |
489 | |
490 | def EVT_TREE_ITEM_EXPANDED(win, id, func): | |
4d1d77e8 | 491 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func) |
d5c9047a RD |
492 | |
493 | def EVT_TREE_ITEM_EXPANDING(win, id, func): | |
4d1d77e8 | 494 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func) |
d5c9047a RD |
495 | |
496 | def EVT_TREE_ITEM_COLLAPSED(win, id, func): | |
4d1d77e8 | 497 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func) |
d5c9047a RD |
498 | |
499 | def EVT_TREE_ITEM_COLLAPSING(win, id, func): | |
4d1d77e8 | 500 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func) |
d5c9047a RD |
501 | |
502 | def EVT_TREE_SEL_CHANGED(win, id, func): | |
4d1d77e8 | 503 | win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func) |
d5c9047a RD |
504 | |
505 | def EVT_TREE_SEL_CHANGING(win, id, func): | |
4d1d77e8 | 506 | win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func) |
d5c9047a RD |
507 | |
508 | def EVT_TREE_KEY_DOWN(win, id, func): | |
4d1d77e8 | 509 | win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func) |
d5c9047a RD |
510 | |
511 | def EVT_TREE_DELETE_ITEM(win, id, func): | |
4d1d77e8 | 512 | win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func) |
d5c9047a | 513 | |
2abc0a0f RD |
514 | def EVT_TREE_ITEM_ACTIVATED(win, id, func): |
515 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func) | |
516 | ||
517 | def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func): | |
518 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func) | |
519 | ||
520 | def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func): | |
521 | win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func) | |
522 | ||
d5c9047a | 523 | |
b639c3c5 | 524 | # wxSpinButton |
62bd0874 RD |
525 | def EVT_SPIN_UP(win, id, func): |
526 | win.Connect(id, -1, wxEVT_SCROLL_LINEUP, func) | |
527 | ||
528 | def EVT_SPIN_DOWN(win, id, func): | |
f6bcfd97 | 529 | win.Connect(id, -1, wxEVT_SCROLL_LINEDOWN, func) |
62bd0874 RD |
530 | |
531 | def EVT_SPIN(win, id, func): | |
62bd0874 RD |
532 | win.Connect(id, -1, wxEVT_SCROLL_THUMBTRACK,func) |
533 | ||
534 | ||
7bf85405 | 535 | |
b639c3c5 RD |
536 | |
537 | # wxTaskBarIcon | |
538 | def EVT_TASKBAR_MOVE(win, func): | |
539 | win.Connect(-1, -1, wxEVT_TASKBAR_MOVE, func) | |
540 | ||
541 | def EVT_TASKBAR_LEFT_DOWN(win, func): | |
542 | win.Connect(-1, -1, wxEVT_TASKBAR_LEFT_DOWN, func) | |
543 | ||
544 | def EVT_TASKBAR_LEFT_UP(win, func): | |
545 | win.Connect(-1, -1, wxEVT_TASKBAR_LEFT_UP, func) | |
546 | ||
547 | def EVT_TASKBAR_RIGHT_DOWN(win, func): | |
548 | win.Connect(-1, -1, wxEVT_TASKBAR_RIGHT_DOWN, func) | |
549 | ||
550 | def EVT_TASKBAR_RIGHT_UP(win, func): | |
551 | win.Connect(-1, -1, wxEVT_TASKBAR_RIGHT_UP, func) | |
552 | ||
553 | def EVT_TASKBAR_LEFT_DCLICK(win, func): | |
554 | win.Connect(-1, -1, wxEVT_TASKBAR_LEFT_DCLICK, func) | |
555 | ||
556 | def EVT_TASKBAR_RIGHT_DCLICK(win, func): | |
557 | win.Connect(-1, -1, wxEVT_TASKBAR_RIGHT_DCLICK, func) | |
558 | ||
559 | ||
f6bcfd97 BP |
560 | ## # wxGrid *** THE OLD ONE *** |
561 | ## def EVT_GRID_SELECT_CELL(win, fn): | |
562 | ## win.Connect(-1, -1, wxEVT_GRID_SELECT_CELL, fn) | |
b639c3c5 | 563 | |
f6bcfd97 BP |
564 | ## def EVT_GRID_CREATE_CELL(win, fn): |
565 | ## win.Connect(-1, -1, wxEVT_GRID_CREATE_CELL, fn) | |
b639c3c5 | 566 | |
f6bcfd97 BP |
567 | ## def EVT_GRID_CHANGE_LABELS(win, fn): |
568 | ## win.Connect(-1, -1, wxEVT_GRID_CHANGE_LABELS, fn) | |
b639c3c5 | 569 | |
f6bcfd97 BP |
570 | ## def EVT_GRID_CHANGE_SEL_LABEL(win, fn): |
571 | ## win.Connect(-1, -1, wxEVT_GRID_CHANGE_SEL_LABEL, fn) | |
b639c3c5 | 572 | |
f6bcfd97 BP |
573 | ## def EVT_GRID_CELL_CHANGE(win, fn): |
574 | ## win.Connect(-1, -1, wxEVT_GRID_CELL_CHANGE, fn) | |
b639c3c5 | 575 | |
f6bcfd97 BP |
576 | ## def EVT_GRID_CELL_LCLICK(win, fn): |
577 | ## win.Connect(-1, -1, wxEVT_GRID_CELL_LCLICK, fn) | |
b639c3c5 | 578 | |
f6bcfd97 BP |
579 | ## def EVT_GRID_CELL_RCLICK(win, fn): |
580 | ## win.Connect(-1, -1, wxEVT_GRID_CELL_RCLICK, fn) | |
b639c3c5 | 581 | |
f6bcfd97 BP |
582 | ## def EVT_GRID_LABEL_LCLICK(win, fn): |
583 | ## win.Connect(-1, -1, wxEVT_GRID_LABEL_LCLICK, fn) | |
b639c3c5 | 584 | |
f6bcfd97 BP |
585 | ## def EVT_GRID_LABEL_RCLICK(win, fn): |
586 | ## win.Connect(-1, -1, wxEVT_GRID_LABEL_RCLICK, fn) | |
b639c3c5 RD |
587 | |
588 | ||
08127323 RD |
589 | # wxSashWindow |
590 | def EVT_SASH_DRAGGED(win, id, func): | |
591 | win.Connect(id, -1, wxEVT_SASH_DRAGGED, func) | |
592 | ||
593 | def EVT_SASH_DRAGGED_RANGE(win, id1, id2, func): | |
594 | win.Connect(id1, id2, wxEVT_SASH_DRAGGED, func) | |
595 | ||
596 | def EVT_QUERY_LAYOUT_INFO(win, func): | |
597 | win.Connect(-1, -1, wxEVT_EVT_QUERY_LAYOUT_INFO, func) | |
598 | ||
599 | def EVT_CALCULATE_LAYOUT(win, func): | |
600 | win.Connect(-1, -1, wxEVT_EVT_CALCULATE_LAYOUT, func) | |
601 | ||
602 | ||
73c5ed36 RD |
603 | # wxListCtrl |
604 | def EVT_LIST_BEGIN_DRAG(win, id, func): | |
605 | win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_DRAG, func) | |
606 | ||
607 | def EVT_LIST_BEGIN_RDRAG(win, id, func): | |
608 | win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_RDRAG, func) | |
609 | ||
610 | def EVT_LIST_BEGIN_LABEL_EDIT(win, id, func): | |
611 | win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, func) | |
612 | ||
613 | def EVT_LIST_END_LABEL_EDIT(win, id, func): | |
614 | win.Connect(id, -1, wxEVT_COMMAND_LIST_END_LABEL_EDIT, func) | |
615 | ||
616 | def EVT_LIST_DELETE_ITEM(win, id, func): | |
617 | win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ITEM, func) | |
618 | ||
619 | def EVT_LIST_DELETE_ALL_ITEMS(win, id, func): | |
620 | win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, func) | |
621 | ||
622 | def EVT_LIST_GET_INFO(win, id, func): | |
623 | win.Connect(id, -1, wxEVT_COMMAND_LIST_GET_INFO, func) | |
624 | ||
625 | def EVT_LIST_SET_INFO(win, id, func): | |
626 | win.Connect(id, -1, wxEVT_COMMAND_LIST_SET_INFO, func) | |
627 | ||
628 | def EVT_LIST_ITEM_SELECTED(win, id, func): | |
629 | win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_SELECTED, func) | |
630 | ||
631 | def EVT_LIST_ITEM_DESELECTED(win, id, func): | |
632 | win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_DESELECTED, func) | |
633 | ||
634 | def EVT_LIST_KEY_DOWN(win, id, func): | |
635 | win.Connect(id, -1, wxEVT_COMMAND_LIST_KEY_DOWN, func) | |
636 | ||
637 | def EVT_LIST_INSERT_ITEM(win, id, func): | |
638 | win.Connect(id, -1, wxEVT_COMMAND_LIST_INSERT_ITEM, func) | |
639 | ||
640 | def EVT_LIST_COL_CLICK(win, id, func): | |
641 | win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_CLICK, func) | |
b639c3c5 | 642 | |
2f90df85 RD |
643 | def EVT_LIST_ITEM_RIGHT_CLICK(win, id, func): |
644 | win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, func) | |
645 | ||
646 | def EVT_LIST_ITEM_MIDDLE_CLICK(win, id, func): | |
647 | win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, func) | |
648 | ||
c368d904 RD |
649 | def EVT_LIST_ITEM_ACTIVATED(win, id, func): |
650 | win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED, func) | |
651 | ||
652 | ||
2f90df85 RD |
653 | |
654 | ||
bb0054cd RD |
655 | #wxSplitterWindow |
656 | def EVT_SPLITTER_SASH_POS_CHANGING(win, id, func): | |
657 | win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, func) | |
658 | ||
659 | def EVT_SPLITTER_SASH_POS_CHANGED(win, id, func): | |
660 | win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, func) | |
661 | ||
662 | def EVT_SPLITTER_UNSPLIT(win, id, func): | |
663 | win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_UNSPLIT, func) | |
664 | ||
665 | def EVT_SPLITTER_DOUBLECLICKED(win, id, func): | |
666 | win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, func) | |
667 | ||
b639c3c5 | 668 | |
f6bcfd97 BP |
669 | # wxTimer |
670 | def EVT_TIMER(win, id, func): | |
671 | win.Connect(id, -1, wxEVT_TIMER, func) | |
672 | ||
c368d904 RD |
673 | # wxProcess |
674 | def EVT_END_PROCESS(eh, id, func): | |
675 | eh.Connect(id, -1, wxEVT_END_PROCESS, func) | |
f6bcfd97 | 676 | |
185d7c3e RD |
677 | |
678 | # wxJoyStick | |
679 | def EVT_JOY_DOWN(win, func): | |
680 | win.Connect(-1, -1, wxEVT_JOY_DOWN, func) | |
681 | ||
682 | def EVT_JOY_UP(win, func): | |
683 | win.Connect(-1, -1, wxEVT_JOY_UP, func) | |
684 | ||
685 | def EVT_JOY_MOVE(win, func): | |
686 | win.Connect(-1, -1, wxEVT_JOY_MOVE, func) | |
687 | ||
688 | def EVT_JOY_ZMOVE(win, func): | |
689 | win.Connect(-1, -1, wxEVT_JOY_ZMOVE, func) | |
690 | ||
691 | def EVT_JOYSTICK_EVENTS(win, func): | |
692 | win.Connect(-1, -1, wxEVT_JOY_DOWN, func) | |
693 | win.Connect(-1, -1, wxEVT_JOY_UP, func) | |
694 | win.Connect(-1, -1, wxEVT_JOY_MOVE, func) | |
695 | win.Connect(-1, -1, wxEVT_JOY_ZMOVE, func) | |
696 | ||
9c039d08 | 697 | #---------------------------------------------------------------------- |
7bf85405 RD |
698 | |
699 | class wxTimer(wxPyTimer): | |
185d7c3e RD |
700 | def __init__(self, evtHandler = None, id = -1): |
701 | if evtHandler is None: | |
702 | wxPyTimer.__init__(self, self.Notify) # derived class must provide | |
703 | # Notify(self) method. | |
704 | else: | |
705 | wxPyTimer.__init__(self, None) | |
706 | self.SetOwner(evtHandler, id) | |
7bf85405 RD |
707 | |
708 | #---------------------------------------------------------------------- | |
709 | # Some wxWin methods can take "NULL" as parameters, but the shadow classes | |
710 | # expect an object with the SWIG pointer as a 'this' member. This class | |
711 | # and instance fools the shadow into passing the NULL pointer. | |
712 | ||
185d7c3e RD |
713 | ## NOTE: This is not needed anymore as None can be passed instead and |
714 | # will be interpreted as NULL. | |
715 | ||
716 | class _NullObj: | |
7bf85405 RD |
717 | this = 'NULL' # SWIG converts this to (void*)0 |
718 | ||
185d7c3e | 719 | NULL = _NullObj() |
7bf85405 RD |
720 | |
721 | ||
722 | #---------------------------------------------------------------------- | |
723 | # aliases | |
724 | ||
b639c3c5 | 725 | wxColor = wxColour |
7bf85405 RD |
726 | wxNamedColor = wxNamedColour |
727 | ||
728 | wxPyDefaultPosition.Set(-1,-1) | |
729 | wxPyDefaultSize.Set(-1,-1) | |
08127323 | 730 | |
f2cb3be9 | 731 | # aliases so that C++ documentation applies: |
2f90df85 RD |
732 | wxDefaultPosition = wxPyDefaultPosition |
733 | wxDefaultSize = wxPyDefaultSize | |
af309447 | 734 | |
6999b0d8 RD |
735 | # backwards compatibility |
736 | wxNoRefBitmap = wxBitmap | |
af309447 | 737 | |
8bf5d46e RD |
738 | #---------------------------------------------------------------------- |
739 | # This helper function will take a wxPython object and convert it to | |
740 | # another wxPython object type. This will not be able to create objects | |
7bcd390c | 741 | # that are derived from wxPython classes by the user, only those that are |
8bf5d46e RD |
742 | # actually part of wxPython and directly corespond to C++ objects. |
743 | # | |
744 | # This is useful in situations where some method returns a generic | |
745 | # type such as wxWindow, but you know that it is actually some | |
746 | # derived type such as a wxTextCtrl. You can't call wxTextCtrl specific | |
747 | # methods on a wxWindow object, but you can use this function to | |
748 | # create a wxTextCtrl object that will pass the same pointer to | |
749 | # the C++ code. You use it like this: | |
750 | # | |
751 | # textCtrl = wxPyTypeCast(window, "wxTextCtrl") | |
752 | # | |
753 | # | |
754 | # WARNING: Using this function to type cast objects into types that | |
755 | # they are not is not recommended and is likely to cause your | |
756 | # program to crash... Hard. | |
757 | # | |
758 | ||
759 | def wxPyTypeCast(obj, typeStr): | |
760 | if hasattr(obj, "this"): | |
761 | newPtr = ptrcast(obj.this, typeStr+"_p") | |
762 | else: | |
763 | newPtr = ptrcast(obj, typeStr+"_p") | |
764 | theClass = globals()[typeStr+"Ptr"] | |
765 | theObj = theClass(newPtr) | |
6999b0d8 RD |
766 | if hasattr(obj, "this"): |
767 | theObj.thisown = obj.thisown | |
8bf5d46e RD |
768 | return theObj |
769 | ||
770 | ||
7bf85405 RD |
771 | #---------------------------------------------------------------------- |
772 | ||
2f90df85 RD |
773 | class wxPyOnDemandOutputWindow: |
774 | def __init__(self, title = "wxPython: stdout/stderr"): | |
775 | self.frame = None | |
776 | self.title = title | |
777 | ||
a1df7a95 | 778 | |
2f90df85 RD |
779 | def SetParent(self, parent): |
780 | self.parent = parent | |
cf694132 | 781 | |
a1df7a95 | 782 | |
2f90df85 RD |
783 | def OnCloseWindow(self, event): |
784 | if self.frame != None: | |
785 | self.frame.Destroy() | |
786 | self.frame = None | |
787 | self.text = None | |
7bf85405 | 788 | |
a1df7a95 | 789 | |
2f90df85 RD |
790 | # this provides the file-like behaviour |
791 | def write(self, str): | |
792 | if not self.frame: | |
793 | self.frame = wxFrame(self.parent, -1, self.title) | |
794 | self.text = wxTextCtrl(self.frame, -1, "", | |
795 | style = wxTE_MULTILINE|wxTE_READONLY) | |
796 | self.frame.SetSize(wxSize(450, 300)) | |
797 | self.frame.Show(true) | |
798 | EVT_CLOSE(self.frame, self.OnCloseWindow) | |
799 | self.text.AppendText(str) | |
800 | ||
a1df7a95 | 801 | |
2f90df85 | 802 | def close(self): |
a1df7a95 RD |
803 | if self.frame != None: |
804 | self.frame.Destroy() | |
2f90df85 RD |
805 | self.frame = None |
806 | self.text = None | |
7bf85405 | 807 | |
7bf85405 RD |
808 | |
809 | ||
fb5e0af0 | 810 | _defRedirect = (wxPlatform == '__WXMSW__') |
7bf85405 RD |
811 | |
812 | #---------------------------------------------------------------------- | |
813 | # The main application class. Derive from this and implement an OnInit | |
814 | # method that creates a frame and then calls self.SetTopWindow(frame) | |
815 | ||
816 | class wxApp(wxPyApp): | |
817 | error = 'wxApp.error' | |
2f90df85 | 818 | outputWindowClass = wxPyOnDemandOutputWindow |
7bf85405 RD |
819 | |
820 | def __init__(self, redirect=_defRedirect, filename=None): | |
821 | wxPyApp.__init__(self) | |
822 | self.stdioWin = None | |
823 | self.saveStdio = (sys.stdout, sys.stderr) | |
824 | if redirect: | |
825 | self.RedirectStdio(filename) | |
7bf85405 RD |
826 | # this initializes wxWindows and then calls our OnInit |
827 | _wxStart(self.OnInit) | |
828 | ||
829 | ||
830 | def __del__(self): | |
831 | try: | |
832 | self.RestoreStdio() | |
833 | except: | |
834 | pass | |
835 | ||
2f90df85 RD |
836 | |
837 | def SetTopWindow(self, frame): | |
838 | if self.stdioWin: | |
839 | self.stdioWin.SetParent(frame) | |
a1df7a95 | 840 | sys.stderr = sys.stdout = self.stdioWin |
2f90df85 RD |
841 | wxPyApp.SetTopWindow(self, frame) |
842 | ||
a1df7a95 | 843 | |
2f90df85 RD |
844 | def MainLoop(self): |
845 | wxPyApp.MainLoop(self) | |
846 | self.RestoreStdio() | |
847 | ||
a1df7a95 | 848 | |
7bf85405 RD |
849 | def RedirectStdio(self, filename): |
850 | if filename: | |
851 | sys.stdout = sys.stderr = open(filename, 'a') | |
852 | else: | |
2f90df85 | 853 | self.stdioWin = self.outputWindowClass() # wxPyOnDemandOutputWindow |
7bf85405 | 854 | |
a1df7a95 | 855 | |
7bf85405 RD |
856 | def RestoreStdio(self): |
857 | sys.stdout, sys.stderr = self.saveStdio | |
858 | if self.stdioWin != None: | |
cf694132 | 859 | self.stdioWin.close() |
7bf85405 | 860 | |
6999b0d8 RD |
861 | #---------------------------------------------------------------------------- |
862 | ||
863 | class wxPySimpleApp(wxApp): | |
864 | def __init__(self): | |
865 | wxApp.__init__(self, 0) | |
866 | def OnInit(self): | |
867 | return true | |
7bf85405 | 868 | |
2f90df85 | 869 | |
f6bcfd97 BP |
870 | class wxPyWidgetTester(wxApp): |
871 | def __init__(self, size = (250, 100)): | |
872 | self.size = size | |
873 | wxApp.__init__(self, 0) | |
874 | ||
875 | def OnInit(self): | |
876 | self.frame = wxFrame(None, -1, "Widget Tester", pos=(0,0), size=self.size) | |
877 | self.SetTopWindow(self.frame) | |
878 | return true | |
879 | ||
880 | def SetWidget(self, widgetClass, *args): | |
881 | w = apply(widgetClass, (self.frame,) + args) | |
882 | self.frame.Show(true) | |
883 | ||
7bf85405 | 884 | #---------------------------------------------------------------------------- |
8bf5d46e | 885 | # DO NOT hold any other references to this object. This is how we know when |
b1462dfa RD |
886 | # to cleanup system resources that wxWin is holding. When this module is |
887 | # unloaded, the refcount on __cleanMeUp goes to zero and it calls the | |
888 | # wxApp_CleanUp function. | |
889 | ||
890 | class __wxPyCleanup: | |
891 | def __init__(self): | |
892 | self.cleanup = wxc.wxApp_CleanUp | |
893 | def __del__(self): | |
894 | self.cleanup() | |
895 | ||
8bf5d46e RD |
896 | __cleanMeUp = __wxPyCleanup() |
897 | #---------------------------------------------------------------------------- | |
898 | ||
899 | ||
900 |