]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_extras.py
fixed initial focus handling in the dialog and made SetFocus() send the focus
[wxWidgets.git] / wxPython / src / _extras.py
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 # 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
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
44 def EVT_CLOSE(win, func):
45 win.Connect(-1, -1, wxEVT_CLOSE_WINDOW, func)
46
47 def EVT_PAINT(win, func):
48 win.Connect(-1, -1, wxEVT_PAINT, func)
49
50 def EVT_ERASE_BACKGROUND(win, func):
51 win.Connect(-1, -1, wxEVT_ERASE_BACKGROUND, func)
52
53 def EVT_CHAR(win, func):
54 win.Connect(-1, -1, wxEVT_CHAR, func)
55
56 def EVT_CHAR_HOOK(win, func):
57 win.Connect(-1, -1, wxEVT_CHAR_HOOK, func)
58
59 def EVT_KEY_DOWN(win, func):
60 win.Connect(-1, -1, wxEVT_KEY_DOWN, func)
61
62 def EVT_KEY_UP(win, func):
63 win.Connect(-1, -1, wxEVT_KEY_UP, func)
64
65 def EVT_MENU_OPEN(win, func):
66 win.Connect(-1, -1, wxEVT_MENU_OPEN, func)
67
68 def EVT_MENU_CLOSE(win, func):
69 win.Connect(-1, -1, wxEVT_MENU_CLOSE, func)
70
71 def EVT_MENU_HIGHLIGHT(win, id, func):
72 win.Connect(id, -1, wxEVT_MENU_HIGHLIGHT, func)
73
74 def EVT_MENU_HIGHLIGHT_ALL(win, func):
75 win.Connect(-1, -1, wxEVT_MENU_HIGHLIGHT, func)
76
77 def EVT_SET_FOCUS(win, func):
78 win.Connect(-1, -1, wxEVT_SET_FOCUS, func)
79
80 def EVT_KILL_FOCUS(win, func):
81 win.Connect(-1, -1, wxEVT_KILL_FOCUS, func)
82
83 def EVT_CHILD_FOCUS(win, func):
84 win.Connect(-1, -1, wxEVT_CHILD_FOCUS, func)
85
86 def EVT_ACTIVATE(win, func):
87 win.Connect(-1, -1, wxEVT_ACTIVATE, func)
88
89 def EVT_ACTIVATE_APP(win, func):
90 win.Connect(-1, -1, wxEVT_ACTIVATE_APP, func)
91
92 def EVT_END_SESSION(win, func):
93 win.Connect(-1, -1, wxEVT_END_SESSION, func)
94
95 def EVT_QUERY_END_SESSION(win, func):
96 win.Connect(-1, -1, wxEVT_QUERY_END_SESSION, func)
97
98 def EVT_DROP_FILES(win, func):
99 win.Connect(-1, -1, wxEVT_DROP_FILES, func)
100
101 def EVT_INIT_DIALOG(win, func):
102 win.Connect(-1, -1, wxEVT_INIT_DIALOG, func)
103
104 def EVT_SYS_COLOUR_CHANGED(win, func):
105 win.Connect(-1, -1, wxEVT_SYS_COLOUR_CHANGED, func)
106
107 def EVT_DISPLAY_CHANGED(win, func):
108 win.Connect(-1, -1, wxEVT_DISPLAY_CHANGED, func)
109
110 def EVT_SHOW(win, func):
111 win.Connect(-1, -1, wxEVT_SHOW, func)
112
113 def EVT_MAXIMIZE(win, func):
114 win.Connect(-1, -1, wxEVT_MAXIMIZE, func)
115
116 def EVT_ICONIZE(win, func):
117 win.Connect(-1, -1, wxEVT_ICONIZE, func)
118
119 def EVT_NAVIGATION_KEY(win, func):
120 win.Connect(-1, -1, wxEVT_NAVIGATION_KEY, func)
121
122 def EVT_PALETTE_CHANGED(win, func):
123 win.Connect(-1, -1, wxEVT_PALETTE_CHANGED, func)
124
125 def EVT_QUERY_NEW_PALETTE(win, func):
126 win.Connect(-1, -1, wxEVT_QUERY_NEW_PALETTE, func)
127
128 def EVT_WINDOW_CREATE(win, func):
129 win.Connect(-1, -1, wxEVT_CREATE, func)
130
131 def EVT_WINDOW_DESTROY(win, func):
132 win.Connect(-1, -1, wxEVT_DESTROY, func)
133
134
135
136 def EVT_IDLE(win, func):
137 win.Connect(-1, -1, wxEVT_IDLE, func)
138
139 def EVT_UPDATE_UI(win, id, func):
140 win.Connect(id, -1, wxEVT_UPDATE_UI, func)
141
142 def EVT_UPDATE_UI_RANGE(win, id, id2, func):
143 win.Connect(id, id2, wxEVT_UPDATE_UI, func)
144
145
146 # Mouse Events
147 def EVT_LEFT_DOWN(win, func):
148 win.Connect(-1, -1, wxEVT_LEFT_DOWN, func)
149
150 def EVT_LEFT_UP(win, func):
151 win.Connect(-1, -1, wxEVT_LEFT_UP, func)
152
153 def EVT_MIDDLE_DOWN(win, func):
154 win.Connect(-1, -1, wxEVT_MIDDLE_DOWN, func)
155
156 def EVT_MIDDLE_UP(win, func):
157 win.Connect(-1, -1, wxEVT_MIDDLE_UP, func)
158
159 def EVT_RIGHT_DOWN(win, func):
160 win.Connect(-1, -1, wxEVT_RIGHT_DOWN, func)
161
162 def EVT_RIGHT_UP(win, func):
163 win.Connect(-1, -1, wxEVT_RIGHT_UP, func)
164
165 def EVT_MOTION(win, func):
166 win.Connect(-1, -1, wxEVT_MOTION, func)
167
168 def EVT_LEFT_DCLICK(win, func):
169 win.Connect(-1, -1, wxEVT_LEFT_DCLICK, func)
170
171 def EVT_MIDDLE_DCLICK(win, func):
172 win.Connect(-1, -1, wxEVT_MIDDLE_DCLICK, func)
173
174 def EVT_RIGHT_DCLICK(win, func):
175 win.Connect(-1, -1, wxEVT_RIGHT_DCLICK, func)
176
177 def EVT_LEAVE_WINDOW(win, func):
178 win.Connect(-1, -1, wxEVT_LEAVE_WINDOW, func)
179
180 def EVT_ENTER_WINDOW(win, func):
181 win.Connect(-1, -1, wxEVT_ENTER_WINDOW, func)
182
183 def EVT_MOUSEWHEEL(win, func):
184 win.Connect(-1, -1, wxEVT_MOUSEWHEEL, func)
185
186 # all mouse events
187 def EVT_MOUSE_EVENTS(win, func):
188 win.Connect(-1, -1, wxEVT_LEFT_DOWN, func)
189 win.Connect(-1, -1, wxEVT_LEFT_UP, func)
190 win.Connect(-1, -1, wxEVT_MIDDLE_DOWN, func)
191 win.Connect(-1, -1, wxEVT_MIDDLE_UP, func)
192 win.Connect(-1, -1, wxEVT_RIGHT_DOWN, func)
193 win.Connect(-1, -1, wxEVT_RIGHT_UP, func)
194 win.Connect(-1, -1, wxEVT_MOTION, func)
195 win.Connect(-1, -1, wxEVT_LEFT_DCLICK, func)
196 win.Connect(-1, -1, wxEVT_MIDDLE_DCLICK, func)
197 win.Connect(-1, -1, wxEVT_RIGHT_DCLICK, func)
198 win.Connect(-1, -1, wxEVT_LEAVE_WINDOW, func)
199 win.Connect(-1, -1, wxEVT_ENTER_WINDOW, func)
200
201 def EVT_MOUSE_CAPTURE_CHANGED(win, func):
202 win.Connect(-1, -1, wxEVT_MOUSE_CAPTURE_CHANGED, func)
203
204 # EVT_COMMAND
205 def EVT_COMMAND(win, id, cmd, func):
206 win.Connect(id, -1, cmd, func)
207
208 def EVT_COMMAND_RANGE(win, id1, id2, cmd, func):
209 win.Connect(id1, id2, cmd, func)
210
211
212 # Scrolling
213 def EVT_SCROLL(win, func):
214 win.Connect(-1, -1, wxEVT_SCROLL_TOP, func)
215 win.Connect(-1, -1, wxEVT_SCROLL_BOTTOM, func)
216 win.Connect(-1, -1, wxEVT_SCROLL_LINEUP, func)
217 win.Connect(-1, -1, wxEVT_SCROLL_LINEDOWN, func)
218 win.Connect(-1, -1, wxEVT_SCROLL_PAGEUP, func)
219 win.Connect(-1, -1, wxEVT_SCROLL_PAGEDOWN, func)
220 win.Connect(-1, -1, wxEVT_SCROLL_THUMBTRACK,func)
221 win.Connect(-1, -1, wxEVT_SCROLL_THUMBRELEASE,func)
222
223 def EVT_SCROLL_TOP(win, func):
224 win.Connect(-1, -1, wxEVT_SCROLL_TOP, func)
225
226 def EVT_SCROLL_BOTTOM(win, func):
227 win.Connect(-1, -1, wxEVT_SCROLL_BOTTOM, func)
228
229 def EVT_SCROLL_LINEUP(win, func):
230 win.Connect(-1, -1, wxEVT_SCROLL_LINEUP, func)
231
232 def EVT_SCROLL_LINEDOWN(win, func):
233 win.Connect(-1, -1, wxEVT_SCROLL_LINEDOWN, func)
234
235 def EVT_SCROLL_PAGEUP(win, func):
236 win.Connect(-1, -1, wxEVT_SCROLL_PAGEUP, func)
237
238 def EVT_SCROLL_PAGEDOWN(win, func):
239 win.Connect(-1, -1, wxEVT_SCROLL_PAGEDOWN, func)
240
241 def EVT_SCROLL_THUMBTRACK(win, func):
242 win.Connect(-1, -1, wxEVT_SCROLL_THUMBTRACK, func)
243
244 def EVT_SCROLL_THUMBRELEASE(win, func):
245 win.Connect(-1, -1, wxEVT_SCROLL_THUMBRELEASE, func)
246
247
248
249 # Scrolling, with an id
250 def EVT_COMMAND_SCROLL(win, id, func):
251 win.Connect(id, -1, wxEVT_SCROLL_TOP, func)
252 win.Connect(id, -1, wxEVT_SCROLL_BOTTOM, func)
253 win.Connect(id, -1, wxEVT_SCROLL_LINEUP, func)
254 win.Connect(id, -1, wxEVT_SCROLL_LINEDOWN, func)
255 win.Connect(id, -1, wxEVT_SCROLL_PAGEUP, func)
256 win.Connect(id, -1, wxEVT_SCROLL_PAGEDOWN, func)
257 win.Connect(id, -1, wxEVT_SCROLL_THUMBTRACK,func)
258 win.Connect(id, -1, wxEVT_SCROLL_THUMBRELEASE,func)
259
260 def EVT_COMMAND_SCROLL_TOP(win, id, func):
261 win.Connect(id, -1, wxEVT_SCROLL_TOP, func)
262
263 def EVT_COMMAND_SCROLL_BOTTOM(win, id, func):
264 win.Connect(id, -1, wxEVT_SCROLL_BOTTOM, func)
265
266 def EVT_COMMAND_SCROLL_LINEUP(win, id, func):
267 win.Connect(id, -1, wxEVT_SCROLL_LINEUP, func)
268
269 def EVT_COMMAND_SCROLL_LINEDOWN(win, id, func):
270 win.Connect(id, -1, wxEVT_SCROLL_LINEDOWN, func)
271
272 def EVT_COMMAND_SCROLL_PAGEUP(win, id, func):
273 win.Connect(id, -1, wxEVT_SCROLL_PAGEUP, func)
274
275 def EVT_COMMAND_SCROLL_PAGEDOWN(win, id, func):
276 win.Connect(id, -1, wxEVT_SCROLL_PAGEDOWN, func)
277
278 def EVT_COMMAND_SCROLL_THUMBTRACK(win, id, func):
279 win.Connect(id, -1, wxEVT_SCROLL_THUMBTRACK, func)
280
281 def EVT_COMMAND_SCROLL_THUMBRELEASE(win, id, func):
282 win.Connect(id, -1, wxEVT_SCROLL_THUMBRELEASE, func)
283
284 #---
285 def EVT_SCROLLWIN(win, func):
286 win.Connect(-1, -1, wxEVT_SCROLLWIN_TOP, func)
287 win.Connect(-1, -1, wxEVT_SCROLLWIN_BOTTOM, func)
288 win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEUP, func)
289 win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEDOWN, func)
290 win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEUP, func)
291 win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEDOWN, func)
292 win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBTRACK, func)
293 win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBRELEASE,func)
294
295 def EVT_SCROLLWIN_TOP(win, func):
296 win.Connect(-1, -1, wxEVT_SCROLLWIN_TOP, func)
297
298 def EVT_SCROLLWIN_BOTTOM(win, func):
299 win.Connect(-1, -1, wxEVT_SCROLLWIN_BOTTOM, func)
300
301 def EVT_SCROLLWIN_LINEUP(win, func):
302 win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEUP, func)
303
304 def EVT_SCROLLWIN_LINEDOWN(win, func):
305 win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEDOWN, func)
306
307 def EVT_SCROLLWIN_PAGEUP(win, func):
308 win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEUP, func)
309
310 def EVT_SCROLLWIN_PAGEDOWN(win, func):
311 win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEDOWN, func)
312
313 def EVT_SCROLLWIN_THUMBTRACK(win, func):
314 win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBTRACK, func)
315
316 def EVT_SCROLLWIN_THUMBRELEASE(win, func):
317 win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBRELEASE, func)
318
319
320
321 # Scrolling, with an id
322 def EVT_COMMAND_SCROLLWIN(win, id, func):
323 win.Connect(id, -1, wxEVT_SCROLLWIN_TOP, func)
324 win.Connect(id, -1, wxEVT_SCROLLWIN_BOTTOM, func)
325 win.Connect(id, -1, wxEVT_SCROLLWIN_LINEUP, func)
326 win.Connect(id, -1, wxEVT_SCROLLWIN_LINEDOWN, func)
327 win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEUP, func)
328 win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEDOWN, func)
329 win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBTRACK, func)
330 win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBRELEASE,func)
331
332 def EVT_COMMAND_SCROLLWIN_TOP(win, id, func):
333 win.Connect(id, -1, wxEVT_SCROLLWIN_TOP, func)
334
335 def EVT_COMMAND_SCROLLWIN_BOTTOM(win, id, func):
336 win.Connect(id, -1, wxEVT_SCROLLWIN_BOTTOM, func)
337
338 def EVT_COMMAND_SCROLLWIN_LINEUP(win, id, func):
339 win.Connect(id, -1, wxEVT_SCROLLWIN_LINEUP, func)
340
341 def EVT_COMMAND_SCROLLWIN_LINEDOWN(win, id, func):
342 win.Connect(id, -1, wxEVT_SCROLLWIN_LINEDOWN, func)
343
344 def EVT_COMMAND_SCROLLWIN_PAGEUP(win, id, func):
345 win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEUP, func)
346
347 def EVT_COMMAND_SCROLLWIN_PAGEDOWN(win, id, func):
348 win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEDOWN, func)
349
350 def EVT_COMMAND_SCROLLWIN_THUMBTRACK(win, id, func):
351 win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBTRACK, func)
352
353 def EVT_COMMAND_SCROLLWIN_THUMBRELEASE(win, id, func):
354 win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBRELEASE, func)
355
356
357 # Convenience commands
358 def EVT_BUTTON(win, id, func):
359 win.Connect(id, -1, wxEVT_COMMAND_BUTTON_CLICKED, func)
360
361 def EVT_CHECKBOX(win, id, func):
362 win.Connect(id, -1, wxEVT_COMMAND_CHECKBOX_CLICKED, func)
363
364 def EVT_CHOICE(win, id, func):
365 win.Connect(id, -1, wxEVT_COMMAND_CHOICE_SELECTED, func)
366
367 def EVT_LISTBOX(win, id, func):
368 win.Connect(id, -1, wxEVT_COMMAND_LISTBOX_SELECTED, func)
369
370 def EVT_LISTBOX_DCLICK(win, id, func):
371 win.Connect(id, -1, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, func)
372
373 def EVT_TEXT(win, id, func):
374 win.Connect(id, -1, wxEVT_COMMAND_TEXT_UPDATED, func)
375
376 def EVT_TEXT_ENTER(win, id, func):
377 win.Connect(id, -1, wxEVT_COMMAND_TEXT_ENTER, func)
378
379 def EVT_TEXT_URL(win, id, func):
380 win.Connect(id, -1, wxEVT_COMMAND_TEXT_URL, func)
381
382 def EVT_TEXT_MAXLEN(win, id, func):
383 win.Connect(id, -1, wxEVT_COMMAND_TEXT_MAXLEN, func)
384
385 def EVT_MENU(win, id, func):
386 win.Connect(id, -1, wxEVT_COMMAND_MENU_SELECTED, func)
387
388 def EVT_MENU_RANGE(win, id1, id2, func):
389 win.Connect(id1, id2, wxEVT_COMMAND_MENU_SELECTED, func)
390
391 def EVT_SLIDER(win, id, func):
392 win.Connect(id, -1, wxEVT_COMMAND_SLIDER_UPDATED, func)
393
394 def EVT_RADIOBOX(win, id, func):
395 win.Connect(id, -1, wxEVT_COMMAND_RADIOBOX_SELECTED, func)
396
397 def EVT_RADIOBUTTON(win, id, func):
398 win.Connect(id, -1, wxEVT_COMMAND_RADIOBUTTON_SELECTED, func)
399
400 def EVT_VLBOX(win, id, func):
401 win.Connect(id, -1, wxEVT_COMMAND_VLBOX_SELECTED, func)
402
403 def EVT_COMBOBOX(win, id, func):
404 win.Connect(id, -1, wxEVT_COMMAND_COMBOBOX_SELECTED, func)
405
406 def EVT_TOOL(win, id, func):
407 win.Connect(id, -1, wxEVT_COMMAND_TOOL_CLICKED, func)
408
409 def EVT_TOOL_RANGE(win, id, id2, func):
410 win.Connect(id, id2, wxEVT_COMMAND_TOOL_CLICKED, func)
411
412 def EVT_TOOL_RCLICKED(win, id, func):
413 win.Connect(id, -1, wxEVT_COMMAND_TOOL_RCLICKED, func)
414
415 def EVT_TOOL_RCLICKED_RANGE(win, id, id2, func):
416 win.Connect(id, id2, wxEVT_COMMAND_TOOL_RCLICKED, func)
417
418 def EVT_TOOL_ENTER(win, id, func):
419 win.Connect(id, -1, wxEVT_COMMAND_TOOL_ENTER, func)
420
421 def EVT_CHECKLISTBOX(win, id, func):
422 win.Connect(id, -1, wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, func)
423
424 def EVT_SPINCTRL(win, id, func):
425 win.Connect(id, -1, wxEVT_COMMAND_SPINCTRL_UPDATED, func)
426
427
428
429 # Generic command events
430
431 def EVT_COMMAND_LEFT_CLICK(win, id, func):
432 win.Connect(id, -1, wxEVT_COMMAND_LEFT_CLICK, func)
433
434 def EVT_COMMAND_LEFT_DCLICK(win, id, func):
435 win.Connect(id, -1, wxEVT_COMMAND_LEFT_DCLICK, func)
436
437 def EVT_COMMAND_RIGHT_CLICK(win, id, func):
438 win.Connect(id, -1, wxEVT_COMMAND_RIGHT_CLICK, func)
439
440 def EVT_COMMAND_RIGHT_DCLICK(win, id, func):
441 win.Connect(id, -1, wxEVT_COMMAND_RIGHT_DCLICK, func)
442
443 def EVT_COMMAND_SET_FOCUS(win, id, func):
444 win.Connect(id, -1, wxEVT_COMMAND_SET_FOCUS, func)
445
446 def EVT_COMMAND_KILL_FOCUS(win, id, func):
447 win.Connect(id, -1, wxEVT_COMMAND_KILL_FOCUS, func)
448
449 def EVT_COMMAND_ENTER(win, id, func):
450 win.Connect(id, -1, wxEVT_COMMAND_ENTER, func)
451
452
453 # wxNotebook events
454 def EVT_NOTEBOOK_PAGE_CHANGED(win, id, func):
455 win.Connect(id, -1, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, func)
456
457 def EVT_NOTEBOOK_PAGE_CHANGING(win, id, func):
458 win.Connect(id, -1, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, func)
459
460
461 # wxSpinButton
462 def EVT_SPIN_UP(win, id, func):
463 win.Connect(id, -1, wxEVT_SCROLL_LINEUP, func)
464
465 def EVT_SPIN_DOWN(win, id, func):
466 win.Connect(id, -1, wxEVT_SCROLL_LINEDOWN, func)
467
468 def EVT_SPIN(win, id, func):
469 win.Connect(id, -1, wxEVT_SCROLL_THUMBTRACK,func)
470
471
472 # wxTaskBarIcon
473 def EVT_TASKBAR_MOVE(win, func):
474 win.Connect(-1, -1, wxEVT_TASKBAR_MOVE, func)
475
476 def EVT_TASKBAR_LEFT_DOWN(win, func):
477 win.Connect(-1, -1, wxEVT_TASKBAR_LEFT_DOWN, func)
478
479 def EVT_TASKBAR_LEFT_UP(win, func):
480 win.Connect(-1, -1, wxEVT_TASKBAR_LEFT_UP, func)
481
482 def EVT_TASKBAR_RIGHT_DOWN(win, func):
483 win.Connect(-1, -1, wxEVT_TASKBAR_RIGHT_DOWN, func)
484
485 def EVT_TASKBAR_RIGHT_UP(win, func):
486 win.Connect(-1, -1, wxEVT_TASKBAR_RIGHT_UP, func)
487
488 def EVT_TASKBAR_LEFT_DCLICK(win, func):
489 win.Connect(-1, -1, wxEVT_TASKBAR_LEFT_DCLICK, func)
490
491 def EVT_TASKBAR_RIGHT_DCLICK(win, func):
492 win.Connect(-1, -1, wxEVT_TASKBAR_RIGHT_DCLICK, func)
493
494
495 # wxSashWindow
496 def EVT_SASH_DRAGGED(win, id, func):
497 win.Connect(id, -1, wxEVT_SASH_DRAGGED, func)
498
499 def EVT_SASH_DRAGGED_RANGE(win, id1, id2, func):
500 win.Connect(id1, id2, wxEVT_SASH_DRAGGED, func)
501
502 def EVT_QUERY_LAYOUT_INFO(win, func):
503 win.Connect(-1, -1, wxEVT_EVT_QUERY_LAYOUT_INFO, func)
504
505 def EVT_CALCULATE_LAYOUT(win, func):
506 win.Connect(-1, -1, wxEVT_EVT_CALCULATE_LAYOUT, func)
507
508
509 #wxSplitterWindow
510 def EVT_SPLITTER_SASH_POS_CHANGING(win, id, func):
511 win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, func)
512
513 def EVT_SPLITTER_SASH_POS_CHANGED(win, id, func):
514 win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, func)
515
516 def EVT_SPLITTER_UNSPLIT(win, id, func):
517 win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_UNSPLIT, func)
518
519 def EVT_SPLITTER_DOUBLECLICKED(win, id, func):
520 win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, func)
521
522
523 # wxTimer
524 def EVT_TIMER(win, id, func):
525 win.Connect(id, -1, wxEVT_TIMER, func)
526
527 # wxProcess
528 def EVT_END_PROCESS(eh, id, func):
529 eh.Connect(id, -1, wxEVT_END_PROCESS, func)
530
531
532 # wxJoyStick
533 def EVT_JOY_DOWN(win, func):
534 win.Connect(-1, -1, wxEVT_JOY_BUTTON_DOWN, func)
535
536 def EVT_JOY_UP(win, func):
537 win.Connect(-1, -1, wxEVT_JOY_BUTTON_UP, func)
538
539 def EVT_JOY_MOVE(win, func):
540 win.Connect(-1, -1, wxEVT_JOY_MOVE, func)
541
542 def EVT_JOY_ZMOVE(win, func):
543 win.Connect(-1, -1, wxEVT_JOY_ZMOVE, func)
544
545 def EVT_JOYSTICK_EVENTS(win, func):
546 win.Connect(-1, -1, wxEVT_JOY_BUTTON_DOWN, func)
547 win.Connect(-1, -1, wxEVT_JOY_BUTTON_UP, func)
548 win.Connect(-1, -1, wxEVT_JOY_MOVE, func)
549 win.Connect(-1, -1, wxEVT_JOY_ZMOVE, func)
550
551
552 def EVT_TOGGLEBUTTON(win, id, func):
553 win.Connect(id, -1, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, func)
554
555
556
557 def EVT_CONTEXT_MENU(win, func):
558 win.Connect(-1, -1, wxEVT_CONTEXT_MENU, func)
559
560
561 #----------------------------------------------------------------------
562
563 class wxTimer(wxPyTimer):
564 def __init__(self, evtHandler = None, id = -1):
565 if evtHandler is None:
566 wxPyTimer.__init__(self, self.Notify) # derived class must provide
567 # Notify(self) method.
568 else:
569 wxPyTimer.__init__(self, None)
570 self.SetOwner(evtHandler, id)
571
572 #----------------------------------------------------------------------
573 # aliases
574
575 wxColor = wxColour
576 wxNamedColor = wxNamedColour
577 wxPen = wxPyPen
578 wxScrollbar = wxScrollBar
579
580
581 # backwards compatibility
582 wxNoRefBitmap = wxBitmap
583 wxPyDefaultPosition = wxDefaultPosition
584 wxPyDefaultSize = wxDefaultSize
585 NULL = None
586 wxSystemSettings_GetSystemColour = wxSystemSettings_GetColour
587 wxSystemSettings_GetSystemFont = wxSystemSettings_GetFont
588 wxSystemSettings_GetSystemMetric = wxSystemSettings_GetMetric
589
590 #----------------------------------------------------------------------
591 # wxGTK sets the locale when initialized. Doing this at the Python
592 # level should set it up to match what GTK is doing at the C level.
593 if wxPlatform == "__WXGTK__":
594 try:
595 import locale
596 locale.setlocale(locale.LC_ALL, "")
597 except:
598 pass
599
600
601
602 #----------------------------------------------------------------------
603 # wxWindows version numbers. wxPython version is in __version__.
604
605 wxMAJOR_VERSION = wxc.wxMAJOR_VERSION
606 wxMINOR_VERSION = wxc.wxMINOR_VERSION
607 wxRELEASE_NUMBER = wxc.wxRELEASE_NUMBER
608 wxVERSION_STRING = wxc.wxVERSION_STRING
609 wxVERSION_NUMBER = wxc.wxVERSION_NUMBER
610
611 wxVERSION = (wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER)
612
613
614 #----------------------------------------------------------------------
615 # This helper function will take a wxPython object and convert it to
616 # another wxPython object type. This will not be able to create objects
617 # that are derived from wxPython classes by the user, only those that are
618 # actually part of wxPython and directly corespond to C++ objects.
619 #
620 # This is useful in situations where some method returns a generic
621 # type such as wxWindow, but you know that it is actually some
622 # derived type such as a wxTextCtrl. You can't call wxTextCtrl specific
623 # methods on a wxWindow object, but you can use this function to
624 # create a wxTextCtrl object that will pass the same pointer to
625 # the C++ code. You use it like this:
626 #
627 # textCtrl = wxPyTypeCast(window, "wxTextCtrl")
628 #
629 #
630 # WARNING: Using this function to type cast objects into types that
631 # they are not is not recommended and is likely to cause your
632 # program to crash... Hard.
633 #
634
635 def wxPyTypeCast(obj, typeStr):
636 if obj is None:
637 return None
638 theClass = globals()[typeStr+"Ptr"]
639 typeStr = __wxPyPtrTypeMap.get(typeStr, typeStr)
640 if hasattr(obj, "this"):
641 # if already the right type then just return it
642 if isinstance(obj, theClass) or obj.__class__ is theClass:
643 return obj
644 newPtr = ptrcast(obj.this, typeStr+"_p")
645 else:
646 newPtr = ptrcast(obj, typeStr+"_p")
647 theObj = theClass(newPtr)
648 if hasattr(obj, "this"):
649 theObj.thisown = obj.thisown
650 return theObj
651
652
653 #----------------------------------------------------------------------------
654
655 class wxPyDeadObjectError(AttributeError):
656 pass
657
658 class _wxPyDeadObject:
659 """
660 Instances of wx objects that are OOR capable will have their __class__
661 changed to this class when the C++ object is deleted. This should help
662 prevent crashes due to referencing a bogus C++ pointer.
663 """
664 reprStr = "wxPython wrapper for DELETED %s object! (The C++ object no longer exists.)"
665 attrStr = "The C++ part of the %s object has been deleted, attribute access no longer allowed."
666
667 def __repr__( self ):
668 if not hasattr(self, "_name"):
669 self._name = "[unknown]"
670 return self.reprStr % self._name
671
672 def __getattr__( self, *args ):
673 if not hasattr(self, "_name"):
674 self._name = "[unknown]"
675 raise wxPyDeadObjectError( self.attrStr % self._name )
676
677 def __nonzero__(self):
678 return 0
679
680
681 #----------------------------------------------------------------------
682 #----------------------------------------------------------------------
683
684 class wxPyOnDemandOutputWindow:
685 def __init__(self, title = "wxPython: stdout/stderr"):
686 self.frame = None
687 self.title = title
688 self.parent = None
689
690 def SetParent(self, parent):
691 self.parent = parent
692
693 def OnCloseWindow(self, event):
694 if self.frame != None:
695 self.frame.Destroy()
696 self.frame = None
697 self.text = None
698
699 # These methods provide the file-like output behaviour.
700 def write(self, str):
701 if not wxThread_IsMain():
702 # Aquire the GUI mutex before making GUI calls. Mutex is released
703 # when locker is deleted at the end of this function.
704 locker = wxMutexGuiLocker()
705
706 if not self.frame:
707 self.frame = wxFrame(self.parent, -1, self.title,
708 style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
709 self.text = wxTextCtrl(self.frame, -1, "",
710 style = wxTE_MULTILINE|wxTE_READONLY)
711 self.frame.SetSize(wxSize(450, 300))
712 self.frame.Show(true)
713 EVT_CLOSE(self.frame, self.OnCloseWindow)
714 self.text.AppendText(str)
715
716 def close(self):
717 if self.frame != None:
718 if not wxThread_IsMain():
719 locker = wxMutexGuiLocker()
720 self.frame.Close()
721
722
723 _defRedirect = (wxPlatform == '__WXMSW__')
724
725 #----------------------------------------------------------------------
726 # The main application class. Derive from this and implement an OnInit
727 # method that creates a frame and then calls self.SetTopWindow(frame)
728
729 class wxApp(wxPyApp):
730 error = 'wxApp.error'
731 outputWindowClass = wxPyOnDemandOutputWindow
732
733 def __init__(self, redirect=_defRedirect, filename=None):
734 wxPyApp.__init__(self)
735 self.stdioWin = None
736 self.saveStdio = (sys.stdout, sys.stderr)
737 if redirect:
738 self.RedirectStdio(filename)
739 # this initializes wxWindows and then calls our OnInit
740 _wxStart(self.OnInit)
741
742
743 def __del__(self):
744 try:
745 self.RestoreStdio()
746 except:
747 pass
748
749
750 def SetTopWindow(self, frame):
751 if self.stdioWin:
752 self.stdioWin.SetParent(frame)
753 wxPyApp.SetTopWindow(self, frame)
754
755
756 def MainLoop(self):
757 wxPyApp.MainLoop(self)
758 self.RestoreStdio()
759
760
761 def RedirectStdio(self, filename):
762 if filename:
763 sys.stdout = sys.stderr = open(filename, 'a')
764 else:
765 self.stdioWin = self.outputWindowClass() # wxPyOnDemandOutputWindow
766 sys.stdout = sys.stderr = self.stdioWin
767
768
769 def RestoreStdio(self):
770 sys.stdout, sys.stderr = self.saveStdio
771
772
773 #----------------------------------------------------------------------------
774
775 class wxPySimpleApp(wxApp):
776 def __init__(self, flag=0):
777 wxApp.__init__(self, flag)
778 def OnInit(self):
779 return true
780
781
782 class wxPyWidgetTester(wxApp):
783 def __init__(self, size = (250, 100)):
784 self.size = size
785 wxApp.__init__(self, 0)
786
787 def OnInit(self):
788 self.frame = wxFrame(None, -1, "Widget Tester", pos=(0,0), size=self.size)
789 self.SetTopWindow(self.frame)
790 return true
791
792 def SetWidget(self, widgetClass, *args):
793 w = apply(widgetClass, (self.frame,) + args)
794 self.frame.Show(true)
795
796 #----------------------------------------------------------------------------
797 # DO NOT hold any other references to this object. This is how we
798 # know when to cleanup system resources that wxWin is holding. When
799 # the sys module is unloaded, the refcount on sys.__wxPythonCleanup
800 # goes to zero and it calls the wxApp_CleanUp function.
801
802 class __wxPyCleanup:
803 def __init__(self):
804 self.cleanup = wxc.wxApp_CleanUp
805 def __del__(self):
806 self.cleanup()
807
808 sys.__wxPythonCleanup = __wxPyCleanup()
809
810 ## # another possible solution, but it gets called too early...
811 ## if sys.version[0] == '2':
812 ## import atexit
813 ## atexit.register(wxc.wxApp_CleanUp)
814 ## else:
815 ## sys.exitfunc = wxc.wxApp_CleanUp
816
817
818 #----------------------------------------------------------------------------
819 #----------------------------------------------------------------------------