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