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