1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Helper functions/classes for the wxPython extension module
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
19 #include "gdk_imlib/gdk_imlib.h"
23 //---------------------------------------------------------------------------
25 //wxHashTable* wxPyWindows = NULL;
28 wxPoint wxPyDefaultPosition
; //wxDefaultPosition);
29 wxSize wxPyDefaultSize
; //wxDefaultSize);
30 wxString
wxPyEmptyStr("");
34 //----------------------------------------------------------------------
35 // Class for implementing the wxp main application shell.
36 //----------------------------------------------------------------------
38 wxPyApp
*wxPythonApp
= NULL
; // Global instance of application object
41 // This one isn't acutally called... See __wxStart()
42 bool wxPyApp::OnInit(void) {
46 int wxPyApp::MainLoop(void) {
47 int retval
= wxApp::MainLoop();
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
))) {
59 wxPythonApp
->GetTopWindow()->Close(TRUE
);
60 wxPythonApp
->DeletePendingObjects();
63 delete wxPythonApp
->GetTopWindow();
64 wxPythonApp
->SetTopWindow(NULL
);
68 wxPythonApp
->OnExit();
73 wxApp::CommonCleanUp();
79 //---------------------------------------------------------------------
80 // a few native methods to add to the module
81 //----------------------------------------------------------------------
84 // Start the user application, user App's OnInit method is a parameter here
85 PyObject
* __wxStart(PyObject
* /* self */, PyObject
* args
)
87 PyObject
* onInitFunc
= NULL
;
92 if (!PyArg_ParseTuple(args
, "O", &onInitFunc
))
95 // This is where we pick up one part of the wxEntry functionality...
96 // the rest is in AfterMainLoop.
98 wxPythonApp
->argc
= 0;
99 wxPythonApp
->argv
= NULL
;
100 wxPythonApp
->OnInitGui();
103 wxClassInfo::InitializeClasses();
104 PyObject
* sysargv
= PySys_GetObject("argv");
105 int argc
= PyList_Size(sysargv
);
106 char** argv
= new char*[argc
+1];
108 for(x
=0; x
<argc
; x
++)
109 argv
[x
] = PyString_AsString(PyList_GetItem(sysargv
, x
));
113 wxTheApp
->argc
= argc
;
114 wxTheApp
->argv
= argv
;
116 gtk_init( &wxTheApp
->argc
, &wxTheApp
->argv
);
122 gtk_widget_push_visual(gdk_imlib_get_visual());
124 gtk_widget_push_colormap(gdk_imlib_get_colormap());
130 wxTheApp
->OnInitGui();
135 // Call the Python App's OnInit function
136 arglist
= PyTuple_New(0);
137 result
= PyEval_CallObject(onInitFunc
, arglist
);
143 if (! PyInt_Check(result
)) {
144 PyErr_SetString(PyExc_TypeError
, "OnInit should return a boolean value");
147 bResult
= PyInt_AS_LONG(result
);
149 wxPythonApp
->DeletePendingObjects();
150 wxPythonApp
->OnExit();
155 wxApp::CommonCleanUp();
157 PyErr_SetString(PyExc_SystemExit
, "OnInit returned false, exiting...");
162 wxTheApp
->m_initialized
= (wxTopLevelWindows
.Number() > 0);
170 //PyObject* __wxMainLoop(PyObject* /* self */, PyObject* /* args */)
172 // wxPythonApp->MainLoop();
173 // if (wxPythonApp->wx_frame) {
174 // wxPythonApp->wx_frame->GetEventHandler()->OnClose();
175 // delete wxPythonApp->wx_frame;
179 // Py_INCREF(Py_None);
184 //PyObject* __wxExitMainLoop(PyObject* /* self */, PyObject* /* args */)
186 // wxPythonApp->ExitMainLoop();
187 // Py_INCREF(Py_None);
193 //PyObject* __wxAddCallback(PyObject* /* self */, PyObject* args)
197 // PyObject* callback;
199 // wxPyEvtHandlers* evtHdlr;
201 // if (!PyArg_ParseTuple(args, "ssO", &swigPtr, &name, &callback))
204 // if (!PyCallable_Check(callback)) {
205 // PyErr_SetString(PyExc_TypeError, "Expected a callable object.");
209 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
210 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
214 // evtHdlr = (wxPyEvtHandlers*)win->GetClientData();
215 // if (! evtHdlr->addCallback(name, callback)) {
216 // PyErr_SetString(PyExc_TypeError, "Unknown callback name.");
220 // Py_INCREF(Py_None);
226 //PyObject* __wxSetWinEvtHdlr(PyObject* /* self */, PyObject* args)
230 // wxPyEvtHandlers* evtHdlr;
232 // if (!PyArg_ParseTuple(args, "s", &swigPtr))
235 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
236 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
240 // evtHdlr = new wxPyEvtHandlers;
241 // win->SetClientData((char*)evtHdlr);
243 // Py_INCREF(Py_None);
249 //PyObject* __wxDelWinEvtHdlr(PyObject* /* self */, PyObject* args)
253 // wxPyEvtHandlers* evtHdlr;
255 // if (!PyArg_ParseTuple(args, "s", &swigPtr))
258 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
259 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
263 // evtHdlr = (wxPyEvtHandlers*)win->GetClientData();
264 // printf("__wxDelWinEvtHdlr: %p\n", evtHdlr);
267 // Py_INCREF(Py_None);
273 PyObject
* wxPython_dict
;
274 PyObject
* __wxSetDictionary(PyObject
* /* self */, PyObject
* args
)
277 if (!PyArg_ParseTuple(args
, "O", &wxPython_dict
))
280 if (!PyDict_Check(wxPython_dict
)) {
281 PyErr_SetString(PyExc_TypeError
, "_wxSetDictionary must have dictionary object!");
285 #define wxPlatform "__MOTIF__"
288 #define wxPlatform "__GTK__"
290 #if defined(__WIN32__) || defined(__WXMSW__)
291 #define wxPlatform "__WXMSW__"
294 #define wxPlatform "__MAC__"
297 PyDict_SetItemString(wxPython_dict
, "wxPlatform", PyString_FromString(wxPlatform
));
304 //---------------------------------------------------------------------------
308 PyObject
* wxPyConstructObject(void* ptr
, char* className
)
310 char buff
[64]; // should be big enough...
313 sprintf(buff
, "_%s_p", className
);
314 SWIG_MakePtr(swigptr
, ptr
, buff
);
316 sprintf(buff
, "%sPtr", className
);
317 PyObject
* classobj
= PyDict_GetItemString(wxPython_dict
, buff
);
323 PyObject
* arg
= Py_BuildValue("(s)", swigptr
);
324 PyObject
* obj
= PyInstance_New(classobj
, arg
, NULL
);
331 // This function is used for all events destined for Python event handlers.
332 void wxPyCallback::EventThunker(wxEvent
& event
) {
333 wxPyCallback
* cb
= (wxPyCallback
*)event
.m_callbackUserData
;
334 PyObject
* func
= cb
->m_func
;
339 arg
= wxPyConstructObject((void*)&event
, event
.GetClassInfo()->GetClassName());
341 tuple
= PyTuple_New(1);
342 PyTuple_SET_ITEM(tuple
, 0, arg
);
343 result
= PyEval_CallObject(func
, tuple
);
355 //---------------------------------------------------------------------------
357 wxPyMenu::wxPyMenu(const wxString
& title
, PyObject
* _func
)
358 : wxMenu(title
, (wxFunction
)(func
? MenuCallback
: NULL
)), func(0) {
366 wxPyMenu::~wxPyMenu() {
372 void wxPyMenu::MenuCallback(wxMenu
& menu
, wxCommandEvent
& evt
) {
373 PyObject
* evtobj
= wxPyConstructObject((void*)&evt
, "wxCommandEvent");
374 PyObject
* menuobj
= wxPyConstructObject((void*)&menu
, "wxMenu");
375 if (PyErr_Occurred()) {
376 // bail out if a problem
380 // Now call the callback...
381 PyObject
* func
= ((wxPyMenu
*)&menu
)->func
;
382 PyObject
* args
= Py_BuildValue("(OO)", menuobj
, evtobj
);
383 PyObject
* res
= PyEval_CallObject(func
, args
);
391 //---------------------------------------------------------------------------
393 wxPyTimer::wxPyTimer(PyObject
* callback
) {
398 wxPyTimer::~wxPyTimer() {
402 void wxPyTimer::Notify() {
404 PyObject
* args
= Py_BuildValue("()");
406 result
= PyEval_CallObject(func
, args
);
418 //----------------------------------------------------------------------
419 // wxPyEvtHandlers class
420 //----------------------------------------------------------------------
422 //wxPyEvtHandlers::wxPyEvtHandlers()
423 // : pyOnActivate(0),
429 // pyOnDefaultAction(0),
431 // pyOnInitMenuPopup(0),
433 // pyOnMenuCommand(0),
434 // pyOnMenuSelect(0),
440 // pyOnSysColourChange(0),
442 // pyOnMouseEnter(0),
443 // pyOnRightClick(0),
444 // pyOnDoubleClickSash(0),
450 //wxPyEvtHandlers::~wxPyEvtHandlers()
452 // Py_XDECREF(pyOnActivate);
453 // Py_XDECREF(pyOnChar);
454 // Py_XDECREF(pyOnCharHook);
455 // Py_XDECREF(pyOnClose);
456 // Py_XDECREF(pyOnCommand);
457 // Py_XDECREF(pyOnDropFiles);
458 // Py_XDECREF(pyOnDefaultAction);
459 // Py_XDECREF(pyOnEvent);
460 // Py_XDECREF(pyOnInitMenuPopup);
461 // Py_XDECREF(pyOnKillFocus);
462 // Py_XDECREF(pyOnMenuCommand);
463 // Py_XDECREF(pyOnMenuSelect);
464 // Py_XDECREF(pyOnMove);
465 // Py_XDECREF(pyOnPaint);
466 // Py_XDECREF(pyOnScroll);
467 // Py_XDECREF(pyOnSetFocus);
468 // Py_XDECREF(pyOnSize);
469 // Py_XDECREF(pyOnSysColourChange);
470 // Py_XDECREF(pyOnLeftClick);
471 // Py_XDECREF(pyOnMouseEnter);
472 // Py_XDECREF(pyOnRightClick);
473 // Py_XDECREF(pyOnDoubleClickSash);
474 // Py_XDECREF(pyOnUnsplit);
476 // wxNode* node = cleanupList.First();
478 // delete (wxPyEvtHandlers*)node->Data();
480 // node = cleanupList.First();
483 // node = decrefList.First();
485 // PyObject* obj = (PyObject*)node->Data();
488 // node = decrefList.First();
490 //// printf("~wxPyEvtHandlers: %p\n", this);
493 ////----------------------------------------------------------------------
495 //Bool wxPyEvtHandlers::addCallback(char* name, PyObject* callback)
497 // Py_INCREF(callback);
499 // if (strcmp(name, "OnActivate") == 0) {
500 // pyOnActivate = callback;
503 // if (strcmp(name, "OnChar") == 0) {
504 // pyOnChar = callback;
507 // if (strcmp(name, "OnCharHook") == 0) {
508 // pyOnCharHook = callback;
511 // if (strcmp(name, "OnClose") == 0) {
512 // pyOnClose = callback;
515 // if (strcmp(name, "OnCommand") == 0) {
516 // pyOnCommand = callback;
519 // if (strcmp(name, "OnDropFiles") == 0) {
520 // pyOnDropFiles = callback;
523 // if (strcmp(name, "OnDefaultAction") == 0) {
524 // pyOnDefaultAction = callback;
527 // if (strcmp(name, "OnEvent") == 0) {
528 // pyOnEvent = callback;
531 // if (strcmp(name, "OnInitMenuPopup") == 0) {
532 // pyOnInitMenuPopup = callback;
535 // if (strcmp(name, "OnKillFocus") == 0) {
536 // pyOnKillFocus = callback;
539 // if (strcmp(name, "OnMenuCommand") == 0) {
540 // pyOnMenuCommand = callback;
543 // if (strcmp(name, "OnMenuSelect") == 0) {
544 // pyOnMenuSelect = callback;
547 // if (strcmp(name, "OnMove") == 0) {
548 // pyOnMove = callback;
551 // if (strcmp(name, "OnPaint") == 0) {
552 // pyOnPaint = callback;
555 // if (strcmp(name, "OnScroll") == 0) {
556 // pyOnScroll = callback;
559 // if (strcmp(name, "OnSetFocus") == 0) {
560 // pyOnSetFocus = callback;
563 // if (strcmp(name, "OnSize") == 0) {
564 // pyOnSize = callback;
567 // if (strcmp(name, "OnSysColourChange") == 0) {
568 // pyOnSysColourChange = callback;
571 // if (strcmp(name, "OnLeftClick") == 0) {
572 // pyOnLeftClick = callback;
575 // if (strcmp(name, "OnMouseEnter") == 0) {
576 // pyOnMouseEnter = callback;
579 // if (strcmp(name, "OnRightClick") == 0) {
580 // pyOnRightClick = callback;
583 // if (strcmp(name, "OnDoubleClickSash") == 0) {
584 // pyOnDoubleClickSash = callback;
587 // if (strcmp(name, "OnUnsplit") == 0) {
588 // pyOnUnsplit = callback;
592 // // If we get here, there was no match.
593 // Py_DECREF(callback);
598 ////----------------------------------------------------------------------
599 //// Helpers to assist in calling the python callable objects
600 ////----------------------------------------------------------------------
602 //PyObject* wxPyEvtHandlers::constructObject(void* ptr, char* className)
604 // char buff[64]; // should be big enough...
607 // sprintf(buff, "_%s_p", className);
608 // SWIG_MakePtr(swigptr, ptr, buff);
610 // sprintf(buff, "%sPtr", className);
611 // PyObject* classobj = PyDict_GetItemString(wxPython_dict, buff);
612 // PyObject* arg = Py_BuildValue("(s)", swigptr);
613 // PyObject* obj = PyInstance_New(classobj, arg, NULL);
621 //int wxPyEvtHandlers::callFunc(PyObject* func, PyObject* arglist)
624 // int retval = FALSE;
626 // result = PyEval_CallObject(func, arglist);
627 // Py_DECREF(arglist);
628 // if (result) { // Assumes an integer return type...
629 // retval = PyInt_AsLong(result);
630 // Py_DECREF(result);
631 // PyErr_Clear(); // forget about it if it's not...
638 ////---------------------------------------------------------------------------
639 //// Methods and helpers of the wxPy* classes
640 ////---------------------------------------------------------------------------
642 //IMP_OnActivate(wxFrame, wxPyFrame);
643 //IMP_OnCharHook(wxFrame, wxPyFrame);
644 //IMP_OnClose(wxFrame, wxPyFrame);
645 //IMP_OnMenuCommand(wxFrame, wxPyFrame);
646 //IMP_OnMenuSelect(wxFrame, wxPyFrame);
647 //IMP_OnSize(wxFrame, wxPyFrame);
648 //IMP_OnDropFiles(wxFrame, wxPyFrame);
650 //IMP_OnChar(wxCanvas, wxPyCanvas);
651 //IMP_OnEvent(wxCanvas, wxPyCanvas);
652 //IMP_OnPaint(wxCanvas, wxPyCanvas);
653 //IMP_OnScroll(wxCanvas, wxPyCanvas);
654 //IMP_OnDropFiles(wxCanvas, wxPyCanvas);
656 //IMP_OnChar(wxPanel, wxPyPanel);
657 //IMP_OnEvent(wxPanel, wxPyPanel);
658 //IMP_OnPaint(wxPanel, wxPyPanel);
659 //IMP_OnScroll(wxPanel, wxPyPanel);
660 //IMP_OnCommand(wxPanel, wxPyPanel);
661 //IMP_OnDefaultAction(wxPanel, wxPyPanel);
662 //IMP_OnDropFiles(wxPanel, wxPyPanel);
664 //IMP_OnChar(wxTextWindow, wxPyTextWindow);
665 //IMP_OnDropFiles(wxTextWindow, wxPyTextWindow);
667 //IMP_OnCharHook(wxDialogBox, wxPyDialogBox);
668 //IMP_OnClose(wxDialogBox, wxPyDialogBox);
669 //IMP_OnSize(wxDialogBox, wxPyDialogBox);
670 //IMP_OnDropFiles(wxDialogBox, wxPyDialogBox);
671 //IMP_OnChar(wxDialogBox, wxPyDialogBox);
672 //IMP_OnEvent(wxDialogBox, wxPyDialogBox);
673 //IMP_OnPaint(wxDialogBox, wxPyDialogBox);
674 //IMP_OnScroll(wxDialogBox, wxPyDialogBox);
675 //IMP_OnCommand(wxDialogBox, wxPyDialogBox);
676 //IMP_OnDefaultAction(wxDialogBox, wxPyDialogBox);
678 //IMP_OnChar(wxToolBar, wxPyToolBar);
679 //IMP_OnEvent(wxToolBar, wxPyToolBar);
680 //IMP_OnPaint(wxToolBar, wxPyToolBar);
681 //IMP_OnScroll(wxToolBar, wxPyToolBar);
682 //IMP_OnCommand(wxToolBar, wxPyToolBar);
683 //IMP_OnDefaultAction(wxToolBar, wxPyToolBar);
684 //IMP_OnDropFiles(wxToolBar, wxPyToolBar);
685 //IMP_OnMouseEnter(wxToolBar, wxPyToolBar);
686 //IMP_OnRightClick(wxToolBar, wxPyToolBar);
688 //IMP_OnChar(wxButtonBar, wxPyButtonBar);
689 //IMP_OnEvent(wxButtonBar, wxPyButtonBar);
690 //IMP_OnPaint(wxButtonBar, wxPyButtonBar);
691 //IMP_OnScroll(wxButtonBar, wxPyButtonBar);
692 //IMP_OnCommand(wxButtonBar, wxPyButtonBar);
693 //IMP_OnDefaultAction(wxButtonBar, wxPyButtonBar);
694 //IMP_OnDropFiles(wxButtonBar, wxPyButtonBar);
695 //IMP_OnMouseEnter(wxButtonBar, wxPyButtonBar);
696 //IMP_OnRightClick(wxButtonBar, wxPyButtonBar);
698 //IMP_OnDoubleClickSash(wxSplitterWindow, wxPySplitterWindow);
699 //IMP_OnUnsplit(wxSplitterWindow, wxPySplitterWindow);
703 //Bool wxPyToolBar::OnLeftClick(int a, int b) {
704 // wxPyEvtHandlers* peh=(wxPyEvtHandlers*)GetClientData();
705 // if (peh->pyOnLeftClick)
706 // return peh->callFunc(peh->pyOnLeftClick, Py_BuildValue("(ii)",a,b));
708 // // If there is no Python callback, redirect the request to
709 // // the OnMenuCommand of the parent frame.
710 // wxFrame* frame = (wxFrame*)GetParent();
711 // frame->OnMenuCommand(a);
715 //// return wxToolBar::OnLeftClick(a,b);
717 //Bool wxPyToolBar::baseclass_OnLeftClick(int a, int b) {
718 // return wxToolBar::OnLeftClick(a,b);
722 //Bool wxPyButtonBar::OnLeftClick(int a, int b) {
723 // wxPyEvtHandlers* peh=(wxPyEvtHandlers*)GetClientData();
724 // if (peh->pyOnLeftClick)
725 // return peh->callFunc(peh->pyOnLeftClick, Py_BuildValue("(ii)",a,b));
727 // // If there is no Python callback, redirect the request to
728 // // the OnMenuCommand of the parent frame.
729 // wxFrame* frame = (wxFrame*)GetParent();
730 // frame->OnMenuCommand(a);
734 //Bool wxPyButtonBar::baseclass_OnLeftClick(int a, int b) {
735 // return wxButtonBar::OnLeftClick(a,b);
740 //wxPyMenu::wxPyMenu(PyObject* _func)
741 // : wxMenu(NULL, (wxFunction)(func ? MenuCallback : NULL)), func(0) {
749 //wxPyMenu::~wxPyMenu() {
755 //void wxPyMenu::MenuCallback(wxWindow& win, wxCommandEvent& evt) {
756 // wxPyEvtHandlers* peh= new wxPyEvtHandlers; // Used for the helper methods
757 // PyObject* evtobj = peh->constructObject((void*)&evt, "wxCommandEvent");
758 // PyObject* winobj = peh->constructObject((void*)&win, "wxWindow");
759 // if (PyErr_Occurred()) {
760 // // bail out if a problem
765 // // Now call the callback...
766 // PyObject* func = ((wxPyMenu*)&win)->func;
767 // peh->callFunc(func, Py_BuildValue("(OO)", winobj, evtobj));
768 // Py_DECREF(evtobj);
769 // Py_DECREF(winobj);
775 //wxPyTimer::wxPyTimer(PyObject* callback) {
780 //wxPyTimer::~wxPyTimer() {
784 //void wxPyTimer::Notify() {
785 // wxPyEvtHandlers* peh= new wxPyEvtHandlers; // just for the helper methods
786 // peh->callFunc(func, Py_BuildValue("()"));
790 //----------------------------------------------------------------------
791 //----------------------------------------------------------------------
792 // Some helper functions for typemaps in my_typemaps.i, so they won't be
793 // imcluded in every file...
796 int* int_LIST_helper(PyObject
* source
) {
797 if (!PyList_Check(source
)) {
798 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
801 int count
= PyList_Size(source
);
802 int* temp
= new int[count
];
804 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
807 for (int x
=0; x
<count
; x
++) {
808 PyObject
* o
= PyList_GetItem(source
, x
);
809 if (! PyInt_Check(o
)) {
810 PyErr_SetString(PyExc_TypeError
, "Expected a list of integers.");
813 temp
[x
] = PyInt_AsLong(o
);
819 long* long_LIST_helper(PyObject
* source
) {
820 if (!PyList_Check(source
)) {
821 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
824 int count
= PyList_Size(source
);
825 long* temp
= new long[count
];
827 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
830 for (int x
=0; x
<count
; x
++) {
831 PyObject
* o
= PyList_GetItem(source
, x
);
832 if (! PyInt_Check(o
)) {
833 PyErr_SetString(PyExc_TypeError
, "Expected a list of integers.");
836 temp
[x
] = PyInt_AsLong(o
);
842 char** string_LIST_helper(PyObject
* source
) {
843 if (!PyList_Check(source
)) {
844 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
847 int count
= PyList_Size(source
);
848 char** temp
= new char*[count
];
850 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
853 for (int x
=0; x
<count
; x
++) {
854 PyObject
* o
= PyList_GetItem(source
, x
);
855 if (! PyString_Check(o
)) {
856 PyErr_SetString(PyExc_TypeError
, "Expected a list of strings.");
859 temp
[x
] = PyString_AsString(o
);
866 wxPoint
* wxPoint_LIST_helper(PyObject
* source
) {
867 if (!PyList_Check(source
)) {
868 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
871 int count
= PyList_Size(source
);
872 wxPoint
* temp
= new wxPoint
[count
];
874 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
877 for (int x
=0; x
<count
; x
++) {
878 PyObject
* o
= PyList_GetItem(source
, x
);
879 if (PyString_Check(o
)) {
880 char* st
= PyString_AsString(o
);
882 if (SWIG_GetPtr(st
,(void **) &pt
,"_wxPoint_p")) {
883 PyErr_SetString(PyExc_TypeError
,"Expected _wxPoint_p.");
888 else if (PyTuple_Check(o
)) {
889 PyObject
* o1
= PyTuple_GetItem(o
, 0);
890 PyObject
* o2
= PyTuple_GetItem(o
, 1);
892 temp
[x
].x
= PyInt_AsLong(o1
);
893 temp
[x
].y
= PyInt_AsLong(o2
);
896 PyErr_SetString(PyExc_TypeError
, "Expected a list of 2-tuples or wxPoints.");
904 wxBitmap
** wxBitmap_LIST_helper(PyObject
* source
) {
905 if (!PyList_Check(source
)) {
906 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
909 int count
= PyList_Size(source
);
910 wxBitmap
** temp
= new wxBitmap
*[count
];
912 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
915 for (int x
=0; x
<count
; x
++) {
916 PyObject
* o
= PyList_GetItem(source
, x
);
917 if (PyString_Check(o
)) {
918 char* st
= PyString_AsString(o
);
920 if (SWIG_GetPtr(st
,(void **) &pt
,"_wxBitmap_p")) {
921 PyErr_SetString(PyExc_TypeError
,"Expected _wxBitmap_p.");
927 PyErr_SetString(PyExc_TypeError
, "Expected a list of wxBitmaps.");
936 wxString
* wxString_LIST_helper(PyObject
* source
) {
937 if (!PyList_Check(source
)) {
938 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
941 int count
= PyList_Size(source
);
942 wxString
* temp
= new wxString
[count
];
944 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
947 for (int x
=0; x
<count
; x
++) {
948 PyObject
* o
= PyList_GetItem(source
, x
);
949 if (! PyString_Check(o
)) {
950 PyErr_SetString(PyExc_TypeError
, "Expected a list of strings.");
953 temp
[x
] = PyString_AsString(o
);
960 wxAcceleratorEntry
* wxAcceleratorEntry_LIST_helper(PyObject
* source
) {
961 if (!PyList_Check(source
)) {
962 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
965 int count
= PyList_Size(source
);
966 wxAcceleratorEntry
* temp
= new wxAcceleratorEntry
[count
];
968 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
971 for (int x
=0; x
<count
; x
++) {
972 PyObject
* o
= PyList_GetItem(source
, x
);
973 if (PyString_Check(o
)) {
974 char* st
= PyString_AsString(o
);
975 wxAcceleratorEntry
* ae
;
976 if (SWIG_GetPtr(st
,(void **) &ae
,"_wxAcceleratorEntry_p")) {
977 PyErr_SetString(PyExc_TypeError
,"Expected _wxAcceleratorEntry_p.");
982 else if (PyTuple_Check(o
)) {
983 PyObject
* o1
= PyTuple_GetItem(o
, 0);
984 PyObject
* o2
= PyTuple_GetItem(o
, 1);
985 PyObject
* o3
= PyTuple_GetItem(o
, 2);
987 temp
[x
].m_flags
= PyInt_AsLong(o1
);
988 temp
[x
].m_keyCode
= PyInt_AsLong(o2
);
989 temp
[x
].m_command
= PyInt_AsLong(o3
);
992 PyErr_SetString(PyExc_TypeError
, "Expected a list of 3-tuples or wxAcceleratorEntry objects.");
1001 //----------------------------------------------------------------------
1002 // A WinMain for when wxWindows and Python are linked together in a single
1003 // application, instead of as a dynamic module
1006 //#if !defined(WIN_PYD) && defined(WIN32)
1008 //extern "C" int Py_Main(int argc, char** argv);
1010 //int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR m_lpCmdLine,
1016 // // Initialize wxWindows, but don't start the main loop
1017 // wxEntry(hInstance, hPrevInstance, m_lpCmdLine, nCmdShow, FALSE);
1020 // PyObject *argvList = PyList_New(0);
1022 // char* stderrfilename = "wxpstderr.log";
1024 // char* script = NULL;
1025 // int argc = wxPythonApp->argc;
1026 // char** argv = wxPythonApp->argv;
1028 // for (int i = 1; i < argc; i++) {
1029 // if (strncmp(argv[i], "wxpstderr=", 10) == 0)
1030 // stderrfilename = argv[i]+10;
1032 // PyList_Append(argvList, PyString_FromString(argv[i]));
1034 // script = argv[i];
1039 // PySys_SetObject("argv", argvList);
1043 //// //PyRun_SimpleString("import sys; sys.stdout=open('wxpstdout.log','w')");
1044 // sprintf(buf, "import sys; sys.stdout=sys.stderr=open('%s','w')", stderrfilename);
1045 // PyRun_SimpleString(buf);
1051 // FILE *fp = fopen(script, "r");
1053 // PyRun_SimpleFile(fp, script);// This returns after wxpApp constructor
1058 // sprintf(msg, "Cannot open %s", script);
1059 // wxMessageBox(msg);
1063 // PyRun_SimpleString("import wxpide");
1071 //----------------------------------------------------------------------
1073 /////////////////////////////////////////////////////////////////////////////
1076 // Revision 1.6 1998/08/18 21:54:12 RD
1077 // ifdef out some wxGTK specific code
1079 // Revision 1.5 1998/08/18 19:48:17 RD
1080 // more wxGTK compatibility things.
1082 // It builds now but there are serious runtime problems...
1084 // Revision 1.4 1998/08/16 04:31:06 RD
1087 // Revision 1.3 1998/08/15 07:36:36 RD
1088 // - Moved the header in the .i files out of the code that gets put into
1089 // the .cpp files. It caused CVS conflicts because of the RCS ID being
1090 // different each time.
1092 // - A few minor fixes.
1094 // Revision 1.2 1998/08/14 23:36:36 RD
1095 // Beginings of wxGTK compatibility
1097 // Revision 1.1 1998/08/09 08:25:51 RD