]>
Commit | Line | Data |
---|---|---|
7bf85405 RD |
1 | #---------------------------------------------------------------------------- |
2 | # Name: _extra.py | |
1e4a197e | 3 | # Purpose: This file is appended to the shadow class file generated |
7bf85405 RD |
4 | # by SWIG. We add some unSWIGable things here. |
5 | # | |
6 | # Author: Robin Dunn | |
7 | # | |
8 | # Created: 6/30/97 | |
7bf85405 RD |
9 | # Copyright: (c) 1998 by Total Control Software |
10 | # Licence: wxWindows license | |
11 | #---------------------------------------------------------------------------- | |
12 | ||
13 | import sys | |
14 | ||
15 | #---------------------------------------------------------------------- | |
16 | # This gives this module's dictionary to the C++ extension code... | |
17 | ||
18 | _wxSetDictionary(vars()) | |
19 | ||
20 | ||
21 | #---------------------------------------------------------------------- | |
22 | #---------------------------------------------------------------------- | |
23 | # Helper function to link python methods to wxWindows virtual | |
24 | # functions by name. | |
25 | ||
26 | def _checkForCallback(obj, name, event, theID=-1): | |
27 | try: cb = getattr(obj, name) | |
28 | except: pass | |
29 | else: obj.Connect(theID, -1, event, cb) | |
30 | ||
7bf85405 RD |
31 | |
32 | #---------------------------------------------------------------------- | |
33 | #---------------------------------------------------------------------- | |
34 | # functions that look and act like the C++ Macros of the same name | |
35 | ||
36 | ||
37 | # Miscellaneous | |
38 | def EVT_SIZE(win, func): | |
39 | win.Connect(-1, -1, wxEVT_SIZE, func) | |
40 | ||
41 | def EVT_MOVE(win, func): | |
42 | win.Connect(-1, -1, wxEVT_MOVE, func) | |
43 | ||
3ef86e32 RD |
44 | def EVT_SIZING(win, func): |
45 | win.Connect(-1, -1, wxEVT_SIZING, func) | |
46 | ||
47 | def EVT_MOVING(win, func): | |
48 | win.Connect(-1, -1, wxEVT_MOVING, func) | |
49 | ||
7bf85405 RD |
50 | def EVT_CLOSE(win, func): |
51 | win.Connect(-1, -1, wxEVT_CLOSE_WINDOW, func) | |
52 | ||
53 | def EVT_PAINT(win, func): | |
54 | win.Connect(-1, -1, wxEVT_PAINT, func) | |
55 | ||
56 | def EVT_ERASE_BACKGROUND(win, func): | |
57 | win.Connect(-1, -1, wxEVT_ERASE_BACKGROUND, func) | |
58 | ||
59 | def EVT_CHAR(win, func): | |
60 | win.Connect(-1, -1, wxEVT_CHAR, func) | |
61 | ||
62 | def EVT_CHAR_HOOK(win, func): | |
63 | win.Connect(-1, -1, wxEVT_CHAR_HOOK, func) | |
64 | ||
8bf5d46e RD |
65 | def EVT_KEY_DOWN(win, func): |
66 | win.Connect(-1, -1, wxEVT_KEY_DOWN, func) | |
67 | ||
68 | def EVT_KEY_UP(win, func): | |
69 | win.Connect(-1, -1, wxEVT_KEY_UP, func) | |
70 | ||
3ef86e32 RD |
71 | def EVT_HOTKEY(win, func): |
72 | win.Connect(-1, -1, wxEVT_HOTKEY, func) | |
73 | ||
afb810d9 RD |
74 | def EVT_MENU_OPEN(win, func): |
75 | win.Connect(-1, -1, wxEVT_MENU_OPEN, func) | |
76 | ||
77 | def EVT_MENU_CLOSE(win, func): | |
78 | win.Connect(-1, -1, wxEVT_MENU_CLOSE, func) | |
79 | ||
7bf85405 RD |
80 | def EVT_MENU_HIGHLIGHT(win, id, func): |
81 | win.Connect(id, -1, wxEVT_MENU_HIGHLIGHT, func) | |
82 | ||
83 | def EVT_MENU_HIGHLIGHT_ALL(win, func): | |
84 | win.Connect(-1, -1, wxEVT_MENU_HIGHLIGHT, func) | |
85 | ||
86 | def EVT_SET_FOCUS(win, func): | |
87 | win.Connect(-1, -1, wxEVT_SET_FOCUS, func) | |
88 | ||
89 | def EVT_KILL_FOCUS(win, func): | |
90 | win.Connect(-1, -1, wxEVT_KILL_FOCUS, func) | |
91 | ||
7b7ac0ab RD |
92 | def EVT_CHILD_FOCUS(win, func): |
93 | win.Connect(-1, -1, wxEVT_CHILD_FOCUS, func) | |
94 | ||
7bf85405 RD |
95 | def EVT_ACTIVATE(win, func): |
96 | win.Connect(-1, -1, wxEVT_ACTIVATE, func) | |
97 | ||
98 | def EVT_ACTIVATE_APP(win, func): | |
99 | win.Connect(-1, -1, wxEVT_ACTIVATE_APP, func) | |
100 | ||
101 | def EVT_END_SESSION(win, func): | |
102 | win.Connect(-1, -1, wxEVT_END_SESSION, func) | |
103 | ||
104 | def EVT_QUERY_END_SESSION(win, func): | |
105 | win.Connect(-1, -1, wxEVT_QUERY_END_SESSION, func) | |
106 | ||
107 | def EVT_DROP_FILES(win, func): | |
108 | win.Connect(-1, -1, wxEVT_DROP_FILES, func) | |
109 | ||
110 | def EVT_INIT_DIALOG(win, func): | |
111 | win.Connect(-1, -1, wxEVT_INIT_DIALOG, func) | |
112 | ||
113 | def EVT_SYS_COLOUR_CHANGED(win, func): | |
114 | win.Connect(-1, -1, wxEVT_SYS_COLOUR_CHANGED, func) | |
115 | ||
be43cc44 RD |
116 | def EVT_DISPLAY_CHANGED(win, func): |
117 | win.Connect(-1, -1, wxEVT_DISPLAY_CHANGED, func) | |
118 | ||
7bf85405 RD |
119 | def EVT_SHOW(win, func): |
120 | win.Connect(-1, -1, wxEVT_SHOW, func) | |
121 | ||
122 | def EVT_MAXIMIZE(win, func): | |
123 | win.Connect(-1, -1, wxEVT_MAXIMIZE, func) | |
124 | ||
125 | def EVT_ICONIZE(win, func): | |
126 | win.Connect(-1, -1, wxEVT_ICONIZE, func) | |
127 | ||
128 | def EVT_NAVIGATION_KEY(win, func): | |
129 | win.Connect(-1, -1, wxEVT_NAVIGATION_KEY, func) | |
130 | ||
3af4e610 RD |
131 | def EVT_PALETTE_CHANGED(win, func): |
132 | win.Connect(-1, -1, wxEVT_PALETTE_CHANGED, func) | |
133 | ||
134 | def EVT_QUERY_NEW_PALETTE(win, func): | |
135 | win.Connect(-1, -1, wxEVT_QUERY_NEW_PALETTE, func) | |
136 | ||
137 | def EVT_WINDOW_CREATE(win, func): | |
54b96882 | 138 | win.Connect(-1, -1, wxEVT_CREATE, func) |
3af4e610 RD |
139 | |
140 | def EVT_WINDOW_DESTROY(win, func): | |
54b96882 | 141 | win.Connect(-1, -1, wxEVT_DESTROY, func) |
3af4e610 | 142 | |
1e4a197e RD |
143 | def EVT_WINDOW_CREATE_ID(win, id, func): |
144 | win.Connect(id, -1, wxEVT_CREATE, func) | |
145 | ||
146 | def EVT_WINDOW_DESTROY_ID(win, id, func): | |
147 | win.Connect(id, -1, wxEVT_DESTROY, func) | |
148 | ||
203c2f9a RD |
149 | def EVT_SET_CURSOR(win, func): |
150 | win.Connect(-1, -1, wxEVT_SET_CURSOR, func) | |
151 | ||
3af4e610 RD |
152 | |
153 | ||
cf694132 RD |
154 | def EVT_IDLE(win, func): |
155 | win.Connect(-1, -1, wxEVT_IDLE, func) | |
156 | ||
bb0054cd RD |
157 | def EVT_UPDATE_UI(win, id, func): |
158 | win.Connect(id, -1, wxEVT_UPDATE_UI, func) | |
159 | ||
eb715945 RD |
160 | def EVT_UPDATE_UI_RANGE(win, id, id2, func): |
161 | win.Connect(id, id2, wxEVT_UPDATE_UI, func) | |
162 | ||
7bf85405 RD |
163 | |
164 | # Mouse Events | |
165 | def EVT_LEFT_DOWN(win, func): | |
166 | win.Connect(-1, -1, wxEVT_LEFT_DOWN, func) | |
167 | ||
168 | def EVT_LEFT_UP(win, func): | |
169 | win.Connect(-1, -1, wxEVT_LEFT_UP, func) | |
170 | ||
171 | def EVT_MIDDLE_DOWN(win, func): | |
172 | win.Connect(-1, -1, wxEVT_MIDDLE_DOWN, func) | |
173 | ||
174 | def EVT_MIDDLE_UP(win, func): | |
175 | win.Connect(-1, -1, wxEVT_MIDDLE_UP, func) | |
176 | ||
177 | def EVT_RIGHT_DOWN(win, func): | |
178 | win.Connect(-1, -1, wxEVT_RIGHT_DOWN, func) | |
179 | ||
180 | def EVT_RIGHT_UP(win, func): | |
181 | win.Connect(-1, -1, wxEVT_RIGHT_UP, func) | |
182 | ||
183 | def EVT_MOTION(win, func): | |
184 | win.Connect(-1, -1, wxEVT_MOTION, func) | |
185 | ||
186 | def EVT_LEFT_DCLICK(win, func): | |
187 | win.Connect(-1, -1, wxEVT_LEFT_DCLICK, func) | |
188 | ||
189 | def EVT_MIDDLE_DCLICK(win, func): | |
190 | win.Connect(-1, -1, wxEVT_MIDDLE_DCLICK, func) | |
191 | ||
192 | def EVT_RIGHT_DCLICK(win, func): | |
193 | win.Connect(-1, -1, wxEVT_RIGHT_DCLICK, func) | |
194 | ||
195 | def EVT_LEAVE_WINDOW(win, func): | |
196 | win.Connect(-1, -1, wxEVT_LEAVE_WINDOW, func) | |
197 | ||
198 | def EVT_ENTER_WINDOW(win, func): | |
199 | win.Connect(-1, -1, wxEVT_ENTER_WINDOW, func) | |
200 | ||
d1679124 RD |
201 | def EVT_MOUSEWHEEL(win, func): |
202 | win.Connect(-1, -1, wxEVT_MOUSEWHEEL, func) | |
7bf85405 RD |
203 | |
204 | # all mouse events | |
205 | def EVT_MOUSE_EVENTS(win, func): | |
206 | win.Connect(-1, -1, wxEVT_LEFT_DOWN, func) | |
207 | win.Connect(-1, -1, wxEVT_LEFT_UP, func) | |
208 | win.Connect(-1, -1, wxEVT_MIDDLE_DOWN, func) | |
209 | win.Connect(-1, -1, wxEVT_MIDDLE_UP, func) | |
210 | win.Connect(-1, -1, wxEVT_RIGHT_DOWN, func) | |
211 | win.Connect(-1, -1, wxEVT_RIGHT_UP, func) | |
212 | win.Connect(-1, -1, wxEVT_MOTION, func) | |
213 | win.Connect(-1, -1, wxEVT_LEFT_DCLICK, func) | |
214 | win.Connect(-1, -1, wxEVT_MIDDLE_DCLICK, func) | |
215 | win.Connect(-1, -1, wxEVT_RIGHT_DCLICK, func) | |
216 | win.Connect(-1, -1, wxEVT_LEAVE_WINDOW, func) | |
217 | win.Connect(-1, -1, wxEVT_ENTER_WINDOW, func) | |
218 | ||
6d26dc89 RD |
219 | def EVT_MOUSE_CAPTURE_CHANGED(win, func): |
220 | win.Connect(-1, -1, wxEVT_MOUSE_CAPTURE_CHANGED, func) | |
221 | ||
7bf85405 RD |
222 | # EVT_COMMAND |
223 | def EVT_COMMAND(win, id, cmd, func): | |
224 | win.Connect(id, -1, cmd, func) | |
225 | ||
226 | def EVT_COMMAND_RANGE(win, id1, id2, cmd, func): | |
227 | win.Connect(id1, id2, cmd, func) | |
228 | ||
26b9cf27 | 229 | |
7bf85405 RD |
230 | # Scrolling |
231 | def EVT_SCROLL(win, func): | |
83f3dd45 RD |
232 | win.Connect(-1, -1, wxEVT_SCROLL_TOP, func) |
233 | win.Connect(-1, -1, wxEVT_SCROLL_BOTTOM, func) | |
234 | win.Connect(-1, -1, wxEVT_SCROLL_LINEUP, func) | |
235 | win.Connect(-1, -1, wxEVT_SCROLL_LINEDOWN, func) | |
236 | win.Connect(-1, -1, wxEVT_SCROLL_PAGEUP, func) | |
237 | win.Connect(-1, -1, wxEVT_SCROLL_PAGEDOWN, func) | |
238 | win.Connect(-1, -1, wxEVT_SCROLL_THUMBTRACK, func) | |
26b9cf27 | 239 | win.Connect(-1, -1, wxEVT_SCROLL_THUMBRELEASE,func) |
83f3dd45 | 240 | win.Connect(-1, -1, wxEVT_SCROLL_ENDSCROLL, func) |
7bf85405 RD |
241 | |
242 | def EVT_SCROLL_TOP(win, func): | |
243 | win.Connect(-1, -1, wxEVT_SCROLL_TOP, func) | |
244 | ||
245 | def EVT_SCROLL_BOTTOM(win, func): | |
246 | win.Connect(-1, -1, wxEVT_SCROLL_BOTTOM, func) | |
247 | ||
248 | def EVT_SCROLL_LINEUP(win, func): | |
249 | win.Connect(-1, -1, wxEVT_SCROLL_LINEUP, func) | |
250 | ||
251 | def EVT_SCROLL_LINEDOWN(win, func): | |
252 | win.Connect(-1, -1, wxEVT_SCROLL_LINEDOWN, func) | |
253 | ||
254 | def EVT_SCROLL_PAGEUP(win, func): | |
255 | win.Connect(-1, -1, wxEVT_SCROLL_PAGEUP, func) | |
256 | ||
257 | def EVT_SCROLL_PAGEDOWN(win, func): | |
258 | win.Connect(-1, -1, wxEVT_SCROLL_PAGEDOWN, func) | |
259 | ||
260 | def EVT_SCROLL_THUMBTRACK(win, func): | |
261 | win.Connect(-1, -1, wxEVT_SCROLL_THUMBTRACK, func) | |
262 | ||
26b9cf27 RD |
263 | def EVT_SCROLL_THUMBRELEASE(win, func): |
264 | win.Connect(-1, -1, wxEVT_SCROLL_THUMBRELEASE, func) | |
265 | ||
83f3dd45 RD |
266 | def EVT_SCROLL_ENDSCROLL(win, func): |
267 | win.Connect(-1, -1, wxEVT_SCROLL_ENDSCROLL, func) | |
268 | ||
7bf85405 RD |
269 | |
270 | ||
271 | # Scrolling, with an id | |
272 | def EVT_COMMAND_SCROLL(win, id, func): | |
273 | win.Connect(id, -1, wxEVT_SCROLL_TOP, func) | |
274 | win.Connect(id, -1, wxEVT_SCROLL_BOTTOM, func) | |
275 | win.Connect(id, -1, wxEVT_SCROLL_LINEUP, func) | |
276 | win.Connect(id, -1, wxEVT_SCROLL_LINEDOWN, func) | |
277 | win.Connect(id, -1, wxEVT_SCROLL_PAGEUP, func) | |
278 | win.Connect(id, -1, wxEVT_SCROLL_PAGEDOWN, func) | |
279 | win.Connect(id, -1, wxEVT_SCROLL_THUMBTRACK,func) | |
26b9cf27 | 280 | win.Connect(id, -1, wxEVT_SCROLL_THUMBRELEASE,func) |
1e4a197e | 281 | win.Connect(id, -1, wxEVT_SCROLL_ENDSCROLL, func) |
7bf85405 RD |
282 | |
283 | def EVT_COMMAND_SCROLL_TOP(win, id, func): | |
284 | win.Connect(id, -1, wxEVT_SCROLL_TOP, func) | |
285 | ||
286 | def EVT_COMMAND_SCROLL_BOTTOM(win, id, func): | |
287 | win.Connect(id, -1, wxEVT_SCROLL_BOTTOM, func) | |
288 | ||
289 | def EVT_COMMAND_SCROLL_LINEUP(win, id, func): | |
290 | win.Connect(id, -1, wxEVT_SCROLL_LINEUP, func) | |
291 | ||
292 | def EVT_COMMAND_SCROLL_LINEDOWN(win, id, func): | |
293 | win.Connect(id, -1, wxEVT_SCROLL_LINEDOWN, func) | |
294 | ||
295 | def EVT_COMMAND_SCROLL_PAGEUP(win, id, func): | |
296 | win.Connect(id, -1, wxEVT_SCROLL_PAGEUP, func) | |
297 | ||
298 | def EVT_COMMAND_SCROLL_PAGEDOWN(win, id, func): | |
299 | win.Connect(id, -1, wxEVT_SCROLL_PAGEDOWN, func) | |
300 | ||
301 | def EVT_COMMAND_SCROLL_THUMBTRACK(win, id, func): | |
302 | win.Connect(id, -1, wxEVT_SCROLL_THUMBTRACK, func) | |
303 | ||
26b9cf27 RD |
304 | def EVT_COMMAND_SCROLL_THUMBRELEASE(win, id, func): |
305 | win.Connect(id, -1, wxEVT_SCROLL_THUMBRELEASE, func) | |
306 | ||
83f3dd45 RD |
307 | def EVT_COMMAND_SCROLL_ENDSCROLL(win, id, func): |
308 | win.Connect(id, -1, wxEVT_SCROLL_ENDSCROLL, func) | |
309 | ||
d426c97e RD |
310 | #--- |
311 | def EVT_SCROLLWIN(win, func): | |
26b9cf27 RD |
312 | win.Connect(-1, -1, wxEVT_SCROLLWIN_TOP, func) |
313 | win.Connect(-1, -1, wxEVT_SCROLLWIN_BOTTOM, func) | |
314 | win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEUP, func) | |
315 | win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEDOWN, func) | |
316 | win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEUP, func) | |
317 | win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEDOWN, func) | |
318 | win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBTRACK, func) | |
319 | win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBRELEASE,func) | |
d426c97e RD |
320 | |
321 | def EVT_SCROLLWIN_TOP(win, func): | |
322 | win.Connect(-1, -1, wxEVT_SCROLLWIN_TOP, func) | |
323 | ||
324 | def EVT_SCROLLWIN_BOTTOM(win, func): | |
325 | win.Connect(-1, -1, wxEVT_SCROLLWIN_BOTTOM, func) | |
326 | ||
327 | def EVT_SCROLLWIN_LINEUP(win, func): | |
328 | win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEUP, func) | |
329 | ||
330 | def EVT_SCROLLWIN_LINEDOWN(win, func): | |
331 | win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEDOWN, func) | |
332 | ||
333 | def EVT_SCROLLWIN_PAGEUP(win, func): | |
334 | win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEUP, func) | |
335 | ||
336 | def EVT_SCROLLWIN_PAGEDOWN(win, func): | |
337 | win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEDOWN, func) | |
338 | ||
339 | def EVT_SCROLLWIN_THUMBTRACK(win, func): | |
340 | win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBTRACK, func) | |
341 | ||
26b9cf27 RD |
342 | def EVT_SCROLLWIN_THUMBRELEASE(win, func): |
343 | win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBRELEASE, func) | |
344 | ||
d426c97e RD |
345 | |
346 | ||
347 | # Scrolling, with an id | |
348 | def EVT_COMMAND_SCROLLWIN(win, id, func): | |
26b9cf27 RD |
349 | win.Connect(id, -1, wxEVT_SCROLLWIN_TOP, func) |
350 | win.Connect(id, -1, wxEVT_SCROLLWIN_BOTTOM, func) | |
351 | win.Connect(id, -1, wxEVT_SCROLLWIN_LINEUP, func) | |
352 | win.Connect(id, -1, wxEVT_SCROLLWIN_LINEDOWN, func) | |
353 | win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEUP, func) | |
354 | win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEDOWN, func) | |
355 | win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBTRACK, func) | |
356 | win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBRELEASE,func) | |
d426c97e RD |
357 | |
358 | def EVT_COMMAND_SCROLLWIN_TOP(win, id, func): | |
359 | win.Connect(id, -1, wxEVT_SCROLLWIN_TOP, func) | |
360 | ||
361 | def EVT_COMMAND_SCROLLWIN_BOTTOM(win, id, func): | |
362 | win.Connect(id, -1, wxEVT_SCROLLWIN_BOTTOM, func) | |
363 | ||
364 | def EVT_COMMAND_SCROLLWIN_LINEUP(win, id, func): | |
365 | win.Connect(id, -1, wxEVT_SCROLLWIN_LINEUP, func) | |
366 | ||
367 | def EVT_COMMAND_SCROLLWIN_LINEDOWN(win, id, func): | |
368 | win.Connect(id, -1, wxEVT_SCROLLWIN_LINEDOWN, func) | |
369 | ||
370 | def EVT_COMMAND_SCROLLWIN_PAGEUP(win, id, func): | |
371 | win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEUP, func) | |
372 | ||
373 | def EVT_COMMAND_SCROLLWIN_PAGEDOWN(win, id, func): | |
374 | win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEDOWN, func) | |
375 | ||
376 | def EVT_COMMAND_SCROLLWIN_THUMBTRACK(win, id, func): | |
377 | win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBTRACK, func) | |
7bf85405 | 378 | |
26b9cf27 RD |
379 | def EVT_COMMAND_SCROLLWIN_THUMBRELEASE(win, id, func): |
380 | win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBRELEASE, func) | |
381 | ||
382 | ||
7bf85405 RD |
383 | # Convenience commands |
384 | def EVT_BUTTON(win, id, func): | |
385 | win.Connect(id, -1, wxEVT_COMMAND_BUTTON_CLICKED, func) | |
386 | ||
387 | def EVT_CHECKBOX(win, id, func): | |
388 | win.Connect(id, -1, wxEVT_COMMAND_CHECKBOX_CLICKED, func) | |
389 | ||
390 | def EVT_CHOICE(win, id, func): | |
391 | win.Connect(id, -1, wxEVT_COMMAND_CHOICE_SELECTED, func) | |
392 | ||
393 | def EVT_LISTBOX(win, id, func): | |
394 | win.Connect(id, -1, wxEVT_COMMAND_LISTBOX_SELECTED, func) | |
395 | ||
396 | def EVT_LISTBOX_DCLICK(win, id, func): | |
397 | win.Connect(id, -1, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, func) | |
398 | ||
399 | def EVT_TEXT(win, id, func): | |
400 | win.Connect(id, -1, wxEVT_COMMAND_TEXT_UPDATED, func) | |
401 | ||
402 | def EVT_TEXT_ENTER(win, id, func): | |
403 | win.Connect(id, -1, wxEVT_COMMAND_TEXT_ENTER, func) | |
404 | ||
c7e7022c RD |
405 | def EVT_TEXT_URL(win, id, func): |
406 | win.Connect(id, -1, wxEVT_COMMAND_TEXT_URL, func) | |
407 | ||
00b6c4e3 RD |
408 | def EVT_TEXT_MAXLEN(win, id, func): |
409 | win.Connect(id, -1, wxEVT_COMMAND_TEXT_MAXLEN, func) | |
410 | ||
7bf85405 RD |
411 | def EVT_MENU(win, id, func): |
412 | win.Connect(id, -1, wxEVT_COMMAND_MENU_SELECTED, func) | |
413 | ||
414 | def EVT_MENU_RANGE(win, id1, id2, func): | |
415 | win.Connect(id1, id2, wxEVT_COMMAND_MENU_SELECTED, func) | |
416 | ||
417 | def EVT_SLIDER(win, id, func): | |
418 | win.Connect(id, -1, wxEVT_COMMAND_SLIDER_UPDATED, func) | |
419 | ||
420 | def EVT_RADIOBOX(win, id, func): | |
421 | win.Connect(id, -1, wxEVT_COMMAND_RADIOBOX_SELECTED, func) | |
422 | ||
423 | def EVT_RADIOBUTTON(win, id, func): | |
424 | win.Connect(id, -1, wxEVT_COMMAND_RADIOBUTTON_SELECTED, func) | |
425 | ||
426 | def EVT_VLBOX(win, id, func): | |
427 | win.Connect(id, -1, wxEVT_COMMAND_VLBOX_SELECTED, func) | |
428 | ||
429 | def EVT_COMBOBOX(win, id, func): | |
430 | win.Connect(id, -1, wxEVT_COMMAND_COMBOBOX_SELECTED, func) | |
431 | ||
432 | def EVT_TOOL(win, id, func): | |
433 | win.Connect(id, -1, wxEVT_COMMAND_TOOL_CLICKED, func) | |
434 | ||
3af4e610 RD |
435 | def EVT_TOOL_RANGE(win, id, id2, func): |
436 | win.Connect(id, id2, wxEVT_COMMAND_TOOL_CLICKED, func) | |
437 | ||
7bf85405 RD |
438 | def EVT_TOOL_RCLICKED(win, id, func): |
439 | win.Connect(id, -1, wxEVT_COMMAND_TOOL_RCLICKED, func) | |
440 | ||
3af4e610 RD |
441 | def EVT_TOOL_RCLICKED_RANGE(win, id, id2, func): |
442 | win.Connect(id, id2, wxEVT_COMMAND_TOOL_RCLICKED, func) | |
443 | ||
7bf85405 RD |
444 | def EVT_TOOL_ENTER(win, id, func): |
445 | win.Connect(id, -1, wxEVT_COMMAND_TOOL_ENTER, func) | |
446 | ||
447 | def EVT_CHECKLISTBOX(win, id, func): | |
448 | win.Connect(id, -1, wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, func) | |
449 | ||
3af4e610 RD |
450 | def EVT_SPINCTRL(win, id, func): |
451 | win.Connect(id, -1, wxEVT_COMMAND_SPINCTRL_UPDATED, func) | |
452 | ||
453 | ||
7bf85405 RD |
454 | |
455 | # Generic command events | |
456 | ||
457 | def EVT_COMMAND_LEFT_CLICK(win, id, func): | |
458 | win.Connect(id, -1, wxEVT_COMMAND_LEFT_CLICK, func) | |
459 | ||
460 | def EVT_COMMAND_LEFT_DCLICK(win, id, func): | |
461 | win.Connect(id, -1, wxEVT_COMMAND_LEFT_DCLICK, func) | |
462 | ||
463 | def EVT_COMMAND_RIGHT_CLICK(win, id, func): | |
464 | win.Connect(id, -1, wxEVT_COMMAND_RIGHT_CLICK, func) | |
465 | ||
466 | def EVT_COMMAND_RIGHT_DCLICK(win, id, func): | |
467 | win.Connect(id, -1, wxEVT_COMMAND_RIGHT_DCLICK, func) | |
468 | ||
469 | def EVT_COMMAND_SET_FOCUS(win, id, func): | |
470 | win.Connect(id, -1, wxEVT_COMMAND_SET_FOCUS, func) | |
471 | ||
472 | def EVT_COMMAND_KILL_FOCUS(win, id, func): | |
473 | win.Connect(id, -1, wxEVT_COMMAND_KILL_FOCUS, func) | |
474 | ||
475 | def EVT_COMMAND_ENTER(win, id, func): | |
476 | win.Connect(id, -1, wxEVT_COMMAND_ENTER, func) | |
477 | ||
478 | ||
b639c3c5 | 479 | # wxSpinButton |
62bd0874 RD |
480 | def EVT_SPIN_UP(win, id, func): |
481 | win.Connect(id, -1, wxEVT_SCROLL_LINEUP, func) | |
482 | ||
483 | def EVT_SPIN_DOWN(win, id, func): | |
f6bcfd97 | 484 | win.Connect(id, -1, wxEVT_SCROLL_LINEDOWN, func) |
62bd0874 RD |
485 | |
486 | def EVT_SPIN(win, id, func): | |
62bd0874 RD |
487 | win.Connect(id, -1, wxEVT_SCROLL_THUMBTRACK,func) |
488 | ||
489 | ||
08127323 RD |
490 | # wxSashWindow |
491 | def EVT_SASH_DRAGGED(win, id, func): | |
492 | win.Connect(id, -1, wxEVT_SASH_DRAGGED, func) | |
493 | ||
494 | def EVT_SASH_DRAGGED_RANGE(win, id1, id2, func): | |
495 | win.Connect(id1, id2, wxEVT_SASH_DRAGGED, func) | |
496 | ||
497 | def EVT_QUERY_LAYOUT_INFO(win, func): | |
1fded56b | 498 | win.Connect(-1, -1, wxEVT_QUERY_LAYOUT_INFO, func) |
08127323 RD |
499 | |
500 | def EVT_CALCULATE_LAYOUT(win, func): | |
1fded56b | 501 | win.Connect(-1, -1, wxEVT_CALCULATE_LAYOUT, func) |
08127323 RD |
502 | |
503 | ||
bb0054cd RD |
504 | #wxSplitterWindow |
505 | def EVT_SPLITTER_SASH_POS_CHANGING(win, id, func): | |
506 | win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, func) | |
507 | ||
508 | def EVT_SPLITTER_SASH_POS_CHANGED(win, id, func): | |
509 | win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, func) | |
510 | ||
511 | def EVT_SPLITTER_UNSPLIT(win, id, func): | |
512 | win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_UNSPLIT, func) | |
513 | ||
514 | def EVT_SPLITTER_DOUBLECLICKED(win, id, func): | |
515 | win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, func) | |
516 | ||
b639c3c5 | 517 | |
f6bcfd97 BP |
518 | # wxTimer |
519 | def EVT_TIMER(win, id, func): | |
520 | win.Connect(id, -1, wxEVT_TIMER, func) | |
521 | ||
c368d904 RD |
522 | # wxProcess |
523 | def EVT_END_PROCESS(eh, id, func): | |
524 | eh.Connect(id, -1, wxEVT_END_PROCESS, func) | |
f6bcfd97 | 525 | |
185d7c3e RD |
526 | |
527 | # wxJoyStick | |
528 | def EVT_JOY_DOWN(win, func): | |
ac346f50 | 529 | win.Connect(-1, -1, wxEVT_JOY_BUTTON_DOWN, func) |
185d7c3e RD |
530 | |
531 | def EVT_JOY_UP(win, func): | |
ac346f50 | 532 | win.Connect(-1, -1, wxEVT_JOY_BUTTON_UP, func) |
185d7c3e RD |
533 | |
534 | def EVT_JOY_MOVE(win, func): | |
535 | win.Connect(-1, -1, wxEVT_JOY_MOVE, func) | |
536 | ||
537 | def EVT_JOY_ZMOVE(win, func): | |
538 | win.Connect(-1, -1, wxEVT_JOY_ZMOVE, func) | |
539 | ||
540 | def EVT_JOYSTICK_EVENTS(win, func): | |
ac346f50 RD |
541 | win.Connect(-1, -1, wxEVT_JOY_BUTTON_DOWN, func) |
542 | win.Connect(-1, -1, wxEVT_JOY_BUTTON_UP, func) | |
185d7c3e RD |
543 | win.Connect(-1, -1, wxEVT_JOY_MOVE, func) |
544 | win.Connect(-1, -1, wxEVT_JOY_ZMOVE, func) | |
545 | ||
d1679124 RD |
546 | |
547 | def EVT_TOGGLEBUTTON(win, id, func): | |
548 | win.Connect(id, -1, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, func) | |
549 | ||
550 | ||
4f3449b4 | 551 | |
4f3449b4 RD |
552 | def EVT_CONTEXT_MENU(win, func): |
553 | win.Connect(-1, -1, wxEVT_CONTEXT_MENU, func) | |
554 | ||
555 | ||
9c039d08 | 556 | #---------------------------------------------------------------------- |
7bf85405 RD |
557 | |
558 | class wxTimer(wxPyTimer): | |
185d7c3e RD |
559 | def __init__(self, evtHandler = None, id = -1): |
560 | if evtHandler is None: | |
561 | wxPyTimer.__init__(self, self.Notify) # derived class must provide | |
562 | # Notify(self) method. | |
563 | else: | |
564 | wxPyTimer.__init__(self, None) | |
565 | self.SetOwner(evtHandler, id) | |
7bf85405 | 566 | |
7bf85405 RD |
567 | #---------------------------------------------------------------------- |
568 | # aliases | |
569 | ||
b639c3c5 | 570 | wxColor = wxColour |
7bf85405 | 571 | wxNamedColor = wxNamedColour |
ecc08ead | 572 | wxPen = wxPyPen |
293a0a86 | 573 | wxScrollbar = wxScrollBar |
1e4a197e RD |
574 | wxPoint2D = wxPoint2DDouble |
575 | ||
576 | wxPyAssertionError = wxc.wxPyAssertionError | |
293a0a86 | 577 | |
af309447 | 578 | |
6999b0d8 | 579 | # backwards compatibility |
1e4a197e RD |
580 | wxNoRefBitmap = wxBitmap |
581 | wxPyDefaultPosition = wxDefaultPosition | |
582 | wxPyDefaultSize = wxDefaultSize | |
583 | NULL = None | |
68320e40 RD |
584 | wxSystemSettings_GetSystemColour = wxSystemSettings_GetColour |
585 | wxSystemSettings_GetSystemFont = wxSystemSettings_GetFont | |
586 | wxSystemSettings_GetSystemMetric = wxSystemSettings_GetMetric | |
00b6c4e3 | 587 | |
1e4a197e RD |
588 | |
589 | # workarounds for bad wxRTTI names | |
590 | __wxPyPtrTypeMap['wxGauge95'] = 'wxGauge' | |
1fded56b RD |
591 | __wxPyPtrTypeMap['wxSlider95'] = 'wxSlider' |
592 | __wxPyPtrTypeMap['wxStatusBar95'] = 'wxStatusBar' | |
1e4a197e RD |
593 | |
594 | ||
595 | ||
596 | def NewId(): | |
597 | import warnings | |
598 | warnings.warn("Use wxNewId instead", DeprecationWarning, 2) | |
599 | return wxNewId() | |
600 | ||
601 | def RegisterId(ID): | |
602 | import warnings | |
603 | warnings.warn("Use wxRegisterId instead", DeprecationWarning, 2) | |
604 | return wxRegisterId(ID) | |
605 | ||
606 | ||
607 | ||
608 | # Use Python's bool constants if available, make aliases if not | |
609 | try: | |
610 | True | |
611 | except NameError: | |
612 | True = 1==1 | |
613 | False = 1==0 | |
614 | ||
615 | # Backwards compaatible | |
616 | TRUE = true = True | |
617 | FALSE = false = False | |
618 | ||
619 | ||
a3fbed81 | 620 | #---------------------------------------------------------------------- |
00b6c4e3 RD |
621 | # wxGTK sets the locale when initialized. Doing this at the Python |
622 | # level should set it up to match what GTK is doing at the C level. | |
293a0a86 RD |
623 | if wxPlatform == "__WXGTK__": |
624 | try: | |
625 | import locale | |
626 | locale.setlocale(locale.LC_ALL, "") | |
627 | except: | |
628 | pass | |
00b6c4e3 | 629 | |
1fded56b RD |
630 | # On MSW add the directory where the wxWindows catalogs were installed |
631 | # to the default catalog path. | |
1e4a197e RD |
632 | if wxPlatform == "__WXMSW__": |
633 | import os | |
634 | localedir = os.path.join(os.path.split(__file__)[0], "locale") | |
635 | wxLocale_AddCatalogLookupPathPrefix(localedir) | |
636 | del os | |
a3fbed81 RD |
637 | |
638 | #---------------------------------------------------------------------- | |
1fded56b RD |
639 | # Load version numbers from __version__... Ensure that major and minor |
640 | # versions are the same for both wxPython and wxWindows. | |
a3fbed81 | 641 | |
1fded56b RD |
642 | from wxPython.__version__ import * |
643 | __version__ = wxVERSION_STRING | |
a3fbed81 | 644 | |
1fded56b RD |
645 | assert wxMAJOR_VERSION == wxc.wxMAJOR_VERSION, "wxPython/wxWindows version mismatch" |
646 | assert wxMINOR_VERSION == wxc.wxMINOR_VERSION, "wxPython/wxWindows version mismatch" | |
647 | if wxRELEASE_VERSION != wxc.wxRELEASE_VERSION: | |
648 | import warnings | |
649 | warnings.warn("wxPython/wxWindows release number mismatch") | |
a3fbed81 RD |
650 | |
651 | ||
8bf5d46e RD |
652 | #---------------------------------------------------------------------- |
653 | # This helper function will take a wxPython object and convert it to | |
654 | # another wxPython object type. This will not be able to create objects | |
7bcd390c | 655 | # that are derived from wxPython classes by the user, only those that are |
8bf5d46e RD |
656 | # actually part of wxPython and directly corespond to C++ objects. |
657 | # | |
658 | # This is useful in situations where some method returns a generic | |
659 | # type such as wxWindow, but you know that it is actually some | |
660 | # derived type such as a wxTextCtrl. You can't call wxTextCtrl specific | |
661 | # methods on a wxWindow object, but you can use this function to | |
662 | # create a wxTextCtrl object that will pass the same pointer to | |
663 | # the C++ code. You use it like this: | |
664 | # | |
665 | # textCtrl = wxPyTypeCast(window, "wxTextCtrl") | |
666 | # | |
667 | # | |
668 | # WARNING: Using this function to type cast objects into types that | |
669 | # they are not is not recommended and is likely to cause your | |
670 | # program to crash... Hard. | |
671 | # | |
672 | ||
673 | def wxPyTypeCast(obj, typeStr): | |
83b18bab RD |
674 | if obj is None: |
675 | return None | |
9416aa89 RD |
676 | theClass = globals()[typeStr+"Ptr"] |
677 | typeStr = __wxPyPtrTypeMap.get(typeStr, typeStr) | |
8bf5d46e | 678 | if hasattr(obj, "this"): |
2aab8f16 RD |
679 | # if already the right type then just return it |
680 | if isinstance(obj, theClass) or obj.__class__ is theClass: | |
9416aa89 | 681 | return obj |
8bf5d46e RD |
682 | newPtr = ptrcast(obj.this, typeStr+"_p") |
683 | else: | |
684 | newPtr = ptrcast(obj, typeStr+"_p") | |
8bf5d46e | 685 | theObj = theClass(newPtr) |
6999b0d8 RD |
686 | if hasattr(obj, "this"): |
687 | theObj.thisown = obj.thisown | |
8bf5d46e RD |
688 | return theObj |
689 | ||
1e4a197e RD |
690 | #---------------------------------------------------------------------------- |
691 | # An isinstance for Pythons < 2.2 that can check a sequence of class objects | |
692 | # like the one in 2.2 can. | |
693 | ||
694 | def wxPy_isinstance(obj, klasses): | |
695 | import types | |
696 | if sys.version[:3] < "2.2" and type(klasses) in [types.TupleType, types.ListType]: | |
697 | for klass in klasses: | |
698 | if isinstance(obj, klass): return True | |
699 | return False | |
700 | else: | |
701 | return isinstance(obj, klasses) | |
8bf5d46e | 702 | |
4acff284 | 703 | #---------------------------------------------------------------------------- |
72797a7d RD |
704 | _wxCallAfterId = None |
705 | ||
706 | def wxCallAfter(callable, *args, **kw): | |
707 | """ | |
708 | Call the specified function after the current and pending event | |
c2dac736 RD |
709 | handlers have been completed. This is also good for making GUI |
710 | method calls from non-GUI threads. | |
72797a7d RD |
711 | """ |
712 | app = wxGetApp() | |
713 | assert app, 'No wxApp created yet' | |
714 | ||
715 | global _wxCallAfterId | |
716 | if _wxCallAfterId is None: | |
1542ea39 | 717 | _wxCallAfterId = wxNewEventType() |
72797a7d | 718 | app.Connect(-1, -1, _wxCallAfterId, |
1fded56b | 719 | lambda event: event.callable(*event.args, **event.kw) ) |
72797a7d RD |
720 | evt = wxPyEvent() |
721 | evt.SetEventType(_wxCallAfterId) | |
722 | evt.callable = callable | |
723 | evt.args = args | |
724 | evt.kw = kw | |
725 | wxPostEvent(app, evt) | |
726 | ||
1fded56b RD |
727 | |
728 | #---------------------------------------------------------------------- | |
729 | ||
730 | ||
731 | class wxFutureCall: | |
732 | """ | |
733 | A convenience class for wxTimer, that calls the given callable | |
734 | object once after the given amount of milliseconds, passing any | |
735 | positional or keyword args. The return value of the callable is | |
736 | availbale after it has been run with the GetResult method. | |
737 | ||
738 | If you don't need to get the return value or restart the timer | |
739 | then there is no need to hold a reference to this object. It will | |
740 | hold a reference to itself while the timer is running (the timer | |
741 | has a reference to self.Notify) but the cycle will be broken when | |
742 | the timer completes, automatically cleaning up the wxFutureCall | |
743 | object. | |
744 | """ | |
745 | def __init__(self, millis, callable, *args, **kwargs): | |
746 | self.millis = millis | |
747 | self.callable = callable | |
748 | self.SetArgs(*args, **kwargs) | |
749 | self.runCount = 0 | |
750 | self.hasRun = False | |
751 | self.result = None | |
752 | self.timer = None | |
753 | self.Start() | |
754 | ||
755 | def __del__(self): | |
756 | self.Stop() | |
757 | ||
758 | ||
759 | def Start(self, millis=None): | |
760 | """ | |
761 | (Re)start the timer | |
762 | """ | |
763 | self.hasRun = False | |
764 | if millis is not None: | |
765 | self.millis = millis | |
766 | self.Stop() | |
767 | self.timer = wxPyTimer(self.Notify) | |
768 | self.timer.Start(self.millis, wxTIMER_ONE_SHOT) | |
769 | Restart = Start | |
770 | ||
771 | ||
772 | def Stop(self): | |
773 | """ | |
774 | Stop and destroy the timer. | |
775 | """ | |
776 | if self.timer is not None: | |
777 | self.timer.Stop() | |
778 | self.timer = None | |
779 | ||
780 | ||
781 | def GetInterval(self): | |
782 | if self.timer is not None: | |
783 | return self.timer.GetInterval() | |
784 | else: | |
785 | return 0 | |
786 | ||
787 | ||
788 | def IsRunning(self): | |
789 | return self.timer is not None and self.timer.IsRunning() | |
790 | ||
791 | ||
792 | def SetArgs(self, *args, **kwargs): | |
793 | """ | |
794 | (Re)set the args passed to the callable object. This is | |
795 | useful in conjunction with Restart if you want to schedule a | |
796 | new call to the same callable object but with different | |
797 | parameters. | |
798 | """ | |
799 | self.args = args | |
800 | self.kwargs = kwargs | |
801 | ||
802 | def HasRun(self): | |
803 | return self.hasRun | |
804 | ||
805 | def GetResult(self): | |
806 | return self.result | |
807 | ||
808 | def Notify(self): | |
809 | """ | |
810 | The timer has expired so call the callable. | |
811 | """ | |
812 | if self.callable and getattr(self.callable, 'im_self', True): | |
813 | self.runCount += 1 | |
814 | self.result = self.callable(*self.args, **self.kwargs) | |
815 | self.hasRun = True | |
816 | wxCallAfter(self.Stop) | |
817 | ||
1e4a197e | 818 | |
72797a7d | 819 | #---------------------------------------------------------------------- |
4acff284 | 820 | |
7cdaed0b RD |
821 | class wxPyDeadObjectError(AttributeError): |
822 | pass | |
4acff284 RD |
823 | |
824 | class _wxPyDeadObject: | |
825 | """ | |
826 | Instances of wx objects that are OOR capable will have their __class__ | |
827 | changed to this class when the C++ object is deleted. This should help | |
828 | prevent crashes due to referencing a bogus C++ pointer. | |
829 | """ | |
7cdaed0b | 830 | reprStr = "wxPython wrapper for DELETED %s object! (The C++ object no longer exists.)" |
fc51b8c3 | 831 | attrStr = "The C++ part of the %s object has been deleted, attribute access no longer allowed." |
7cdaed0b | 832 | |
4acff284 RD |
833 | def __repr__( self ): |
834 | if not hasattr(self, "_name"): | |
835 | self._name = "[unknown]" | |
7cdaed0b | 836 | return self.reprStr % self._name |
4acff284 RD |
837 | |
838 | def __getattr__( self, *args ): | |
839 | if not hasattr(self, "_name"): | |
840 | self._name = "[unknown]" | |
7cdaed0b RD |
841 | raise wxPyDeadObjectError( self.attrStr % self._name ) |
842 | ||
843 | def __nonzero__(self): | |
844 | return 0 | |
4acff284 RD |
845 | |
846 | ||
1fded56b RD |
847 | #---------------------------------------------------------------------- |
848 | ||
849 | class wxNotebookPage(wxPanel): | |
850 | """ | |
851 | There is an old (and apparently unsolvable) bug when placing a | |
852 | window with a nonstandard background colour in a wxNotebook on | |
853 | wxGTK, as the notbooks's background colour would always be used | |
854 | when the window is refreshed. The solution is to place a panel in | |
855 | the notbook and the coloured window on the panel, sized to cover | |
856 | the panel. This simple class does that for you, just put an | |
857 | instance of this in the notebook and make your regular window a | |
858 | child of this one and it will handle the resize for you. | |
859 | """ | |
860 | def __init__(self, parent, id=-1, | |
861 | pos=wxDefaultPosition, size=wxDefaultSize, | |
862 | style=wxTAB_TRAVERSAL, name="panel"): | |
863 | wxPanel.__init__(self, parent, id, pos, size, style, name) | |
864 | self.child = None | |
865 | EVT_SIZE(self, self.OnSize) | |
866 | def OnSize(self, evt): | |
867 | if self.child is None: | |
868 | children = self.GetChildren() | |
869 | if len(children): | |
870 | self.child = children[0] | |
871 | if self.child: | |
872 | self.child.SetPosition((0,0)) | |
873 | self.child.SetSize(self.GetSize()) | |
874 | ||
875 | ||
c856d372 | 876 | #---------------------------------------------------------------------- |
7bf85405 RD |
877 | #---------------------------------------------------------------------- |
878 | ||
2f90df85 RD |
879 | class wxPyOnDemandOutputWindow: |
880 | def __init__(self, title = "wxPython: stdout/stderr"): | |
881 | self.frame = None | |
882 | self.title = title | |
c856d372 | 883 | self.parent = None |
2f90df85 RD |
884 | |
885 | def SetParent(self, parent): | |
886 | self.parent = parent | |
cf694132 | 887 | |
2f90df85 RD |
888 | def OnCloseWindow(self, event): |
889 | if self.frame != None: | |
890 | self.frame.Destroy() | |
891 | self.frame = None | |
892 | self.text = None | |
7bf85405 | 893 | |
6e18ca6c | 894 | # These methods provide the file-like output behaviour. |
2f90df85 | 895 | def write(self, str): |
6e18ca6c RD |
896 | if not wxThread_IsMain(): |
897 | # Aquire the GUI mutex before making GUI calls. Mutex is released | |
03a2c062 | 898 | # when locker is deleted at the end of this function. |
6e18ca6c RD |
899 | locker = wxMutexGuiLocker() |
900 | ||
2f90df85 | 901 | if not self.frame: |
03a2c062 RD |
902 | self.frame = wxFrame(self.parent, -1, self.title, |
903 | style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE) | |
2f90df85 RD |
904 | self.text = wxTextCtrl(self.frame, -1, "", |
905 | style = wxTE_MULTILINE|wxTE_READONLY) | |
906 | self.frame.SetSize(wxSize(450, 300)) | |
1e4a197e | 907 | self.frame.Show(True) |
2f90df85 RD |
908 | EVT_CLOSE(self.frame, self.OnCloseWindow) |
909 | self.text.AppendText(str) | |
910 | ||
911 | def close(self): | |
a1df7a95 | 912 | if self.frame != None: |
6e18ca6c RD |
913 | if not wxThread_IsMain(): |
914 | locker = wxMutexGuiLocker() | |
c856d372 | 915 | self.frame.Close() |
7bf85405 | 916 | |
7bf85405 | 917 | |
606d919c | 918 | _defRedirect = (wxPlatform == '__WXMSW__' or wxPlatform == '__WXMAC__') |
7bf85405 RD |
919 | |
920 | #---------------------------------------------------------------------- | |
921 | # The main application class. Derive from this and implement an OnInit | |
922 | # method that creates a frame and then calls self.SetTopWindow(frame) | |
923 | ||
924 | class wxApp(wxPyApp): | |
925 | error = 'wxApp.error' | |
2f90df85 | 926 | outputWindowClass = wxPyOnDemandOutputWindow |
7bf85405 | 927 | |
1e4a197e | 928 | def __init__(self, redirect=_defRedirect, filename=None, useBestVisual=False): |
7bf85405 | 929 | wxPyApp.__init__(self) |
1fded56b RD |
930 | |
931 | if wx.wxPlatform == "__WXMAC__": | |
932 | try: | |
933 | import MacOS | |
934 | if not MacOS.WMAvailable(): | |
935 | print """This program needs access to the screen. Please run with | |
936 | 'pythonw', not 'python', and only when you are logged in on the main display | |
937 | of your Mac.""" | |
938 | sys.exit(1) | |
939 | except: | |
940 | pass | |
941 | ||
7bf85405 RD |
942 | self.stdioWin = None |
943 | self.saveStdio = (sys.stdout, sys.stderr) | |
1e4a197e RD |
944 | |
945 | # This has to be done before OnInit | |
946 | self.SetUseBestVisual(useBestVisual) | |
947 | ||
7bf85405 RD |
948 | if redirect: |
949 | self.RedirectStdio(filename) | |
1e4a197e | 950 | |
dd116e73 RD |
951 | # Set the default handler for SIGINT. This fixes a problem |
952 | # where if Ctrl-C is pressed in the console that started this | |
953 | # app then it will not appear to do anything, (not even send | |
954 | # KeyboardInterrupt???) but will later segfault on exit. By | |
955 | # setting the default handler then the app will exit, as | |
956 | # expected (depending on platform.) | |
1a10a058 RD |
957 | try: |
958 | import signal | |
959 | signal.signal(signal.SIGINT, signal.SIG_DFL) | |
960 | except: | |
961 | pass | |
dd116e73 | 962 | |
7bf85405 RD |
963 | # this initializes wxWindows and then calls our OnInit |
964 | _wxStart(self.OnInit) | |
965 | ||
966 | ||
967 | def __del__(self): | |
968 | try: | |
969 | self.RestoreStdio() | |
970 | except: | |
971 | pass | |
972 | ||
2f90df85 RD |
973 | |
974 | def SetTopWindow(self, frame): | |
975 | if self.stdioWin: | |
976 | self.stdioWin.SetParent(frame) | |
2f90df85 RD |
977 | wxPyApp.SetTopWindow(self, frame) |
978 | ||
a1df7a95 | 979 | |
2f90df85 RD |
980 | def MainLoop(self): |
981 | wxPyApp.MainLoop(self) | |
982 | self.RestoreStdio() | |
983 | ||
a1df7a95 | 984 | |
7bf85405 RD |
985 | def RedirectStdio(self, filename): |
986 | if filename: | |
987 | sys.stdout = sys.stderr = open(filename, 'a') | |
988 | else: | |
1e4a197e | 989 | self.stdioWin = self.outputWindowClass() |
c856d372 | 990 | sys.stdout = sys.stderr = self.stdioWin |
7bf85405 | 991 | |
a1df7a95 | 992 | |
7bf85405 RD |
993 | def RestoreStdio(self): |
994 | sys.stdout, sys.stderr = self.saveStdio | |
c856d372 | 995 | |
7bf85405 | 996 | |
1e4a197e | 997 | # change from wxPyApp_ to wxApp_ |
1e4a197e RD |
998 | wxApp_GetMacSupportPCMenuShortcuts = wxc.wxPyApp_GetMacSupportPCMenuShortcuts |
999 | wxApp_GetMacAboutMenuItemId = wxc.wxPyApp_GetMacAboutMenuItemId | |
1000 | wxApp_GetMacPreferencesMenuItemId = wxc.wxPyApp_GetMacPreferencesMenuItemId | |
1001 | wxApp_GetMacExitMenuItemId = wxc.wxPyApp_GetMacExitMenuItemId | |
1002 | wxApp_GetMacHelpMenuTitleName = wxc.wxPyApp_GetMacHelpMenuTitleName | |
1e4a197e RD |
1003 | wxApp_SetMacSupportPCMenuShortcuts = wxc.wxPyApp_SetMacSupportPCMenuShortcuts |
1004 | wxApp_SetMacAboutMenuItemId = wxc.wxPyApp_SetMacAboutMenuItemId | |
1005 | wxApp_SetMacPreferencesMenuItemId = wxc.wxPyApp_SetMacPreferencesMenuItemId | |
1006 | wxApp_SetMacExitMenuItemId = wxc.wxPyApp_SetMacExitMenuItemId | |
1007 | wxApp_SetMacHelpMenuTitleName = wxc.wxPyApp_SetMacHelpMenuTitleName | |
1008 | ||
1009 | ||
6999b0d8 RD |
1010 | #---------------------------------------------------------------------------- |
1011 | ||
1012 | class wxPySimpleApp(wxApp): | |
83b18bab RD |
1013 | def __init__(self, flag=0): |
1014 | wxApp.__init__(self, flag) | |
6999b0d8 | 1015 | def OnInit(self): |
3fce70fb | 1016 | wxInitAllImageHandlers() |
1e4a197e | 1017 | return True |
7bf85405 | 1018 | |
2f90df85 | 1019 | |
f6bcfd97 BP |
1020 | class wxPyWidgetTester(wxApp): |
1021 | def __init__(self, size = (250, 100)): | |
1022 | self.size = size | |
1023 | wxApp.__init__(self, 0) | |
1024 | ||
1025 | def OnInit(self): | |
1026 | self.frame = wxFrame(None, -1, "Widget Tester", pos=(0,0), size=self.size) | |
1027 | self.SetTopWindow(self.frame) | |
1e4a197e | 1028 | return True |
f6bcfd97 BP |
1029 | |
1030 | def SetWidget(self, widgetClass, *args): | |
1fded56b | 1031 | w = widgetClass(self.frame, *args) |
1e4a197e | 1032 | self.frame.Show(True) |
f6bcfd97 | 1033 | |
7bf85405 | 1034 | #---------------------------------------------------------------------------- |
4acff284 RD |
1035 | # DO NOT hold any other references to this object. This is how we |
1036 | # know when to cleanup system resources that wxWin is holding. When | |
1037 | # the sys module is unloaded, the refcount on sys.__wxPythonCleanup | |
1038 | # goes to zero and it calls the wxApp_CleanUp function. | |
b1462dfa | 1039 | |
c0fbf24b RD |
1040 | class __wxPyCleanup: |
1041 | def __init__(self): | |
1042 | self.cleanup = wxc.wxApp_CleanUp | |
1043 | def __del__(self): | |
1044 | self.cleanup() | |
1045 | ||
1046 | sys.__wxPythonCleanup = __wxPyCleanup() | |
1047 | ||
ef2060fa | 1048 | ## # another possible solution, but it gets called too early... |
c0fbf24b RD |
1049 | ## if sys.version[0] == '2': |
1050 | ## import atexit | |
1051 | ## atexit.register(wxc.wxApp_CleanUp) | |
1052 | ## else: | |
1053 | ## sys.exitfunc = wxc.wxApp_CleanUp | |
b1462dfa | 1054 | |
9416aa89 RD |
1055 | |
1056 | #---------------------------------------------------------------------------- | |
8bf5d46e | 1057 | #---------------------------------------------------------------------------- |