]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_extras.py
removed duplicate method def
[wxWidgets.git] / wxPython / src / _extras.py
CommitLineData
7bf85405
RD
1#----------------------------------------------------------------------------
2# Name: _extra.py
1e4a197e 3# Purpose: This file is appended to the shadow class file generated
7bf85405
RD
4# by SWIG. We add some unSWIGable things here.
5#
6# Author: Robin Dunn
7#
8# Created: 6/30/97
7bf85405
RD
9# Copyright: (c) 1998 by Total Control Software
10# Licence: wxWindows license
11#----------------------------------------------------------------------------
12
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
7bf85405
RD
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
3ef86e32
RD
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
7bf85405
RD
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
8bf5d46e
RD
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
3ef86e32
RD
71def EVT_HOTKEY(win, func):
72 win.Connect(-1, -1, wxEVT_HOTKEY, func)
73
afb810d9
RD
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
7bf85405
RD
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
7b7ac0ab
RD
92def EVT_CHILD_FOCUS(win, func):
93 win.Connect(-1, -1, wxEVT_CHILD_FOCUS, func)
94
7bf85405
RD
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
be43cc44
RD
116def EVT_DISPLAY_CHANGED(win, func):
117 win.Connect(-1, -1, wxEVT_DISPLAY_CHANGED, func)
118
7bf85405
RD
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
3af4e610
RD
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):
54b96882 138 win.Connect(-1, -1, wxEVT_CREATE, func)
3af4e610
RD
139
140def EVT_WINDOW_DESTROY(win, func):
54b96882 141 win.Connect(-1, -1, wxEVT_DESTROY, func)
3af4e610 142
1e4a197e
RD
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
203c2f9a
RD
149def EVT_SET_CURSOR(win, func):
150 win.Connect(-1, -1, wxEVT_SET_CURSOR, func)
151
3af4e610
RD
152
153
cf694132
RD
154def EVT_IDLE(win, func):
155 win.Connect(-1, -1, wxEVT_IDLE, func)
156
bb0054cd
RD
157def EVT_UPDATE_UI(win, id, func):
158 win.Connect(id, -1, wxEVT_UPDATE_UI, func)
159
eb715945
RD
160def EVT_UPDATE_UI_RANGE(win, id, id2, func):
161 win.Connect(id, id2, wxEVT_UPDATE_UI, func)
162
7bf85405
RD
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
d1679124
RD
201def EVT_MOUSEWHEEL(win, func):
202 win.Connect(-1, -1, wxEVT_MOUSEWHEEL, func)
7bf85405
RD
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
6d26dc89
RD
219def EVT_MOUSE_CAPTURE_CHANGED(win, func):
220 win.Connect(-1, -1, wxEVT_MOUSE_CAPTURE_CHANGED, func)
221
7bf85405
RD
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
26b9cf27 229
7bf85405
RD
230# Scrolling
231def EVT_SCROLL(win, func):
83f3dd45
RD
232 win.Connect(-1, -1, wxEVT_SCROLL_TOP, func)
233 win.Connect(-1, -1, wxEVT_SCROLL_BOTTOM, func)
234 win.Connect(-1, -1, wxEVT_SCROLL_LINEUP, func)
235 win.Connect(-1, -1, wxEVT_SCROLL_LINEDOWN, func)
236 win.Connect(-1, -1, wxEVT_SCROLL_PAGEUP, func)
237 win.Connect(-1, -1, wxEVT_SCROLL_PAGEDOWN, func)
238 win.Connect(-1, -1, wxEVT_SCROLL_THUMBTRACK, func)
26b9cf27 239 win.Connect(-1, -1, wxEVT_SCROLL_THUMBRELEASE,func)
83f3dd45 240 win.Connect(-1, -1, wxEVT_SCROLL_ENDSCROLL, func)
7bf85405
RD
241
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
26b9cf27
RD
263def EVT_SCROLL_THUMBRELEASE(win, func):
264 win.Connect(-1, -1, wxEVT_SCROLL_THUMBRELEASE, func)
265
83f3dd45
RD
266def EVT_SCROLL_ENDSCROLL(win, func):
267 win.Connect(-1, -1, wxEVT_SCROLL_ENDSCROLL, func)
268
7bf85405
RD
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)
26b9cf27 280 win.Connect(id, -1, wxEVT_SCROLL_THUMBRELEASE,func)
1e4a197e 281 win.Connect(id, -1, wxEVT_SCROLL_ENDSCROLL, func)
7bf85405
RD
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
26b9cf27
RD
304def EVT_COMMAND_SCROLL_THUMBRELEASE(win, id, func):
305 win.Connect(id, -1, wxEVT_SCROLL_THUMBRELEASE, func)
306
83f3dd45
RD
307def EVT_COMMAND_SCROLL_ENDSCROLL(win, id, func):
308 win.Connect(id, -1, wxEVT_SCROLL_ENDSCROLL, func)
309
d426c97e
RD
310#---
311def EVT_SCROLLWIN(win, func):
26b9cf27
RD
312 win.Connect(-1, -1, wxEVT_SCROLLWIN_TOP, func)
313 win.Connect(-1, -1, wxEVT_SCROLLWIN_BOTTOM, func)
314 win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEUP, func)
315 win.Connect(-1, -1, wxEVT_SCROLLWIN_LINEDOWN, func)
316 win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEUP, func)
317 win.Connect(-1, -1, wxEVT_SCROLLWIN_PAGEDOWN, func)
318 win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBTRACK, func)
319 win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBRELEASE,func)
d426c97e
RD
320
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
26b9cf27
RD
342def EVT_SCROLLWIN_THUMBRELEASE(win, func):
343 win.Connect(-1, -1, wxEVT_SCROLLWIN_THUMBRELEASE, func)
344
d426c97e
RD
345
346
347# Scrolling, with an id
348def EVT_COMMAND_SCROLLWIN(win, id, func):
26b9cf27
RD
349 win.Connect(id, -1, wxEVT_SCROLLWIN_TOP, func)
350 win.Connect(id, -1, wxEVT_SCROLLWIN_BOTTOM, func)
351 win.Connect(id, -1, wxEVT_SCROLLWIN_LINEUP, func)
352 win.Connect(id, -1, wxEVT_SCROLLWIN_LINEDOWN, func)
353 win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEUP, func)
354 win.Connect(id, -1, wxEVT_SCROLLWIN_PAGEDOWN, func)
355 win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBTRACK, func)
356 win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBRELEASE,func)
d426c97e
RD
357
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)
7bf85405 378
26b9cf27
RD
379def EVT_COMMAND_SCROLLWIN_THUMBRELEASE(win, id, func):
380 win.Connect(id, -1, wxEVT_SCROLLWIN_THUMBRELEASE, func)
381
382
7bf85405
RD
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
c7e7022c
RD
405def EVT_TEXT_URL(win, id, func):
406 win.Connect(id, -1, wxEVT_COMMAND_TEXT_URL, func)
407
00b6c4e3
RD
408def EVT_TEXT_MAXLEN(win, id, func):
409 win.Connect(id, -1, wxEVT_COMMAND_TEXT_MAXLEN, func)
410
7bf85405
RD
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
3af4e610
RD
435def EVT_TOOL_RANGE(win, id, id2, func):
436 win.Connect(id, id2, wxEVT_COMMAND_TOOL_CLICKED, func)
437
7bf85405
RD
438def EVT_TOOL_RCLICKED(win, id, func):
439 win.Connect(id, -1, wxEVT_COMMAND_TOOL_RCLICKED, func)
440
3af4e610
RD
441def EVT_TOOL_RCLICKED_RANGE(win, id, id2, func):
442 win.Connect(id, id2, wxEVT_COMMAND_TOOL_RCLICKED, func)
443
7bf85405
RD
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
3af4e610
RD
450def EVT_SPINCTRL(win, id, func):
451 win.Connect(id, -1, wxEVT_COMMAND_SPINCTRL_UPDATED, func)
452
453
7bf85405
RD
454
455# Generic command events
456
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
b639c3c5 479# wxSpinButton
62bd0874
RD
480def EVT_SPIN_UP(win, id, func):
481 win.Connect(id, -1, wxEVT_SCROLL_LINEUP, func)
482
483def EVT_SPIN_DOWN(win, id, func):
f6bcfd97 484 win.Connect(id, -1, wxEVT_SCROLL_LINEDOWN, func)
62bd0874
RD
485
486def EVT_SPIN(win, id, func):
62bd0874
RD
487 win.Connect(id, -1, wxEVT_SCROLL_THUMBTRACK,func)
488
489
08127323
RD
490# wxSashWindow
491def EVT_SASH_DRAGGED(win, id, func):
492 win.Connect(id, -1, wxEVT_SASH_DRAGGED, func)
493
494def EVT_SASH_DRAGGED_RANGE(win, id1, id2, func):
495 win.Connect(id1, id2, wxEVT_SASH_DRAGGED, func)
496
497def EVT_QUERY_LAYOUT_INFO(win, func):
1fded56b 498 win.Connect(-1, -1, wxEVT_QUERY_LAYOUT_INFO, func)
08127323
RD
499
500def EVT_CALCULATE_LAYOUT(win, func):
1fded56b 501 win.Connect(-1, -1, wxEVT_CALCULATE_LAYOUT, func)
08127323
RD
502
503
bb0054cd
RD
504#wxSplitterWindow
505def EVT_SPLITTER_SASH_POS_CHANGING(win, id, func):
506 win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, func)
507
508def EVT_SPLITTER_SASH_POS_CHANGED(win, id, func):
509 win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, func)
510
511def EVT_SPLITTER_UNSPLIT(win, id, func):
512 win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_UNSPLIT, func)
513
514def EVT_SPLITTER_DOUBLECLICKED(win, id, func):
515 win.Connect(id, -1, wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, func)
516
b639c3c5 517
f6bcfd97
BP
518# wxTimer
519def EVT_TIMER(win, id, func):
520 win.Connect(id, -1, wxEVT_TIMER, func)
521
c368d904
RD
522# wxProcess
523def EVT_END_PROCESS(eh, id, func):
524 eh.Connect(id, -1, wxEVT_END_PROCESS, func)
f6bcfd97 525
185d7c3e
RD
526
527# wxJoyStick
528def EVT_JOY_DOWN(win, func):
ac346f50 529 win.Connect(-1, -1, wxEVT_JOY_BUTTON_DOWN, func)
185d7c3e
RD
530
531def EVT_JOY_UP(win, func):
ac346f50 532 win.Connect(-1, -1, wxEVT_JOY_BUTTON_UP, func)
185d7c3e
RD
533
534def EVT_JOY_MOVE(win, func):
535 win.Connect(-1, -1, wxEVT_JOY_MOVE, func)
536
537def EVT_JOY_ZMOVE(win, func):
538 win.Connect(-1, -1, wxEVT_JOY_ZMOVE, func)
539
540def EVT_JOYSTICK_EVENTS(win, func):
ac346f50
RD
541 win.Connect(-1, -1, wxEVT_JOY_BUTTON_DOWN, func)
542 win.Connect(-1, -1, wxEVT_JOY_BUTTON_UP, func)
185d7c3e
RD
543 win.Connect(-1, -1, wxEVT_JOY_MOVE, func)
544 win.Connect(-1, -1, wxEVT_JOY_ZMOVE, func)
545
d1679124
RD
546
547def EVT_TOGGLEBUTTON(win, id, func):
548 win.Connect(id, -1, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, func)
549
550
4f3449b4 551
4f3449b4
RD
552def EVT_CONTEXT_MENU(win, func):
553 win.Connect(-1, -1, wxEVT_CONTEXT_MENU, func)
554
555
9c039d08 556#----------------------------------------------------------------------
7bf85405
RD
557
558class wxTimer(wxPyTimer):
185d7c3e
RD
559 def __init__(self, evtHandler = None, id = -1):
560 if evtHandler is None:
561 wxPyTimer.__init__(self, self.Notify) # derived class must provide
562 # Notify(self) method.
563 else:
564 wxPyTimer.__init__(self, None)
565 self.SetOwner(evtHandler, id)
7bf85405 566
7bf85405
RD
567#----------------------------------------------------------------------
568# aliases
569
b639c3c5 570wxColor = wxColour
7bf85405 571wxNamedColor = wxNamedColour
ecc08ead 572wxPen = wxPyPen
293a0a86 573wxScrollbar = wxScrollBar
1e4a197e
RD
574wxPoint2D = wxPoint2DDouble
575
576wxPyAssertionError = wxc.wxPyAssertionError
293a0a86 577
af309447 578
6999b0d8 579# backwards compatibility
1e4a197e
RD
580wxNoRefBitmap = wxBitmap
581wxPyDefaultPosition = wxDefaultPosition
582wxPyDefaultSize = wxDefaultSize
583NULL = None
68320e40
RD
584wxSystemSettings_GetSystemColour = wxSystemSettings_GetColour
585wxSystemSettings_GetSystemFont = wxSystemSettings_GetFont
586wxSystemSettings_GetSystemMetric = wxSystemSettings_GetMetric
00b6c4e3 587
1e4a197e
RD
588
589# workarounds for bad wxRTTI names
590__wxPyPtrTypeMap['wxGauge95'] = 'wxGauge'
1fded56b
RD
591__wxPyPtrTypeMap['wxSlider95'] = 'wxSlider'
592__wxPyPtrTypeMap['wxStatusBar95'] = 'wxStatusBar'
1e4a197e
RD
593
594
595
596def NewId():
597 import warnings
598 warnings.warn("Use wxNewId instead", DeprecationWarning, 2)
599 return wxNewId()
600
601def RegisterId(ID):
602 import warnings
603 warnings.warn("Use wxRegisterId instead", DeprecationWarning, 2)
604 return wxRegisterId(ID)
605
606
607
608# Use Python's bool constants if available, make aliases if not
609try:
610 True
611except NameError:
612 True = 1==1
613 False = 1==0
614
615# Backwards compaatible
616TRUE = true = True
617FALSE = false = False
618
619
a3fbed81 620#----------------------------------------------------------------------
00b6c4e3
RD
621# wxGTK sets the locale when initialized. Doing this at the Python
622# level should set it up to match what GTK is doing at the C level.
293a0a86
RD
623if wxPlatform == "__WXGTK__":
624 try:
625 import locale
626 locale.setlocale(locale.LC_ALL, "")
627 except:
628 pass
00b6c4e3 629
1fded56b
RD
630# On MSW add the directory where the wxWindows catalogs were installed
631# to the default catalog path.
1e4a197e
RD
632if wxPlatform == "__WXMSW__":
633 import os
634 localedir = os.path.join(os.path.split(__file__)[0], "locale")
635 wxLocale_AddCatalogLookupPathPrefix(localedir)
636 del os
a3fbed81
RD
637
638#----------------------------------------------------------------------
1fded56b
RD
639# Load version numbers from __version__... Ensure that major and minor
640# versions are the same for both wxPython and wxWindows.
a3fbed81 641
1fded56b
RD
642from wxPython.__version__ import *
643__version__ = wxVERSION_STRING
a3fbed81 644
1fded56b
RD
645assert wxMAJOR_VERSION == wxc.wxMAJOR_VERSION, "wxPython/wxWindows version mismatch"
646assert wxMINOR_VERSION == wxc.wxMINOR_VERSION, "wxPython/wxWindows version mismatch"
647if wxRELEASE_VERSION != wxc.wxRELEASE_VERSION:
648 import warnings
649 warnings.warn("wxPython/wxWindows release number mismatch")
a3fbed81
RD
650
651
8bf5d46e
RD
652#----------------------------------------------------------------------
653# This helper function will take a wxPython object and convert it to
654# another wxPython object type. This will not be able to create objects
7bcd390c 655# that are derived from wxPython classes by the user, only those that are
8bf5d46e
RD
656# actually part of wxPython and directly corespond to C++ objects.
657#
658# This is useful in situations where some method returns a generic
659# type such as wxWindow, but you know that it is actually some
660# derived type such as a wxTextCtrl. You can't call wxTextCtrl specific
661# methods on a wxWindow object, but you can use this function to
662# create a wxTextCtrl object that will pass the same pointer to
663# the C++ code. You use it like this:
664#
665# textCtrl = wxPyTypeCast(window, "wxTextCtrl")
666#
667#
668# WARNING: Using this function to type cast objects into types that
669# they are not is not recommended and is likely to cause your
670# program to crash... Hard.
671#
672
673def wxPyTypeCast(obj, typeStr):
83b18bab
RD
674 if obj is None:
675 return None
9416aa89
RD
676 theClass = globals()[typeStr+"Ptr"]
677 typeStr = __wxPyPtrTypeMap.get(typeStr, typeStr)
8bf5d46e 678 if hasattr(obj, "this"):
2aab8f16
RD
679 # if already the right type then just return it
680 if isinstance(obj, theClass) or obj.__class__ is theClass:
9416aa89 681 return obj
8bf5d46e
RD
682 newPtr = ptrcast(obj.this, typeStr+"_p")
683 else:
684 newPtr = ptrcast(obj, typeStr+"_p")
8bf5d46e 685 theObj = theClass(newPtr)
6999b0d8
RD
686 if hasattr(obj, "this"):
687 theObj.thisown = obj.thisown
8bf5d46e
RD
688 return theObj
689
1e4a197e
RD
690#----------------------------------------------------------------------------
691# An isinstance for Pythons < 2.2 that can check a sequence of class objects
692# like the one in 2.2 can.
693
694def wxPy_isinstance(obj, klasses):
695 import types
696 if sys.version[:3] < "2.2" and type(klasses) in [types.TupleType, types.ListType]:
697 for klass in klasses:
698 if isinstance(obj, klass): return True
699 return False
700 else:
701 return isinstance(obj, klasses)
8bf5d46e 702
4acff284 703#----------------------------------------------------------------------------
72797a7d
RD
704_wxCallAfterId = None
705
706def wxCallAfter(callable, *args, **kw):
707 """
708 Call the specified function after the current and pending event
c2dac736
RD
709 handlers have been completed. This is also good for making GUI
710 method calls from non-GUI threads.
72797a7d
RD
711 """
712 app = wxGetApp()
713 assert app, 'No wxApp created yet'
714
715 global _wxCallAfterId
716 if _wxCallAfterId is None:
1542ea39 717 _wxCallAfterId = wxNewEventType()
72797a7d 718 app.Connect(-1, -1, _wxCallAfterId,
1fded56b 719 lambda event: event.callable(*event.args, **event.kw) )
72797a7d
RD
720 evt = wxPyEvent()
721 evt.SetEventType(_wxCallAfterId)
722 evt.callable = callable
723 evt.args = args
724 evt.kw = kw
725 wxPostEvent(app, evt)
726
1fded56b
RD
727
728#----------------------------------------------------------------------
729
730
731class wxFutureCall:
732 """
733 A convenience class for wxTimer, that calls the given callable
734 object once after the given amount of milliseconds, passing any
735 positional or keyword args. The return value of the callable is
736 availbale after it has been run with the GetResult method.
737
738 If you don't need to get the return value or restart the timer
739 then there is no need to hold a reference to this object. It will
740 hold a reference to itself while the timer is running (the timer
741 has a reference to self.Notify) but the cycle will be broken when
742 the timer completes, automatically cleaning up the wxFutureCall
743 object.
744 """
745 def __init__(self, millis, callable, *args, **kwargs):
746 self.millis = millis
747 self.callable = callable
748 self.SetArgs(*args, **kwargs)
749 self.runCount = 0
750 self.hasRun = False
751 self.result = None
752 self.timer = None
753 self.Start()
754
755 def __del__(self):
756 self.Stop()
757
758
759 def Start(self, millis=None):
760 """
761 (Re)start the timer
762 """
763 self.hasRun = False
764 if millis is not None:
765 self.millis = millis
766 self.Stop()
767 self.timer = wxPyTimer(self.Notify)
768 self.timer.Start(self.millis, wxTIMER_ONE_SHOT)
769 Restart = Start
770
771
772 def Stop(self):
773 """
774 Stop and destroy the timer.
775 """
776 if self.timer is not None:
777 self.timer.Stop()
778 self.timer = None
779
780
781 def GetInterval(self):
782 if self.timer is not None:
783 return self.timer.GetInterval()
784 else:
785 return 0
786
787
788 def IsRunning(self):
789 return self.timer is not None and self.timer.IsRunning()
790
791
792 def SetArgs(self, *args, **kwargs):
793 """
794 (Re)set the args passed to the callable object. This is
795 useful in conjunction with Restart if you want to schedule a
796 new call to the same callable object but with different
797 parameters.
798 """
799 self.args = args
800 self.kwargs = kwargs
801
802 def HasRun(self):
803 return self.hasRun
804
805 def GetResult(self):
806 return self.result
807
808 def Notify(self):
809 """
810 The timer has expired so call the callable.
811 """
812 if self.callable and getattr(self.callable, 'im_self', True):
813 self.runCount += 1
814 self.result = self.callable(*self.args, **self.kwargs)
815 self.hasRun = True
816 wxCallAfter(self.Stop)
817
1e4a197e 818
72797a7d 819#----------------------------------------------------------------------
4acff284 820
7cdaed0b
RD
821class wxPyDeadObjectError(AttributeError):
822 pass
4acff284
RD
823
824class _wxPyDeadObject:
825 """
826 Instances of wx objects that are OOR capable will have their __class__
827 changed to this class when the C++ object is deleted. This should help
828 prevent crashes due to referencing a bogus C++ pointer.
829 """
7cdaed0b 830 reprStr = "wxPython wrapper for DELETED %s object! (The C++ object no longer exists.)"
fc51b8c3 831 attrStr = "The C++ part of the %s object has been deleted, attribute access no longer allowed."
7cdaed0b 832
4acff284
RD
833 def __repr__( self ):
834 if not hasattr(self, "_name"):
835 self._name = "[unknown]"
7cdaed0b 836 return self.reprStr % self._name
4acff284
RD
837
838 def __getattr__( self, *args ):
839 if not hasattr(self, "_name"):
840 self._name = "[unknown]"
7cdaed0b
RD
841 raise wxPyDeadObjectError( self.attrStr % self._name )
842
843 def __nonzero__(self):
844 return 0
4acff284
RD
845
846
1fded56b
RD
847#----------------------------------------------------------------------
848
849class wxNotebookPage(wxPanel):
850 """
851 There is an old (and apparently unsolvable) bug when placing a
852 window with a nonstandard background colour in a wxNotebook on
853 wxGTK, as the notbooks's background colour would always be used
854 when the window is refreshed. The solution is to place a panel in
855 the notbook and the coloured window on the panel, sized to cover
856 the panel. This simple class does that for you, just put an
857 instance of this in the notebook and make your regular window a
858 child of this one and it will handle the resize for you.
859 """
860 def __init__(self, parent, id=-1,
861 pos=wxDefaultPosition, size=wxDefaultSize,
862 style=wxTAB_TRAVERSAL, name="panel"):
863 wxPanel.__init__(self, parent, id, pos, size, style, name)
864 self.child = None
865 EVT_SIZE(self, self.OnSize)
866 def OnSize(self, evt):
867 if self.child is None:
868 children = self.GetChildren()
869 if len(children):
870 self.child = children[0]
871 if self.child:
872 self.child.SetPosition((0,0))
873 self.child.SetSize(self.GetSize())
874
875
c856d372 876#----------------------------------------------------------------------
7bf85405
RD
877#----------------------------------------------------------------------
878
2f90df85
RD
879class wxPyOnDemandOutputWindow:
880 def __init__(self, title = "wxPython: stdout/stderr"):
881 self.frame = None
882 self.title = title
c856d372 883 self.parent = None
2f90df85
RD
884
885 def SetParent(self, parent):
886 self.parent = parent
cf694132 887
2f90df85
RD
888 def OnCloseWindow(self, event):
889 if self.frame != None:
890 self.frame.Destroy()
891 self.frame = None
892 self.text = None
7bf85405 893
6e18ca6c 894 # These methods provide the file-like output behaviour.
2f90df85 895 def write(self, str):
6e18ca6c
RD
896 if not wxThread_IsMain():
897 # Aquire the GUI mutex before making GUI calls. Mutex is released
03a2c062 898 # when locker is deleted at the end of this function.
6e18ca6c
RD
899 locker = wxMutexGuiLocker()
900
2f90df85 901 if not self.frame:
03a2c062
RD
902 self.frame = wxFrame(self.parent, -1, self.title,
903 style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
2f90df85
RD
904 self.text = wxTextCtrl(self.frame, -1, "",
905 style = wxTE_MULTILINE|wxTE_READONLY)
906 self.frame.SetSize(wxSize(450, 300))
1e4a197e 907 self.frame.Show(True)
2f90df85
RD
908 EVT_CLOSE(self.frame, self.OnCloseWindow)
909 self.text.AppendText(str)
910
911 def close(self):
a1df7a95 912 if self.frame != None:
6e18ca6c
RD
913 if not wxThread_IsMain():
914 locker = wxMutexGuiLocker()
c856d372 915 self.frame.Close()
7bf85405 916
7bf85405 917
606d919c 918_defRedirect = (wxPlatform == '__WXMSW__' or wxPlatform == '__WXMAC__')
7bf85405
RD
919
920#----------------------------------------------------------------------
921# The main application class. Derive from this and implement an OnInit
922# method that creates a frame and then calls self.SetTopWindow(frame)
923
924class wxApp(wxPyApp):
925 error = 'wxApp.error'
2f90df85 926 outputWindowClass = wxPyOnDemandOutputWindow
7bf85405 927
1e4a197e 928 def __init__(self, redirect=_defRedirect, filename=None, useBestVisual=False):
7bf85405 929 wxPyApp.__init__(self)
1fded56b
RD
930
931 if wx.wxPlatform == "__WXMAC__":
932 try:
933 import MacOS
934 if not MacOS.WMAvailable():
935 print """This program needs access to the screen. Please run with
936'pythonw', not 'python', and only when you are logged in on the main display
937of your Mac."""
938 sys.exit(1)
939 except:
940 pass
941
7bf85405
RD
942 self.stdioWin = None
943 self.saveStdio = (sys.stdout, sys.stderr)
1e4a197e
RD
944
945 # This has to be done before OnInit
946 self.SetUseBestVisual(useBestVisual)
947
7bf85405
RD
948 if redirect:
949 self.RedirectStdio(filename)
1e4a197e 950
dd116e73
RD
951 # Set the default handler for SIGINT. This fixes a problem
952 # where if Ctrl-C is pressed in the console that started this
953 # app then it will not appear to do anything, (not even send
954 # KeyboardInterrupt???) but will later segfault on exit. By
955 # setting the default handler then the app will exit, as
956 # expected (depending on platform.)
957 import signal
958 signal.signal(signal.SIGINT, signal.SIG_DFL)
959
7bf85405
RD
960 # this initializes wxWindows and then calls our OnInit
961 _wxStart(self.OnInit)
962
963
964 def __del__(self):
965 try:
966 self.RestoreStdio()
967 except:
968 pass
969
2f90df85
RD
970
971 def SetTopWindow(self, frame):
972 if self.stdioWin:
973 self.stdioWin.SetParent(frame)
2f90df85
RD
974 wxPyApp.SetTopWindow(self, frame)
975
a1df7a95 976
2f90df85
RD
977 def MainLoop(self):
978 wxPyApp.MainLoop(self)
979 self.RestoreStdio()
980
a1df7a95 981
7bf85405
RD
982 def RedirectStdio(self, filename):
983 if filename:
984 sys.stdout = sys.stderr = open(filename, 'a')
985 else:
1e4a197e 986 self.stdioWin = self.outputWindowClass()
c856d372 987 sys.stdout = sys.stderr = self.stdioWin
7bf85405 988
a1df7a95 989
7bf85405
RD
990 def RestoreStdio(self):
991 sys.stdout, sys.stderr = self.saveStdio
c856d372 992
7bf85405 993
1e4a197e
RD
994# change from wxPyApp_ to wxApp_
995wxApp_GetMacDefaultEncodingIsPC = wxc.wxPyApp_GetMacDefaultEncodingIsPC
996wxApp_GetMacSupportPCMenuShortcuts = wxc.wxPyApp_GetMacSupportPCMenuShortcuts
997wxApp_GetMacAboutMenuItemId = wxc.wxPyApp_GetMacAboutMenuItemId
998wxApp_GetMacPreferencesMenuItemId = wxc.wxPyApp_GetMacPreferencesMenuItemId
999wxApp_GetMacExitMenuItemId = wxc.wxPyApp_GetMacExitMenuItemId
1000wxApp_GetMacHelpMenuTitleName = wxc.wxPyApp_GetMacHelpMenuTitleName
1001wxApp_SetMacDefaultEncodingIsPC = wxc.wxPyApp_SetMacDefaultEncodingIsPC
1002wxApp_SetMacSupportPCMenuShortcuts = wxc.wxPyApp_SetMacSupportPCMenuShortcuts
1003wxApp_SetMacAboutMenuItemId = wxc.wxPyApp_SetMacAboutMenuItemId
1004wxApp_SetMacPreferencesMenuItemId = wxc.wxPyApp_SetMacPreferencesMenuItemId
1005wxApp_SetMacExitMenuItemId = wxc.wxPyApp_SetMacExitMenuItemId
1006wxApp_SetMacHelpMenuTitleName = wxc.wxPyApp_SetMacHelpMenuTitleName
1007
1008
6999b0d8
RD
1009#----------------------------------------------------------------------------
1010
1011class wxPySimpleApp(wxApp):
83b18bab
RD
1012 def __init__(self, flag=0):
1013 wxApp.__init__(self, flag)
6999b0d8 1014 def OnInit(self):
3fce70fb 1015 wxInitAllImageHandlers()
1e4a197e 1016 return True
7bf85405 1017
2f90df85 1018
f6bcfd97
BP
1019class wxPyWidgetTester(wxApp):
1020 def __init__(self, size = (250, 100)):
1021 self.size = size
1022 wxApp.__init__(self, 0)
1023
1024 def OnInit(self):
1025 self.frame = wxFrame(None, -1, "Widget Tester", pos=(0,0), size=self.size)
1026 self.SetTopWindow(self.frame)
1e4a197e 1027 return True
f6bcfd97
BP
1028
1029 def SetWidget(self, widgetClass, *args):
1fded56b 1030 w = widgetClass(self.frame, *args)
1e4a197e 1031 self.frame.Show(True)
f6bcfd97 1032
7bf85405 1033#----------------------------------------------------------------------------
4acff284
RD
1034# DO NOT hold any other references to this object. This is how we
1035# know when to cleanup system resources that wxWin is holding. When
1036# the sys module is unloaded, the refcount on sys.__wxPythonCleanup
1037# goes to zero and it calls the wxApp_CleanUp function.
b1462dfa 1038
c0fbf24b
RD
1039class __wxPyCleanup:
1040 def __init__(self):
1041 self.cleanup = wxc.wxApp_CleanUp
1042 def __del__(self):
1043 self.cleanup()
1044
1045sys.__wxPythonCleanup = __wxPyCleanup()
1046
ef2060fa 1047## # another possible solution, but it gets called too early...
c0fbf24b
RD
1048## if sys.version[0] == '2':
1049## import atexit
1050## atexit.register(wxc.wxApp_CleanUp)
1051## else:
1052## sys.exitfunc = wxc.wxApp_CleanUp
b1462dfa 1053
9416aa89
RD
1054
1055#----------------------------------------------------------------------------
8bf5d46e 1056#----------------------------------------------------------------------------