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