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