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