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