]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/helpers.cpp
- Moved the header in the .i files out of the code that gets put into
[wxWidgets.git] / utils / wxPython / src / helpers.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: helpers.cpp
3 // Purpose: Helper functions/classes for the wxPython extension module
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 7/1/97
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 #undef DEBUG
14 #include <Python.h>
15 #include "helpers.h"
16
17 #ifdef __WXGTK__
18 #ifdef USE_GDK_IMLIB
19 #include "gdk_imlib/gdk_imlib.h"
20 #endif
21 #endif
22
23 //---------------------------------------------------------------------------
24
25 //wxHashTable* wxPyWindows = NULL;
26
27
28 wxPoint wxPyDefaultPosition; //wxDefaultPosition);
29 wxSize wxPyDefaultSize; //wxDefaultSize);
30 wxString wxPyEmptyStr("");
31
32
33
34 //----------------------------------------------------------------------
35 // Class for implementing the wxp main application shell.
36 //----------------------------------------------------------------------
37
38 wxPyApp *wxPythonApp = NULL; // Global instance of application object
39
40
41 // This one isn't acutally called... See __wxStart()
42 bool wxPyApp::OnInit(void) {
43 return false;
44 }
45
46 int wxPyApp::MainLoop(void) {
47 int retval = wxApp::MainLoop();
48 AfterMainLoop();
49 return retval;
50 }
51
52 void wxPyApp::AfterMainLoop(void) {
53 // more stuff from wxEntry...
54 if (wxPythonApp->GetTopWindow()) {
55 // Forcibly delete the window.
56 if (wxPythonApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame)) ||
57 wxPythonApp->GetTopWindow()->IsKindOf(CLASSINFO(wxDialog))) {
58
59 wxPythonApp->GetTopWindow()->Close(TRUE);
60 wxPythonApp->DeletePendingObjects();
61 }
62 else {
63 delete wxPythonApp->GetTopWindow();
64 wxPythonApp->SetTopWindow(NULL);
65 }
66 }
67
68 wxPythonApp->OnExit();
69 #ifdef __WXMSW__
70 wxApp::CleanUp();
71 #endif
72 #ifdef __WXGTK__
73 wxApp::CommonCleanUp();
74 #endif
75 delete wxPythonApp;
76 }
77
78
79 //----------------------------------------------------------------------
80 // a few native methods to add to the module
81 //----------------------------------------------------------------------
82
83
84 // Start the user application, user App's OnInit method is a parameter here
85 PyObject* __wxStart(PyObject* /* self */, PyObject* args)
86 {
87 PyObject* onInitFunc = NULL;
88 PyObject* arglist;
89 PyObject* result;
90 long bResult;
91
92 if (!PyArg_ParseTuple(args, "O", &onInitFunc))
93 return NULL;
94
95 // This is where we pick up one part of the wxEntry functionality...
96 // the rest is in AfterMainLoop.
97 #ifdef __WXMSW__
98 wxPythonApp->argc = 0;
99 wxPythonApp->argv = NULL;
100 wxPythonApp->OnInitGui();
101 #endif
102 #ifdef __WXGTK__
103 wxTheApp->argc = 0;
104 wxTheApp->argv = NULL;
105
106 gtk_init( &wxTheApp->argc, &wxTheApp->argv );
107
108 #ifdef USE_GDK_IMLIB
109
110 gdk_imlib_init();
111
112 gtk_widget_push_visual(gdk_imlib_get_visual());
113
114 gtk_widget_push_colormap(gdk_imlib_get_colormap());
115
116 #endif
117
118 wxApp::CommonInit();
119
120 wxTheApp->OnInitGui();
121
122 #endif
123
124
125 // Call the Python App's OnInit function
126 arglist = PyTuple_New(0);
127 result = PyEval_CallObject(onInitFunc, arglist);
128 if (!result) {
129 PyErr_Print();
130 exit(1);
131 }
132
133 if (! PyInt_Check(result)) {
134 PyErr_SetString(PyExc_TypeError, "OnInit should return a boolean value");
135 return NULL;
136 }
137 bResult = PyInt_AS_LONG(result);
138 if (! bResult) {
139 wxPythonApp->DeletePendingObjects();
140 wxPythonApp->OnExit();
141 #ifdef __WXMSW__
142 wxApp::CleanUp();
143 #endif
144 #ifdef __WXGTK__
145 wxApp::CommonCleanUp();
146 #endif
147 PyErr_SetString(PyExc_SystemExit, "OnInit returned false, exiting...");
148 return NULL;
149 }
150
151 Py_INCREF(Py_None);
152 return Py_None;
153 }
154
155
156 //PyObject* __wxMainLoop(PyObject* /* self */, PyObject* /* args */)
157 //{
158 // wxPythonApp->MainLoop();
159 // if (wxPythonApp->wx_frame) {
160 // wxPythonApp->wx_frame->GetEventHandler()->OnClose();
161 // delete wxPythonApp->wx_frame;
162 // }
163 // wxCleanUp();
164
165 // Py_INCREF(Py_None);
166 // return Py_None;
167 //}
168
169
170 //PyObject* __wxExitMainLoop(PyObject* /* self */, PyObject* /* args */)
171 //{
172 // wxPythonApp->ExitMainLoop();
173 // Py_INCREF(Py_None);
174 // return Py_None;
175 //}
176
177
178
179 //PyObject* __wxAddCallback(PyObject* /* self */, PyObject* args)
180 //{
181 // char* swigPtr;
182 // char* name;
183 // PyObject* callback;
184 // wxWindow* win;
185 // wxPyEvtHandlers* evtHdlr;
186
187 // if (!PyArg_ParseTuple(args, "ssO", &swigPtr, &name, &callback))
188 // return NULL;
189
190 // if (!PyCallable_Check(callback)) {
191 // PyErr_SetString(PyExc_TypeError, "Expected a callable object.");
192 // return NULL;
193 // }
194
195 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
196 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
197 // return NULL;
198 // }
199
200 // evtHdlr = (wxPyEvtHandlers*)win->GetClientData();
201 // if (! evtHdlr->addCallback(name, callback)) {
202 // PyErr_SetString(PyExc_TypeError, "Unknown callback name.");
203 // return NULL;
204 // }
205
206 // Py_INCREF(Py_None);
207 // return Py_None;
208 //}
209
210
211
212 //PyObject* __wxSetWinEvtHdlr(PyObject* /* self */, PyObject* args)
213 //{
214 // char* swigPtr;
215 // wxWindow* win;
216 // wxPyEvtHandlers* evtHdlr;
217
218 // if (!PyArg_ParseTuple(args, "s", &swigPtr))
219 // return NULL;
220
221 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
222 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
223 // return NULL;
224 // }
225
226 // evtHdlr = new wxPyEvtHandlers;
227 // win->SetClientData((char*)evtHdlr);
228
229 // Py_INCREF(Py_None);
230 // return Py_None;
231 //}
232
233
234
235 //PyObject* __wxDelWinEvtHdlr(PyObject* /* self */, PyObject* args)
236 //{
237 // char* swigPtr;
238 // wxWindow* win;
239 // wxPyEvtHandlers* evtHdlr;
240
241 // if (!PyArg_ParseTuple(args, "s", &swigPtr))
242 // return NULL;
243
244 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
245 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
246 // return NULL;
247 // }
248
249 // evtHdlr = (wxPyEvtHandlers*)win->GetClientData();
250 // printf("__wxDelWinEvtHdlr: %p\n", evtHdlr);
251 // delete evtHdlr;
252
253 // Py_INCREF(Py_None);
254 // return Py_None;
255 //}
256
257
258
259 PyObject* wxPython_dict;
260 PyObject* __wxSetDictionary(PyObject* /* self */, PyObject* args)
261 {
262
263 if (!PyArg_ParseTuple(args, "O", &wxPython_dict))
264 return NULL;
265
266 if (!PyDict_Check(wxPython_dict)) {
267 PyErr_SetString(PyExc_TypeError, "_wxSetDictionary must have dictionary object!");
268 return NULL;
269 }
270 #ifdef __WXMOTIF__
271 #define wxPlatform "__MOTIF__"
272 #endif
273 #ifdef __WXGTK__
274 #define wxPlatform "__GTK__"
275 #endif
276 #if defined(__WIN32__) || defined(__WXMSW__)
277 #define wxPlatform "__WIN32__"
278 #endif
279 #ifdef __WXMAC__
280 #define wxPlatform "__MAC__"
281 #endif
282
283 PyDict_SetItemString(wxPython_dict, "wxPlatform", PyString_FromString(wxPlatform));
284
285 Py_INCREF(Py_None);
286 return Py_None;
287 }
288
289
290 //---------------------------------------------------------------------------
291
292
293 static
294 PyObject* wxPyConstructObject(void* ptr, char* className)
295 {
296 char buff[64]; // should be big enough...
297 char swigptr[64];
298
299 sprintf(buff, "_%s_p", className);
300 SWIG_MakePtr(swigptr, ptr, buff);
301
302 sprintf(buff, "%sPtr", className);
303 PyObject* classobj = PyDict_GetItemString(wxPython_dict, buff);
304 if (! classobj) {
305 Py_INCREF(Py_None);
306 return Py_None;
307 }
308
309 PyObject* arg = Py_BuildValue("(s)", swigptr);
310 PyObject* obj = PyInstance_New(classobj, arg, NULL);
311 Py_DECREF(arg);
312
313 return obj;
314 }
315
316
317 // This function is used for all events destined for Python event handlers.
318 void wxPyCallback::EventThunker(wxEvent& event) {
319 wxPyCallback* cb = (wxPyCallback*)event.m_callbackUserData;
320 PyObject* func = cb->m_func;
321 PyObject* result;
322 PyObject* arg;
323 PyObject* tuple;
324
325 arg = wxPyConstructObject((void*)&event, event.GetClassInfo()->GetClassName());
326
327 tuple = PyTuple_New(1);
328 PyTuple_SET_ITEM(tuple, 0, arg);
329 result = PyEval_CallObject(func, tuple);
330 Py_DECREF(arg);
331 Py_DECREF(tuple);
332 if (result) {
333 Py_DECREF(result);
334 PyErr_Clear();
335 } else {
336 PyErr_Print();
337 }
338 }
339
340
341 //---------------------------------------------------------------------------
342
343 #ifdef __WXMSW__
344 wxPyMenu::wxPyMenu(const wxString& title, PyObject* _func)
345 : wxMenu(title, (wxFunction)(func ? MenuCallback : NULL)), func(0) {
346
347 if (_func) {
348 func = _func;
349 Py_INCREF(func);
350 }
351 }
352
353 wxPyMenu::~wxPyMenu() {
354 if (func)
355 Py_DECREF(func);
356 }
357
358
359 void wxPyMenu::MenuCallback(wxMenu& menu, wxCommandEvent& evt) {
360 PyObject* evtobj = wxPyConstructObject((void*)&evt, "wxCommandEvent");
361 PyObject* menuobj = wxPyConstructObject((void*)&menu, "wxMenu");
362 if (PyErr_Occurred()) {
363 // bail out if a problem
364 PyErr_Print();
365 return;
366 }
367 // Now call the callback...
368 PyObject* func = ((wxPyMenu*)&menu)->func;
369 PyObject* args = Py_BuildValue("(OO)", menuobj, evtobj);
370 PyObject* res = PyEval_CallObject(func, args);
371 Py_DECREF(args);
372 Py_DECREF(res);
373 Py_DECREF(evtobj);
374 Py_DECREF(menuobj);
375 }
376 #endif
377
378 //---------------------------------------------------------------------------
379
380 wxPyTimer::wxPyTimer(PyObject* callback) {
381 func = callback;
382 Py_INCREF(func);
383 }
384
385 wxPyTimer::~wxPyTimer() {
386 Py_DECREF(func);
387 }
388
389 void wxPyTimer::Notify() {
390 PyObject* result;
391 PyObject* args = Py_BuildValue("()");
392
393 result = PyEval_CallObject(func, args);
394 Py_DECREF(args);
395 if (result) {
396 Py_DECREF(result);
397 PyErr_Clear();
398 } else {
399 PyErr_Print();
400 }
401 }
402
403
404
405 //----------------------------------------------------------------------
406 // wxPyEvtHandlers class
407 //----------------------------------------------------------------------
408
409 //wxPyEvtHandlers::wxPyEvtHandlers()
410 // : pyOnActivate(0),
411 // pyOnChar(0),
412 // pyOnCharHook(0),
413 // pyOnClose(0),
414 // pyOnCommand(0),
415 // pyOnDropFiles(0),
416 // pyOnDefaultAction(0),
417 // pyOnEvent(0),
418 // pyOnInitMenuPopup(0),
419 // pyOnKillFocus(0),
420 // pyOnMenuCommand(0),
421 // pyOnMenuSelect(0),
422 // pyOnMove(0),
423 // pyOnPaint(0),
424 // pyOnScroll(0),
425 // pyOnSetFocus(0),
426 // pyOnSize(0),
427 // pyOnSysColourChange(0),
428 // pyOnLeftClick(0),
429 // pyOnMouseEnter(0),
430 // pyOnRightClick(0),
431 // pyOnDoubleClickSash(0),
432 // pyOnUnsplit(0)
433 //{
434 //}
435
436
437 //wxPyEvtHandlers::~wxPyEvtHandlers()
438 //{
439 // Py_XDECREF(pyOnActivate);
440 // Py_XDECREF(pyOnChar);
441 // Py_XDECREF(pyOnCharHook);
442 // Py_XDECREF(pyOnClose);
443 // Py_XDECREF(pyOnCommand);
444 // Py_XDECREF(pyOnDropFiles);
445 // Py_XDECREF(pyOnDefaultAction);
446 // Py_XDECREF(pyOnEvent);
447 // Py_XDECREF(pyOnInitMenuPopup);
448 // Py_XDECREF(pyOnKillFocus);
449 // Py_XDECREF(pyOnMenuCommand);
450 // Py_XDECREF(pyOnMenuSelect);
451 // Py_XDECREF(pyOnMove);
452 // Py_XDECREF(pyOnPaint);
453 // Py_XDECREF(pyOnScroll);
454 // Py_XDECREF(pyOnSetFocus);
455 // Py_XDECREF(pyOnSize);
456 // Py_XDECREF(pyOnSysColourChange);
457 // Py_XDECREF(pyOnLeftClick);
458 // Py_XDECREF(pyOnMouseEnter);
459 // Py_XDECREF(pyOnRightClick);
460 // Py_XDECREF(pyOnDoubleClickSash);
461 // Py_XDECREF(pyOnUnsplit);
462
463 // wxNode* node = cleanupList.First();
464 // while (node) {
465 // delete (wxPyEvtHandlers*)node->Data();
466 // delete node;
467 // node = cleanupList.First();
468 // }
469
470 // node = decrefList.First();
471 // while (node) {
472 // PyObject* obj = (PyObject*)node->Data();
473 // Py_DECREF(obj);
474 // delete node;
475 // node = decrefList.First();
476 // }
477 //// printf("~wxPyEvtHandlers: %p\n", this);
478 //}
479
480 ////----------------------------------------------------------------------
481
482 //Bool wxPyEvtHandlers::addCallback(char* name, PyObject* callback)
483 //{
484 // Py_INCREF(callback);
485
486 // if (strcmp(name, "OnActivate") == 0) {
487 // pyOnActivate = callback;
488 // return TRUE;
489 // }
490 // if (strcmp(name, "OnChar") == 0) {
491 // pyOnChar = callback;
492 // return TRUE;
493 // }
494 // if (strcmp(name, "OnCharHook") == 0) {
495 // pyOnCharHook = callback;
496 // return TRUE;
497 // }
498 // if (strcmp(name, "OnClose") == 0) {
499 // pyOnClose = callback;
500 // return TRUE;
501 // }
502 // if (strcmp(name, "OnCommand") == 0) {
503 // pyOnCommand = callback;
504 // return TRUE;
505 // }
506 // if (strcmp(name, "OnDropFiles") == 0) {
507 // pyOnDropFiles = callback;
508 // return TRUE;
509 // }
510 // if (strcmp(name, "OnDefaultAction") == 0) {
511 // pyOnDefaultAction = callback;
512 // return TRUE;
513 // }
514 // if (strcmp(name, "OnEvent") == 0) {
515 // pyOnEvent = callback;
516 // return TRUE;
517 // }
518 // if (strcmp(name, "OnInitMenuPopup") == 0) {
519 // pyOnInitMenuPopup = callback;
520 // return TRUE;
521 // }
522 // if (strcmp(name, "OnKillFocus") == 0) {
523 // pyOnKillFocus = callback;
524 // return TRUE;
525 // }
526 // if (strcmp(name, "OnMenuCommand") == 0) {
527 // pyOnMenuCommand = callback;
528 // return TRUE;
529 // }
530 // if (strcmp(name, "OnMenuSelect") == 0) {
531 // pyOnMenuSelect = callback;
532 // return TRUE;
533 // }
534 // if (strcmp(name, "OnMove") == 0) {
535 // pyOnMove = callback;
536 // return TRUE;
537 // }
538 // if (strcmp(name, "OnPaint") == 0) {
539 // pyOnPaint = callback;
540 // return TRUE;
541 // }
542 // if (strcmp(name, "OnScroll") == 0) {
543 // pyOnScroll = callback;
544 // return TRUE;
545 // }
546 // if (strcmp(name, "OnSetFocus") == 0) {
547 // pyOnSetFocus = callback;
548 // return TRUE;
549 // }
550 // if (strcmp(name, "OnSize") == 0) {
551 // pyOnSize = callback;
552 // return TRUE;
553 // }
554 // if (strcmp(name, "OnSysColourChange") == 0) {
555 // pyOnSysColourChange = callback;
556 // return TRUE;
557 // }
558 // if (strcmp(name, "OnLeftClick") == 0) {
559 // pyOnLeftClick = callback;
560 // return TRUE;
561 // }
562 // if (strcmp(name, "OnMouseEnter") == 0) {
563 // pyOnMouseEnter = callback;
564 // return TRUE;
565 // }
566 // if (strcmp(name, "OnRightClick") == 0) {
567 // pyOnRightClick = callback;
568 // return TRUE;
569 // }
570 // if (strcmp(name, "OnDoubleClickSash") == 0) {
571 // pyOnDoubleClickSash = callback;
572 // return TRUE;
573 // }
574 // if (strcmp(name, "OnUnsplit") == 0) {
575 // pyOnUnsplit = callback;
576 // return TRUE;
577 // }
578
579 // // If we get here, there was no match.
580 // Py_DECREF(callback);
581 // return FALSE;
582 //}
583
584
585 ////----------------------------------------------------------------------
586 //// Helpers to assist in calling the python callable objects
587 ////----------------------------------------------------------------------
588
589 //PyObject* wxPyEvtHandlers::constructObject(void* ptr, char* className)
590 //{
591 // char buff[64]; // should be big enough...
592 // char swigptr[64];
593
594 // sprintf(buff, "_%s_p", className);
595 // SWIG_MakePtr(swigptr, ptr, buff);
596
597 // sprintf(buff, "%sPtr", className);
598 // PyObject* classobj = PyDict_GetItemString(wxPython_dict, buff);
599 // PyObject* arg = Py_BuildValue("(s)", swigptr);
600 // PyObject* obj = PyInstance_New(classobj, arg, NULL);
601 // Py_DECREF(arg);
602
603 // return obj;
604 //}
605
606
607
608 //int wxPyEvtHandlers::callFunc(PyObject* func, PyObject* arglist)
609 //{
610 // PyObject* result;
611 // int retval = FALSE;
612
613 // result = PyEval_CallObject(func, arglist);
614 // Py_DECREF(arglist);
615 // if (result) { // Assumes an integer return type...
616 // retval = PyInt_AsLong(result);
617 // Py_DECREF(result);
618 // PyErr_Clear(); // forget about it if it's not...
619 // } else {
620 // PyErr_Print();
621 // }
622 // return retval;
623 //}
624
625 ////---------------------------------------------------------------------------
626 //// Methods and helpers of the wxPy* classes
627 ////---------------------------------------------------------------------------
628
629 //IMP_OnActivate(wxFrame, wxPyFrame);
630 //IMP_OnCharHook(wxFrame, wxPyFrame);
631 //IMP_OnClose(wxFrame, wxPyFrame);
632 //IMP_OnMenuCommand(wxFrame, wxPyFrame);
633 //IMP_OnMenuSelect(wxFrame, wxPyFrame);
634 //IMP_OnSize(wxFrame, wxPyFrame);
635 //IMP_OnDropFiles(wxFrame, wxPyFrame);
636
637 //IMP_OnChar(wxCanvas, wxPyCanvas);
638 //IMP_OnEvent(wxCanvas, wxPyCanvas);
639 //IMP_OnPaint(wxCanvas, wxPyCanvas);
640 //IMP_OnScroll(wxCanvas, wxPyCanvas);
641 //IMP_OnDropFiles(wxCanvas, wxPyCanvas);
642
643 //IMP_OnChar(wxPanel, wxPyPanel);
644 //IMP_OnEvent(wxPanel, wxPyPanel);
645 //IMP_OnPaint(wxPanel, wxPyPanel);
646 //IMP_OnScroll(wxPanel, wxPyPanel);
647 //IMP_OnCommand(wxPanel, wxPyPanel);
648 //IMP_OnDefaultAction(wxPanel, wxPyPanel);
649 //IMP_OnDropFiles(wxPanel, wxPyPanel);
650
651 //IMP_OnChar(wxTextWindow, wxPyTextWindow);
652 //IMP_OnDropFiles(wxTextWindow, wxPyTextWindow);
653
654 //IMP_OnCharHook(wxDialogBox, wxPyDialogBox);
655 //IMP_OnClose(wxDialogBox, wxPyDialogBox);
656 //IMP_OnSize(wxDialogBox, wxPyDialogBox);
657 //IMP_OnDropFiles(wxDialogBox, wxPyDialogBox);
658 //IMP_OnChar(wxDialogBox, wxPyDialogBox);
659 //IMP_OnEvent(wxDialogBox, wxPyDialogBox);
660 //IMP_OnPaint(wxDialogBox, wxPyDialogBox);
661 //IMP_OnScroll(wxDialogBox, wxPyDialogBox);
662 //IMP_OnCommand(wxDialogBox, wxPyDialogBox);
663 //IMP_OnDefaultAction(wxDialogBox, wxPyDialogBox);
664
665 //IMP_OnChar(wxToolBar, wxPyToolBar);
666 //IMP_OnEvent(wxToolBar, wxPyToolBar);
667 //IMP_OnPaint(wxToolBar, wxPyToolBar);
668 //IMP_OnScroll(wxToolBar, wxPyToolBar);
669 //IMP_OnCommand(wxToolBar, wxPyToolBar);
670 //IMP_OnDefaultAction(wxToolBar, wxPyToolBar);
671 //IMP_OnDropFiles(wxToolBar, wxPyToolBar);
672 //IMP_OnMouseEnter(wxToolBar, wxPyToolBar);
673 //IMP_OnRightClick(wxToolBar, wxPyToolBar);
674
675 //IMP_OnChar(wxButtonBar, wxPyButtonBar);
676 //IMP_OnEvent(wxButtonBar, wxPyButtonBar);
677 //IMP_OnPaint(wxButtonBar, wxPyButtonBar);
678 //IMP_OnScroll(wxButtonBar, wxPyButtonBar);
679 //IMP_OnCommand(wxButtonBar, wxPyButtonBar);
680 //IMP_OnDefaultAction(wxButtonBar, wxPyButtonBar);
681 //IMP_OnDropFiles(wxButtonBar, wxPyButtonBar);
682 //IMP_OnMouseEnter(wxButtonBar, wxPyButtonBar);
683 //IMP_OnRightClick(wxButtonBar, wxPyButtonBar);
684
685 //IMP_OnDoubleClickSash(wxSplitterWindow, wxPySplitterWindow);
686 //IMP_OnUnsplit(wxSplitterWindow, wxPySplitterWindow);
687
688
689
690 //Bool wxPyToolBar::OnLeftClick(int a, int b) {
691 // wxPyEvtHandlers* peh=(wxPyEvtHandlers*)GetClientData();
692 // if (peh->pyOnLeftClick)
693 // return peh->callFunc(peh->pyOnLeftClick, Py_BuildValue("(ii)",a,b));
694 // else {
695 // // If there is no Python callback, redirect the request to
696 // // the OnMenuCommand of the parent frame.
697 // wxFrame* frame = (wxFrame*)GetParent();
698 // frame->OnMenuCommand(a);
699 // return TRUE;
700 // }
701 //// else
702 //// return wxToolBar::OnLeftClick(a,b);
703 //}
704 //Bool wxPyToolBar::baseclass_OnLeftClick(int a, int b) {
705 // return wxToolBar::OnLeftClick(a,b);
706 //}
707
708
709 //Bool wxPyButtonBar::OnLeftClick(int a, int b) {
710 // wxPyEvtHandlers* peh=(wxPyEvtHandlers*)GetClientData();
711 // if (peh->pyOnLeftClick)
712 // return peh->callFunc(peh->pyOnLeftClick, Py_BuildValue("(ii)",a,b));
713 // else {
714 // // If there is no Python callback, redirect the request to
715 // // the OnMenuCommand of the parent frame.
716 // wxFrame* frame = (wxFrame*)GetParent();
717 // frame->OnMenuCommand(a);
718 // return TRUE;
719 // }
720 //}
721 //Bool wxPyButtonBar::baseclass_OnLeftClick(int a, int b) {
722 // return wxButtonBar::OnLeftClick(a,b);
723 //}
724
725
726
727 //wxPyMenu::wxPyMenu(PyObject* _func)
728 // : wxMenu(NULL, (wxFunction)(func ? MenuCallback : NULL)), func(0) {
729
730 // if (_func) {
731 // func = _func;
732 // Py_INCREF(func);
733 // }
734 //}
735
736 //wxPyMenu::~wxPyMenu() {
737 // if (func)
738 // Py_DECREF(func);
739 //}
740
741
742 //void wxPyMenu::MenuCallback(wxWindow& win, wxCommandEvent& evt) {
743 // wxPyEvtHandlers* peh= new wxPyEvtHandlers; // Used for the helper methods
744 // PyObject* evtobj = peh->constructObject((void*)&evt, "wxCommandEvent");
745 // PyObject* winobj = peh->constructObject((void*)&win, "wxWindow");
746 // if (PyErr_Occurred()) {
747 // // bail out if a problem
748 // PyErr_Print();
749 // delete peh;
750 // return;
751 // }
752 // // Now call the callback...
753 // PyObject* func = ((wxPyMenu*)&win)->func;
754 // peh->callFunc(func, Py_BuildValue("(OO)", winobj, evtobj));
755 // Py_DECREF(evtobj);
756 // Py_DECREF(winobj);
757 // delete peh;
758 //}
759
760
761
762 //wxPyTimer::wxPyTimer(PyObject* callback) {
763 // func = callback;
764 // Py_INCREF(func);
765 //}
766
767 //wxPyTimer::~wxPyTimer() {
768 // Py_DECREF(func);
769 //}
770
771 //void wxPyTimer::Notify() {
772 // wxPyEvtHandlers* peh= new wxPyEvtHandlers; // just for the helper methods
773 // peh->callFunc(func, Py_BuildValue("()"));
774 // delete peh;
775 //}
776
777 //----------------------------------------------------------------------
778 //----------------------------------------------------------------------
779 // Some helper functions for typemaps in my_typemaps.i, so they won't be
780 // imcluded in every file...
781
782
783 int* int_LIST_helper(PyObject* source) {
784 if (!PyList_Check(source)) {
785 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
786 return NULL;
787 }
788 int count = PyList_Size(source);
789 int* temp = new int[count];
790 if (! temp) {
791 PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array");
792 return NULL;
793 }
794 for (int x=0; x<count; x++) {
795 PyObject* o = PyList_GetItem(source, x);
796 if (! PyInt_Check(o)) {
797 PyErr_SetString(PyExc_TypeError, "Expected a list of integers.");
798 return NULL;
799 }
800 temp[x] = PyInt_AsLong(o);
801 }
802 return temp;
803 }
804
805
806 long* long_LIST_helper(PyObject* source) {
807 if (!PyList_Check(source)) {
808 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
809 return NULL;
810 }
811 int count = PyList_Size(source);
812 long* temp = new long[count];
813 if (! temp) {
814 PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array");
815 return NULL;
816 }
817 for (int x=0; x<count; x++) {
818 PyObject* o = PyList_GetItem(source, x);
819 if (! PyInt_Check(o)) {
820 PyErr_SetString(PyExc_TypeError, "Expected a list of integers.");
821 return NULL;
822 }
823 temp[x] = PyInt_AsLong(o);
824 }
825 return temp;
826 }
827
828
829 char** string_LIST_helper(PyObject* source) {
830 if (!PyList_Check(source)) {
831 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
832 return NULL;
833 }
834 int count = PyList_Size(source);
835 char** temp = new char*[count];
836 if (! temp) {
837 PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array");
838 return NULL;
839 }
840 for (int x=0; x<count; x++) {
841 PyObject* o = PyList_GetItem(source, x);
842 if (! PyString_Check(o)) {
843 PyErr_SetString(PyExc_TypeError, "Expected a list of strings.");
844 return NULL;
845 }
846 temp[x] = PyString_AsString(o);
847 }
848 return temp;
849 }
850
851
852
853 wxPoint* wxPoint_LIST_helper(PyObject* source) {
854 if (!PyList_Check(source)) {
855 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
856 return NULL;
857 }
858 int count = PyList_Size(source);
859 wxPoint* temp = new wxPoint[count];
860 if (! temp) {
861 PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array");
862 return NULL;
863 }
864 for (int x=0; x<count; x++) {
865 PyObject* o = PyList_GetItem(source, x);
866 if (PyString_Check(o)) {
867 char* st = PyString_AsString(o);
868 wxPoint* pt;
869 if (SWIG_GetPtr(st,(void **) &pt,"_wxPoint_p")) {
870 PyErr_SetString(PyExc_TypeError,"Expected _wxPoint_p.");
871 return NULL;
872 }
873 temp[x] = *pt;
874 }
875 else if (PyTuple_Check(o)) {
876 PyObject* o1 = PyTuple_GetItem(o, 0);
877 PyObject* o2 = PyTuple_GetItem(o, 1);
878
879 temp[x].x = PyInt_AsLong(o1);
880 temp[x].y = PyInt_AsLong(o2);
881 }
882 else {
883 PyErr_SetString(PyExc_TypeError, "Expected a list of 2-tuples or wxPoints.");
884 return NULL;
885 }
886 }
887 return temp;
888 }
889
890
891 wxBitmap** wxBitmap_LIST_helper(PyObject* source) {
892 if (!PyList_Check(source)) {
893 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
894 return NULL;
895 }
896 int count = PyList_Size(source);
897 wxBitmap** temp = new wxBitmap*[count];
898 if (! temp) {
899 PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array");
900 return NULL;
901 }
902 for (int x=0; x<count; x++) {
903 PyObject* o = PyList_GetItem(source, x);
904 if (PyString_Check(o)) {
905 char* st = PyString_AsString(o);
906 wxBitmap* pt;
907 if (SWIG_GetPtr(st,(void **) &pt,"_wxBitmap_p")) {
908 PyErr_SetString(PyExc_TypeError,"Expected _wxBitmap_p.");
909 return NULL;
910 }
911 temp[x] = pt;
912 }
913 else {
914 PyErr_SetString(PyExc_TypeError, "Expected a list of wxBitmaps.");
915 return NULL;
916 }
917 }
918 return temp;
919 }
920
921
922
923 wxString* wxString_LIST_helper(PyObject* source) {
924 if (!PyList_Check(source)) {
925 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
926 return NULL;
927 }
928 int count = PyList_Size(source);
929 wxString* temp = new wxString[count];
930 if (! temp) {
931 PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array");
932 return NULL;
933 }
934 for (int x=0; x<count; x++) {
935 PyObject* o = PyList_GetItem(source, x);
936 if (! PyString_Check(o)) {
937 PyErr_SetString(PyExc_TypeError, "Expected a list of strings.");
938 return NULL;
939 }
940 temp[x] = PyString_AsString(o);
941 }
942 return temp;
943 }
944
945
946 #ifdef __WXMSW__
947 wxAcceleratorEntry* wxAcceleratorEntry_LIST_helper(PyObject* source) {
948 if (!PyList_Check(source)) {
949 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
950 return NULL;
951 }
952 int count = PyList_Size(source);
953 wxAcceleratorEntry* temp = new wxAcceleratorEntry[count];
954 if (! temp) {
955 PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array");
956 return NULL;
957 }
958 for (int x=0; x<count; x++) {
959 PyObject* o = PyList_GetItem(source, x);
960 if (PyString_Check(o)) {
961 char* st = PyString_AsString(o);
962 wxAcceleratorEntry* ae;
963 if (SWIG_GetPtr(st,(void **) &ae,"_wxAcceleratorEntry_p")) {
964 PyErr_SetString(PyExc_TypeError,"Expected _wxAcceleratorEntry_p.");
965 return NULL;
966 }
967 temp[x] = *ae;
968 }
969 else if (PyTuple_Check(o)) {
970 PyObject* o1 = PyTuple_GetItem(o, 0);
971 PyObject* o2 = PyTuple_GetItem(o, 1);
972 PyObject* o3 = PyTuple_GetItem(o, 2);
973
974 temp[x].m_flags = PyInt_AsLong(o1);
975 temp[x].m_keyCode = PyInt_AsLong(o2);
976 temp[x].m_command = PyInt_AsLong(o3);
977 }
978 else {
979 PyErr_SetString(PyExc_TypeError, "Expected a list of 3-tuples or wxAcceleratorEntry objects.");
980 return NULL;
981 }
982 }
983 return temp;
984 }
985
986 #endif
987
988 //----------------------------------------------------------------------
989 // A WinMain for when wxWindows and Python are linked together in a single
990 // application, instead of as a dynamic module
991
992
993 //#if !defined(WIN_PYD) && defined(WIN32)
994
995 //extern "C" int Py_Main(int argc, char** argv);
996
997 //int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR m_lpCmdLine,
998 // int nCmdShow )
999 //{
1000
1001 // wxpCreateApp();
1002
1003 // // Initialize wxWindows, but don't start the main loop
1004 // wxEntry(hInstance, hPrevInstance, m_lpCmdLine, nCmdShow, FALSE);
1005
1006 // Py_Initialize();
1007 // PyObject *argvList = PyList_New(0);
1008
1009 // char* stderrfilename = "wxpstderr.log";
1010 // int pyargc = 1;
1011 // char* script = NULL;
1012 // int argc = wxPythonApp->argc;
1013 // char** argv = wxPythonApp->argv;
1014
1015 // for (int i = 1; i < argc; i++) {
1016 // if (strncmp(argv[i], "wxpstderr=", 10) == 0)
1017 // stderrfilename = argv[i]+10;
1018 // else {
1019 // PyList_Append(argvList, PyString_FromString(argv[i]));
1020 // if (!script)
1021 // script = argv[i];
1022 // pyargc++;
1023 // }
1024 // }
1025
1026 // PySys_SetObject("argv", argvList);
1027
1028 //#if 1
1029 // char buf[256];
1030 //// //PyRun_SimpleString("import sys; sys.stdout=open('wxpstdout.log','w')");
1031 // sprintf(buf, "import sys; sys.stdout=sys.stderr=open('%s','w')", stderrfilename);
1032 // PyRun_SimpleString(buf);
1033 //#endif
1034
1035 // initwxPythonc();
1036
1037 // if (script) {
1038 // FILE *fp = fopen(script, "r");
1039 // if (fp) {
1040 // PyRun_SimpleFile(fp, script);// This returns after wxpApp constructor
1041 // fclose(fp);
1042 // }
1043 // else {
1044 // char msg[256];
1045 // sprintf(msg, "Cannot open %s", script);
1046 // wxMessageBox(msg);
1047 // }
1048 // }
1049 // else
1050 // PyRun_SimpleString("import wxpide");
1051
1052 // return 0;
1053 //}
1054
1055
1056 //#endif
1057
1058 //----------------------------------------------------------------------
1059
1060 /////////////////////////////////////////////////////////////////////////////
1061 //
1062 // $Log$
1063 // Revision 1.3 1998/08/15 07:36:36 RD
1064 // - Moved the header in the .i files out of the code that gets put into
1065 // the .cpp files. It caused CVS conflicts because of the RCS ID being
1066 // different each time.
1067 //
1068 // - A few minor fixes.
1069 //
1070 // Revision 1.2 1998/08/14 23:36:36 RD
1071 // Beginings of wxGTK compatibility
1072 //
1073 // Revision 1.1 1998/08/09 08:25:51 RD
1074 // Initial version
1075 //
1076 //