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