1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Helper functions/classes for the wxPython extenaion module
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
18 //---------------------------------------------------------------------------
20 //wxHashTable* wxPyWindows = NULL;
23 wxPoint wxPyDefaultPosition
; //wxDefaultPosition);
24 wxSize wxPyDefaultSize
; //wxDefaultSize);
25 wxString
wxPyEmptyStr("");
29 //----------------------------------------------------------------------
30 // Class for implementing the wxp main application shell.
31 //----------------------------------------------------------------------
33 wxPyApp
*wxPythonApp
= NULL
; // Global instance of application object
36 // This one isn't acutally called... See __wxStart()
37 bool wxPyApp::OnInit(void) {
41 int wxPyApp::MainLoop(void) {
42 int retval
= wxApp::MainLoop();
47 void wxPyApp::AfterMainLoop(void) {
48 // more stuff from wxEntry...
49 if (wxPythonApp
->GetTopWindow()) {
50 // Forcibly delete the window.
51 if (wxPythonApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame
)) ||
52 wxPythonApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxDialog
))) {
54 wxPythonApp
->GetTopWindow()->Close(TRUE
);
55 wxPythonApp
->DeletePendingObjects();
58 delete wxPythonApp
->GetTopWindow();
59 wxPythonApp
->SetTopWindow(NULL
);
63 wxPythonApp
->OnExit();
68 wxApp::CommonCleanup();
74 //----------------------------------------------------------------------
75 // a few native methods to add to the module
76 //----------------------------------------------------------------------
79 // Start the user application, user App's OnInit method is a parameter here
80 PyObject
* __wxStart(PyObject
* /* self */, PyObject
* args
)
82 PyObject
* onInitFunc
= NULL
;
87 if (!PyArg_ParseTuple(args
, "O", &onInitFunc
))
90 // This is where we pick up one part of the wxEntry functionality...
91 // the rest is in AfterMainLoop.
93 wxPythonApp
->argc
= 0;
94 wxPythonApp
->argv
= NULL
;
95 wxPythonApp
->OnInitGui();
99 wxTheApp
->argv
= NULL
;
101 gtk_init( &wxTheApp
->argc
, &wxTheApp
->argv
);
107 gtk_widget_push_visual(gdk_imlib_get_visual());
109 gtk_widget_push_colormap(gdk_imlib_get_colormap());
115 wxTheApp
->OnInitGui();
120 // Call the Python App's OnInit function
121 arglist
= PyTuple_New(0);
122 result
= PyEval_CallObject(onInitFunc
, arglist
);
128 if (! PyInt_Check(result
)) {
129 PyErr_SetString(PyExc_TypeError
, "OnInit should return a boolean value");
132 bResult
= PyInt_AS_LONG(result
);
134 wxPythonApp
->DeletePendingObjects();
135 wxPythonApp
->OnExit();
140 wxApp::CommonCleanup();
142 PyErr_SetString(PyExc_SystemExit
, "OnInit returned false, exiting...");
151 //PyObject* __wxMainLoop(PyObject* /* self */, PyObject* /* args */)
153 // wxPythonApp->MainLoop();
154 // if (wxPythonApp->wx_frame) {
155 // wxPythonApp->wx_frame->GetEventHandler()->OnClose();
156 // delete wxPythonApp->wx_frame;
160 // Py_INCREF(Py_None);
165 //PyObject* __wxExitMainLoop(PyObject* /* self */, PyObject* /* args */)
167 // wxPythonApp->ExitMainLoop();
168 // Py_INCREF(Py_None);
174 //PyObject* __wxAddCallback(PyObject* /* self */, PyObject* args)
178 // PyObject* callback;
180 // wxPyEvtHandlers* evtHdlr;
182 // if (!PyArg_ParseTuple(args, "ssO", &swigPtr, &name, &callback))
185 // if (!PyCallable_Check(callback)) {
186 // PyErr_SetString(PyExc_TypeError, "Expected a callable object.");
190 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
191 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
195 // evtHdlr = (wxPyEvtHandlers*)win->GetClientData();
196 // if (! evtHdlr->addCallback(name, callback)) {
197 // PyErr_SetString(PyExc_TypeError, "Unknown callback name.");
201 // Py_INCREF(Py_None);
207 //PyObject* __wxSetWinEvtHdlr(PyObject* /* self */, PyObject* args)
211 // wxPyEvtHandlers* evtHdlr;
213 // if (!PyArg_ParseTuple(args, "s", &swigPtr))
216 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
217 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
221 // evtHdlr = new wxPyEvtHandlers;
222 // win->SetClientData((char*)evtHdlr);
224 // Py_INCREF(Py_None);
230 //PyObject* __wxDelWinEvtHdlr(PyObject* /* self */, PyObject* args)
234 // wxPyEvtHandlers* evtHdlr;
236 // if (!PyArg_ParseTuple(args, "s", &swigPtr))
239 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
240 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
244 // evtHdlr = (wxPyEvtHandlers*)win->GetClientData();
245 // printf("__wxDelWinEvtHdlr: %p\n", evtHdlr);
248 // Py_INCREF(Py_None);
254 PyObject
* wxPython_dict
;
255 PyObject
* __wxSetDictionary(PyObject
* /* self */, PyObject
* args
)
258 if (!PyArg_ParseTuple(args
, "O", &wxPython_dict
))
261 if (!PyDict_Check(wxPython_dict
)) {
262 PyErr_SetString(PyExc_TypeError
, "_wxSetDictionary must have dictionary object!");
266 #define wxPlatform "__MOTIF__"
269 #define wxPlatform "__GTK__"
271 #if defined(__WIN32__) || defined(__WXMSW__)
272 #define wxPlatform "__WIN32__"
275 #define wxPlatform "__MAC__"
278 PyDict_SetItemString(wxPython_dict
, "wxPlatform", PyString_FromString(wxPlatform
));
285 //---------------------------------------------------------------------------
289 PyObject
* wxPyConstructObject(void* ptr
, char* className
)
291 char buff
[64]; // should be big enough...
294 sprintf(buff
, "_%s_p", className
);
295 SWIG_MakePtr(swigptr
, ptr
, buff
);
297 sprintf(buff
, "%sPtr", className
);
298 PyObject
* classobj
= PyDict_GetItemString(wxPython_dict
, buff
);
304 PyObject
* arg
= Py_BuildValue("(s)", swigptr
);
305 PyObject
* obj
= PyInstance_New(classobj
, arg
, NULL
);
312 // This function is used for all events destined for Python event handlers.
313 void wxPyCallback::EventThunker(wxEvent
& event
) {
314 wxPyCallback
* cb
= (wxPyCallback
*)event
.m_callbackUserData
;
315 PyObject
* func
= cb
->m_func
;
320 arg
= wxPyConstructObject((void*)&event
, event
.GetClassInfo()->GetClassName());
322 tuple
= PyTuple_New(1);
323 PyTuple_SET_ITEM(tuple
, 0, arg
);
324 result
= PyEval_CallObject(func
, tuple
);
336 //---------------------------------------------------------------------------
338 wxPyMenu::wxPyMenu(const wxString
& title
, PyObject
* _func
)
339 : wxMenu(title
, (wxFunction
)(func
? MenuCallback
: NULL
)), func(0) {
347 wxPyMenu::~wxPyMenu() {
353 void wxPyMenu::MenuCallback(wxMenu
& menu
, wxCommandEvent
& evt
) {
354 PyObject
* evtobj
= wxPyConstructObject((void*)&evt
, "wxCommandEvent");
355 PyObject
* menuobj
= wxPyConstructObject((void*)&menu
, "wxMenu");
356 if (PyErr_Occurred()) {
357 // bail out if a problem
361 // Now call the callback...
362 PyObject
* func
= ((wxPyMenu
*)&menu
)->func
;
363 PyObject
* args
= Py_BuildValue("(OO)", menuobj
, evtobj
);
364 PyObject
* res
= PyEval_CallObject(func
, args
);
371 //---------------------------------------------------------------------------
373 wxPyTimer::wxPyTimer(PyObject
* callback
) {
378 wxPyTimer::~wxPyTimer() {
382 void wxPyTimer::Notify() {
384 PyObject
* args
= Py_BuildValue("()");
386 result
= PyEval_CallObject(func
, args
);
398 //----------------------------------------------------------------------
399 // wxPyEvtHandlers class
400 //----------------------------------------------------------------------
402 //wxPyEvtHandlers::wxPyEvtHandlers()
403 // : pyOnActivate(0),
409 // pyOnDefaultAction(0),
411 // pyOnInitMenuPopup(0),
413 // pyOnMenuCommand(0),
414 // pyOnMenuSelect(0),
420 // pyOnSysColourChange(0),
422 // pyOnMouseEnter(0),
423 // pyOnRightClick(0),
424 // pyOnDoubleClickSash(0),
430 //wxPyEvtHandlers::~wxPyEvtHandlers()
432 // Py_XDECREF(pyOnActivate);
433 // Py_XDECREF(pyOnChar);
434 // Py_XDECREF(pyOnCharHook);
435 // Py_XDECREF(pyOnClose);
436 // Py_XDECREF(pyOnCommand);
437 // Py_XDECREF(pyOnDropFiles);
438 // Py_XDECREF(pyOnDefaultAction);
439 // Py_XDECREF(pyOnEvent);
440 // Py_XDECREF(pyOnInitMenuPopup);
441 // Py_XDECREF(pyOnKillFocus);
442 // Py_XDECREF(pyOnMenuCommand);
443 // Py_XDECREF(pyOnMenuSelect);
444 // Py_XDECREF(pyOnMove);
445 // Py_XDECREF(pyOnPaint);
446 // Py_XDECREF(pyOnScroll);
447 // Py_XDECREF(pyOnSetFocus);
448 // Py_XDECREF(pyOnSize);
449 // Py_XDECREF(pyOnSysColourChange);
450 // Py_XDECREF(pyOnLeftClick);
451 // Py_XDECREF(pyOnMouseEnter);
452 // Py_XDECREF(pyOnRightClick);
453 // Py_XDECREF(pyOnDoubleClickSash);
454 // Py_XDECREF(pyOnUnsplit);
456 // wxNode* node = cleanupList.First();
458 // delete (wxPyEvtHandlers*)node->Data();
460 // node = cleanupList.First();
463 // node = decrefList.First();
465 // PyObject* obj = (PyObject*)node->Data();
468 // node = decrefList.First();
470 //// printf("~wxPyEvtHandlers: %p\n", this);
473 ////----------------------------------------------------------------------
475 //Bool wxPyEvtHandlers::addCallback(char* name, PyObject* callback)
477 // Py_INCREF(callback);
479 // if (strcmp(name, "OnActivate") == 0) {
480 // pyOnActivate = callback;
483 // if (strcmp(name, "OnChar") == 0) {
484 // pyOnChar = callback;
487 // if (strcmp(name, "OnCharHook") == 0) {
488 // pyOnCharHook = callback;
491 // if (strcmp(name, "OnClose") == 0) {
492 // pyOnClose = callback;
495 // if (strcmp(name, "OnCommand") == 0) {
496 // pyOnCommand = callback;
499 // if (strcmp(name, "OnDropFiles") == 0) {
500 // pyOnDropFiles = callback;
503 // if (strcmp(name, "OnDefaultAction") == 0) {
504 // pyOnDefaultAction = callback;
507 // if (strcmp(name, "OnEvent") == 0) {
508 // pyOnEvent = callback;
511 // if (strcmp(name, "OnInitMenuPopup") == 0) {
512 // pyOnInitMenuPopup = callback;
515 // if (strcmp(name, "OnKillFocus") == 0) {
516 // pyOnKillFocus = callback;
519 // if (strcmp(name, "OnMenuCommand") == 0) {
520 // pyOnMenuCommand = callback;
523 // if (strcmp(name, "OnMenuSelect") == 0) {
524 // pyOnMenuSelect = callback;
527 // if (strcmp(name, "OnMove") == 0) {
528 // pyOnMove = callback;
531 // if (strcmp(name, "OnPaint") == 0) {
532 // pyOnPaint = callback;
535 // if (strcmp(name, "OnScroll") == 0) {
536 // pyOnScroll = callback;
539 // if (strcmp(name, "OnSetFocus") == 0) {
540 // pyOnSetFocus = callback;
543 // if (strcmp(name, "OnSize") == 0) {
544 // pyOnSize = callback;
547 // if (strcmp(name, "OnSysColourChange") == 0) {
548 // pyOnSysColourChange = callback;
551 // if (strcmp(name, "OnLeftClick") == 0) {
552 // pyOnLeftClick = callback;
555 // if (strcmp(name, "OnMouseEnter") == 0) {
556 // pyOnMouseEnter = callback;
559 // if (strcmp(name, "OnRightClick") == 0) {
560 // pyOnRightClick = callback;
563 // if (strcmp(name, "OnDoubleClickSash") == 0) {
564 // pyOnDoubleClickSash = callback;
567 // if (strcmp(name, "OnUnsplit") == 0) {
568 // pyOnUnsplit = callback;
572 // // If we get here, there was no match.
573 // Py_DECREF(callback);
578 ////----------------------------------------------------------------------
579 //// Helpers to assist in calling the python callable objects
580 ////----------------------------------------------------------------------
582 //PyObject* wxPyEvtHandlers::constructObject(void* ptr, char* className)
584 // char buff[64]; // should be big enough...
587 // sprintf(buff, "_%s_p", className);
588 // SWIG_MakePtr(swigptr, ptr, buff);
590 // sprintf(buff, "%sPtr", className);
591 // PyObject* classobj = PyDict_GetItemString(wxPython_dict, buff);
592 // PyObject* arg = Py_BuildValue("(s)", swigptr);
593 // PyObject* obj = PyInstance_New(classobj, arg, NULL);
601 //int wxPyEvtHandlers::callFunc(PyObject* func, PyObject* arglist)
604 // int retval = FALSE;
606 // result = PyEval_CallObject(func, arglist);
607 // Py_DECREF(arglist);
608 // if (result) { // Assumes an integer return type...
609 // retval = PyInt_AsLong(result);
610 // Py_DECREF(result);
611 // PyErr_Clear(); // forget about it if it's not...
618 ////---------------------------------------------------------------------------
619 //// Methods and helpers of the wxPy* classes
620 ////---------------------------------------------------------------------------
622 //IMP_OnActivate(wxFrame, wxPyFrame);
623 //IMP_OnCharHook(wxFrame, wxPyFrame);
624 //IMP_OnClose(wxFrame, wxPyFrame);
625 //IMP_OnMenuCommand(wxFrame, wxPyFrame);
626 //IMP_OnMenuSelect(wxFrame, wxPyFrame);
627 //IMP_OnSize(wxFrame, wxPyFrame);
628 //IMP_OnDropFiles(wxFrame, wxPyFrame);
630 //IMP_OnChar(wxCanvas, wxPyCanvas);
631 //IMP_OnEvent(wxCanvas, wxPyCanvas);
632 //IMP_OnPaint(wxCanvas, wxPyCanvas);
633 //IMP_OnScroll(wxCanvas, wxPyCanvas);
634 //IMP_OnDropFiles(wxCanvas, wxPyCanvas);
636 //IMP_OnChar(wxPanel, wxPyPanel);
637 //IMP_OnEvent(wxPanel, wxPyPanel);
638 //IMP_OnPaint(wxPanel, wxPyPanel);
639 //IMP_OnScroll(wxPanel, wxPyPanel);
640 //IMP_OnCommand(wxPanel, wxPyPanel);
641 //IMP_OnDefaultAction(wxPanel, wxPyPanel);
642 //IMP_OnDropFiles(wxPanel, wxPyPanel);
644 //IMP_OnChar(wxTextWindow, wxPyTextWindow);
645 //IMP_OnDropFiles(wxTextWindow, wxPyTextWindow);
647 //IMP_OnCharHook(wxDialogBox, wxPyDialogBox);
648 //IMP_OnClose(wxDialogBox, wxPyDialogBox);
649 //IMP_OnSize(wxDialogBox, wxPyDialogBox);
650 //IMP_OnDropFiles(wxDialogBox, wxPyDialogBox);
651 //IMP_OnChar(wxDialogBox, wxPyDialogBox);
652 //IMP_OnEvent(wxDialogBox, wxPyDialogBox);
653 //IMP_OnPaint(wxDialogBox, wxPyDialogBox);
654 //IMP_OnScroll(wxDialogBox, wxPyDialogBox);
655 //IMP_OnCommand(wxDialogBox, wxPyDialogBox);
656 //IMP_OnDefaultAction(wxDialogBox, wxPyDialogBox);
658 //IMP_OnChar(wxToolBar, wxPyToolBar);
659 //IMP_OnEvent(wxToolBar, wxPyToolBar);
660 //IMP_OnPaint(wxToolBar, wxPyToolBar);
661 //IMP_OnScroll(wxToolBar, wxPyToolBar);
662 //IMP_OnCommand(wxToolBar, wxPyToolBar);
663 //IMP_OnDefaultAction(wxToolBar, wxPyToolBar);
664 //IMP_OnDropFiles(wxToolBar, wxPyToolBar);
665 //IMP_OnMouseEnter(wxToolBar, wxPyToolBar);
666 //IMP_OnRightClick(wxToolBar, wxPyToolBar);
668 //IMP_OnChar(wxButtonBar, wxPyButtonBar);
669 //IMP_OnEvent(wxButtonBar, wxPyButtonBar);
670 //IMP_OnPaint(wxButtonBar, wxPyButtonBar);
671 //IMP_OnScroll(wxButtonBar, wxPyButtonBar);
672 //IMP_OnCommand(wxButtonBar, wxPyButtonBar);
673 //IMP_OnDefaultAction(wxButtonBar, wxPyButtonBar);
674 //IMP_OnDropFiles(wxButtonBar, wxPyButtonBar);
675 //IMP_OnMouseEnter(wxButtonBar, wxPyButtonBar);
676 //IMP_OnRightClick(wxButtonBar, wxPyButtonBar);
678 //IMP_OnDoubleClickSash(wxSplitterWindow, wxPySplitterWindow);
679 //IMP_OnUnsplit(wxSplitterWindow, wxPySplitterWindow);
683 //Bool wxPyToolBar::OnLeftClick(int a, int b) {
684 // wxPyEvtHandlers* peh=(wxPyEvtHandlers*)GetClientData();
685 // if (peh->pyOnLeftClick)
686 // return peh->callFunc(peh->pyOnLeftClick, Py_BuildValue("(ii)",a,b));
688 // // If there is no Python callback, redirect the request to
689 // // the OnMenuCommand of the parent frame.
690 // wxFrame* frame = (wxFrame*)GetParent();
691 // frame->OnMenuCommand(a);
695 //// return wxToolBar::OnLeftClick(a,b);
697 //Bool wxPyToolBar::baseclass_OnLeftClick(int a, int b) {
698 // return wxToolBar::OnLeftClick(a,b);
702 //Bool wxPyButtonBar::OnLeftClick(int a, int b) {
703 // wxPyEvtHandlers* peh=(wxPyEvtHandlers*)GetClientData();
704 // if (peh->pyOnLeftClick)
705 // return peh->callFunc(peh->pyOnLeftClick, Py_BuildValue("(ii)",a,b));
707 // // If there is no Python callback, redirect the request to
708 // // the OnMenuCommand of the parent frame.
709 // wxFrame* frame = (wxFrame*)GetParent();
710 // frame->OnMenuCommand(a);
714 //Bool wxPyButtonBar::baseclass_OnLeftClick(int a, int b) {
715 // return wxButtonBar::OnLeftClick(a,b);
720 //wxPyMenu::wxPyMenu(PyObject* _func)
721 // : wxMenu(NULL, (wxFunction)(func ? MenuCallback : NULL)), func(0) {
729 //wxPyMenu::~wxPyMenu() {
735 //void wxPyMenu::MenuCallback(wxWindow& win, wxCommandEvent& evt) {
736 // wxPyEvtHandlers* peh= new wxPyEvtHandlers; // Used for the helper methods
737 // PyObject* evtobj = peh->constructObject((void*)&evt, "wxCommandEvent");
738 // PyObject* winobj = peh->constructObject((void*)&win, "wxWindow");
739 // if (PyErr_Occurred()) {
740 // // bail out if a problem
745 // // Now call the callback...
746 // PyObject* func = ((wxPyMenu*)&win)->func;
747 // peh->callFunc(func, Py_BuildValue("(OO)", winobj, evtobj));
748 // Py_DECREF(evtobj);
749 // Py_DECREF(winobj);
755 //wxPyTimer::wxPyTimer(PyObject* callback) {
760 //wxPyTimer::~wxPyTimer() {
764 //void wxPyTimer::Notify() {
765 // wxPyEvtHandlers* peh= new wxPyEvtHandlers; // just for the helper methods
766 // peh->callFunc(func, Py_BuildValue("()"));
770 //----------------------------------------------------------------------
771 //----------------------------------------------------------------------
772 // Some helper functions for typemaps in my_typemaps.i, so they won't be
773 // imcluded in every file...
776 int* int_LIST_helper(PyObject
* source
) {
777 if (!PyList_Check(source
)) {
778 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
781 int count
= PyList_Size(source
);
782 int* temp
= new int[count
];
784 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
787 for (int x
=0; x
<count
; x
++) {
788 PyObject
* o
= PyList_GetItem(source
, x
);
789 if (! PyInt_Check(o
)) {
790 PyErr_SetString(PyExc_TypeError
, "Expected a list of integers.");
793 temp
[x
] = PyInt_AsLong(o
);
799 long* long_LIST_helper(PyObject
* source
) {
800 if (!PyList_Check(source
)) {
801 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
804 int count
= PyList_Size(source
);
805 long* temp
= new long[count
];
807 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
810 for (int x
=0; x
<count
; x
++) {
811 PyObject
* o
= PyList_GetItem(source
, x
);
812 if (! PyInt_Check(o
)) {
813 PyErr_SetString(PyExc_TypeError
, "Expected a list of integers.");
816 temp
[x
] = PyInt_AsLong(o
);
822 char** string_LIST_helper(PyObject
* source
) {
823 if (!PyList_Check(source
)) {
824 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
827 int count
= PyList_Size(source
);
828 char** temp
= new char*[count
];
830 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
833 for (int x
=0; x
<count
; x
++) {
834 PyObject
* o
= PyList_GetItem(source
, x
);
835 if (! PyString_Check(o
)) {
836 PyErr_SetString(PyExc_TypeError
, "Expected a list of strings.");
839 temp
[x
] = PyString_AsString(o
);
846 wxPoint
* wxPoint_LIST_helper(PyObject
* source
) {
847 if (!PyList_Check(source
)) {
848 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
851 int count
= PyList_Size(source
);
852 wxPoint
* temp
= new wxPoint
[count
];
854 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
857 for (int x
=0; x
<count
; x
++) {
858 PyObject
* o
= PyList_GetItem(source
, x
);
859 if (PyString_Check(o
)) {
860 char* st
= PyString_AsString(o
);
862 if (SWIG_GetPtr(st
,(void **) &pt
,"_wxPoint_p")) {
863 PyErr_SetString(PyExc_TypeError
,"Expected _wxPoint_p.");
868 else if (PyTuple_Check(o
)) {
869 PyObject
* o1
= PyTuple_GetItem(o
, 0);
870 PyObject
* o2
= PyTuple_GetItem(o
, 1);
872 temp
[x
].x
= PyInt_AsLong(o1
);
873 temp
[x
].y
= PyInt_AsLong(o2
);
876 PyErr_SetString(PyExc_TypeError
, "Expected a list of 2-tuples or wxPoints.");
884 wxBitmap
** wxBitmap_LIST_helper(PyObject
* source
) {
885 if (!PyList_Check(source
)) {
886 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
889 int count
= PyList_Size(source
);
890 wxBitmap
** temp
= new wxBitmap
*[count
];
892 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
895 for (int x
=0; x
<count
; x
++) {
896 PyObject
* o
= PyList_GetItem(source
, x
);
897 if (PyString_Check(o
)) {
898 char* st
= PyString_AsString(o
);
900 if (SWIG_GetPtr(st
,(void **) &pt
,"_wxBitmap_p")) {
901 PyErr_SetString(PyExc_TypeError
,"Expected _wxBitmap_p.");
907 PyErr_SetString(PyExc_TypeError
, "Expected a list of wxBitmaps.");
916 wxString
* wxString_LIST_helper(PyObject
* source
) {
917 if (!PyList_Check(source
)) {
918 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
921 int count
= PyList_Size(source
);
922 wxString
* temp
= new wxString
[count
];
924 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
927 for (int x
=0; x
<count
; x
++) {
928 PyObject
* o
= PyList_GetItem(source
, x
);
929 if (! PyString_Check(o
)) {
930 PyErr_SetString(PyExc_TypeError
, "Expected a list of strings.");
933 temp
[x
] = PyString_AsString(o
);
939 wxAcceleratorEntry
* wxAcceleratorEntry_LIST_helper(PyObject
* source
) {
940 if (!PyList_Check(source
)) {
941 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
944 int count
= PyList_Size(source
);
945 wxAcceleratorEntry
* temp
= new wxAcceleratorEntry
[count
];
947 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
950 for (int x
=0; x
<count
; x
++) {
951 PyObject
* o
= PyList_GetItem(source
, x
);
952 if (PyString_Check(o
)) {
953 char* st
= PyString_AsString(o
);
954 wxAcceleratorEntry
* ae
;
955 if (SWIG_GetPtr(st
,(void **) &ae
,"_wxAcceleratorEntry_p")) {
956 PyErr_SetString(PyExc_TypeError
,"Expected _wxAcceleratorEntry_p.");
961 else if (PyTuple_Check(o
)) {
962 PyObject
* o1
= PyTuple_GetItem(o
, 0);
963 PyObject
* o2
= PyTuple_GetItem(o
, 1);
964 PyObject
* o3
= PyTuple_GetItem(o
, 2);
966 temp
[x
].m_flags
= PyInt_AsLong(o1
);
967 temp
[x
].m_keyCode
= PyInt_AsLong(o2
);
968 temp
[x
].m_command
= PyInt_AsLong(o3
);
971 PyErr_SetString(PyExc_TypeError
, "Expected a list of 3-tuples or wxAcceleratorEntry objects.");
980 //----------------------------------------------------------------------
981 // A WinMain for when wxWindows and Python are linked together in a single
982 // application, instead of as a dynamic module
985 //#if !defined(WIN_PYD) && defined(WIN32)
987 //extern "C" int Py_Main(int argc, char** argv);
989 //int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR m_lpCmdLine,
995 // // Initialize wxWindows, but don't start the main loop
996 // wxEntry(hInstance, hPrevInstance, m_lpCmdLine, nCmdShow, FALSE);
999 // PyObject *argvList = PyList_New(0);
1001 // char* stderrfilename = "wxpstderr.log";
1003 // char* script = NULL;
1004 // int argc = wxPythonApp->argc;
1005 // char** argv = wxPythonApp->argv;
1007 // for (int i = 1; i < argc; i++) {
1008 // if (strncmp(argv[i], "wxpstderr=", 10) == 0)
1009 // stderrfilename = argv[i]+10;
1011 // PyList_Append(argvList, PyString_FromString(argv[i]));
1013 // script = argv[i];
1018 // PySys_SetObject("argv", argvList);
1022 //// //PyRun_SimpleString("import sys; sys.stdout=open('wxpstdout.log','w')");
1023 // sprintf(buf, "import sys; sys.stdout=sys.stderr=open('%s','w')", stderrfilename);
1024 // PyRun_SimpleString(buf);
1030 // FILE *fp = fopen(script, "r");
1032 // PyRun_SimpleFile(fp, script);// This returns after wxpApp constructor
1037 // sprintf(msg, "Cannot open %s", script);
1038 // wxMessageBox(msg);
1042 // PyRun_SimpleString("import wxpide");
1050 //----------------------------------------------------------------------
1052 /////////////////////////////////////////////////////////////////////////////
1055 // Revision 1.1 1998/08/09 08:25:51 RD