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