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();
104 wxTheApp
->argv
= NULL
;
106 gtk_init( &wxTheApp
->argc
, &wxTheApp
->argv
);
112 gtk_widget_push_visual(gdk_imlib_get_visual());
114 gtk_widget_push_colormap(gdk_imlib_get_colormap());
120 wxTheApp
->OnInitGui();
125 // Call the Python App's OnInit function
126 arglist
= PyTuple_New(0);
127 result
= PyEval_CallObject(onInitFunc
, arglist
);
133 if (! PyInt_Check(result
)) {
134 PyErr_SetString(PyExc_TypeError
, "OnInit should return a boolean value");
137 bResult
= PyInt_AS_LONG(result
);
139 wxPythonApp
->DeletePendingObjects();
140 wxPythonApp
->OnExit();
145 wxApp::CommonCleanUp();
147 PyErr_SetString(PyExc_SystemExit
, "OnInit returned false, exiting...");
156 //PyObject* __wxMainLoop(PyObject* /* self */, PyObject* /* args */)
158 // wxPythonApp->MainLoop();
159 // if (wxPythonApp->wx_frame) {
160 // wxPythonApp->wx_frame->GetEventHandler()->OnClose();
161 // delete wxPythonApp->wx_frame;
165 // Py_INCREF(Py_None);
170 //PyObject* __wxExitMainLoop(PyObject* /* self */, PyObject* /* args */)
172 // wxPythonApp->ExitMainLoop();
173 // Py_INCREF(Py_None);
179 //PyObject* __wxAddCallback(PyObject* /* self */, PyObject* args)
183 // PyObject* callback;
185 // wxPyEvtHandlers* evtHdlr;
187 // if (!PyArg_ParseTuple(args, "ssO", &swigPtr, &name, &callback))
190 // if (!PyCallable_Check(callback)) {
191 // PyErr_SetString(PyExc_TypeError, "Expected a callable object.");
195 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
196 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
200 // evtHdlr = (wxPyEvtHandlers*)win->GetClientData();
201 // if (! evtHdlr->addCallback(name, callback)) {
202 // PyErr_SetString(PyExc_TypeError, "Unknown callback name.");
206 // Py_INCREF(Py_None);
212 //PyObject* __wxSetWinEvtHdlr(PyObject* /* self */, PyObject* args)
216 // wxPyEvtHandlers* evtHdlr;
218 // if (!PyArg_ParseTuple(args, "s", &swigPtr))
221 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
222 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
226 // evtHdlr = new wxPyEvtHandlers;
227 // win->SetClientData((char*)evtHdlr);
229 // Py_INCREF(Py_None);
235 //PyObject* __wxDelWinEvtHdlr(PyObject* /* self */, PyObject* args)
239 // wxPyEvtHandlers* evtHdlr;
241 // if (!PyArg_ParseTuple(args, "s", &swigPtr))
244 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
245 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
249 // evtHdlr = (wxPyEvtHandlers*)win->GetClientData();
250 // printf("__wxDelWinEvtHdlr: %p\n", evtHdlr);
253 // Py_INCREF(Py_None);
259 PyObject
* wxPython_dict
;
260 PyObject
* __wxSetDictionary(PyObject
* /* self */, PyObject
* args
)
263 if (!PyArg_ParseTuple(args
, "O", &wxPython_dict
))
266 if (!PyDict_Check(wxPython_dict
)) {
267 PyErr_SetString(PyExc_TypeError
, "_wxSetDictionary must have dictionary object!");
271 #define wxPlatform "__MOTIF__"
274 #define wxPlatform "__GTK__"
276 #if defined(__WIN32__) || defined(__WXMSW__)
277 #define wxPlatform "__WIN32__"
280 #define wxPlatform "__MAC__"
283 PyDict_SetItemString(wxPython_dict
, "wxPlatform", PyString_FromString(wxPlatform
));
290 //---------------------------------------------------------------------------
294 PyObject
* wxPyConstructObject(void* ptr
, char* className
)
296 char buff
[64]; // should be big enough...
299 sprintf(buff
, "_%s_p", className
);
300 SWIG_MakePtr(swigptr
, ptr
, buff
);
302 sprintf(buff
, "%sPtr", className
);
303 PyObject
* classobj
= PyDict_GetItemString(wxPython_dict
, buff
);
309 PyObject
* arg
= Py_BuildValue("(s)", swigptr
);
310 PyObject
* obj
= PyInstance_New(classobj
, arg
, NULL
);
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
;
325 arg
= wxPyConstructObject((void*)&event
, event
.GetClassInfo()->GetClassName());
327 tuple
= PyTuple_New(1);
328 PyTuple_SET_ITEM(tuple
, 0, arg
);
329 result
= PyEval_CallObject(func
, tuple
);
341 //---------------------------------------------------------------------------
344 wxPyMenu::wxPyMenu(const wxString
& title
, PyObject
* _func
)
345 : wxMenu(title
, (wxFunction
)(func
? MenuCallback
: NULL
)), func(0) {
353 wxPyMenu::~wxPyMenu() {
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
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
);
378 //---------------------------------------------------------------------------
380 wxPyTimer::wxPyTimer(PyObject
* callback
) {
385 wxPyTimer::~wxPyTimer() {
389 void wxPyTimer::Notify() {
391 PyObject
* args
= Py_BuildValue("()");
393 result
= PyEval_CallObject(func
, args
);
405 //----------------------------------------------------------------------
406 // wxPyEvtHandlers class
407 //----------------------------------------------------------------------
409 //wxPyEvtHandlers::wxPyEvtHandlers()
410 // : pyOnActivate(0),
416 // pyOnDefaultAction(0),
418 // pyOnInitMenuPopup(0),
420 // pyOnMenuCommand(0),
421 // pyOnMenuSelect(0),
427 // pyOnSysColourChange(0),
429 // pyOnMouseEnter(0),
430 // pyOnRightClick(0),
431 // pyOnDoubleClickSash(0),
437 //wxPyEvtHandlers::~wxPyEvtHandlers()
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);
463 // wxNode* node = cleanupList.First();
465 // delete (wxPyEvtHandlers*)node->Data();
467 // node = cleanupList.First();
470 // node = decrefList.First();
472 // PyObject* obj = (PyObject*)node->Data();
475 // node = decrefList.First();
477 //// printf("~wxPyEvtHandlers: %p\n", this);
480 ////----------------------------------------------------------------------
482 //Bool wxPyEvtHandlers::addCallback(char* name, PyObject* callback)
484 // Py_INCREF(callback);
486 // if (strcmp(name, "OnActivate") == 0) {
487 // pyOnActivate = callback;
490 // if (strcmp(name, "OnChar") == 0) {
491 // pyOnChar = callback;
494 // if (strcmp(name, "OnCharHook") == 0) {
495 // pyOnCharHook = callback;
498 // if (strcmp(name, "OnClose") == 0) {
499 // pyOnClose = callback;
502 // if (strcmp(name, "OnCommand") == 0) {
503 // pyOnCommand = callback;
506 // if (strcmp(name, "OnDropFiles") == 0) {
507 // pyOnDropFiles = callback;
510 // if (strcmp(name, "OnDefaultAction") == 0) {
511 // pyOnDefaultAction = callback;
514 // if (strcmp(name, "OnEvent") == 0) {
515 // pyOnEvent = callback;
518 // if (strcmp(name, "OnInitMenuPopup") == 0) {
519 // pyOnInitMenuPopup = callback;
522 // if (strcmp(name, "OnKillFocus") == 0) {
523 // pyOnKillFocus = callback;
526 // if (strcmp(name, "OnMenuCommand") == 0) {
527 // pyOnMenuCommand = callback;
530 // if (strcmp(name, "OnMenuSelect") == 0) {
531 // pyOnMenuSelect = callback;
534 // if (strcmp(name, "OnMove") == 0) {
535 // pyOnMove = callback;
538 // if (strcmp(name, "OnPaint") == 0) {
539 // pyOnPaint = callback;
542 // if (strcmp(name, "OnScroll") == 0) {
543 // pyOnScroll = callback;
546 // if (strcmp(name, "OnSetFocus") == 0) {
547 // pyOnSetFocus = callback;
550 // if (strcmp(name, "OnSize") == 0) {
551 // pyOnSize = callback;
554 // if (strcmp(name, "OnSysColourChange") == 0) {
555 // pyOnSysColourChange = callback;
558 // if (strcmp(name, "OnLeftClick") == 0) {
559 // pyOnLeftClick = callback;
562 // if (strcmp(name, "OnMouseEnter") == 0) {
563 // pyOnMouseEnter = callback;
566 // if (strcmp(name, "OnRightClick") == 0) {
567 // pyOnRightClick = callback;
570 // if (strcmp(name, "OnDoubleClickSash") == 0) {
571 // pyOnDoubleClickSash = callback;
574 // if (strcmp(name, "OnUnsplit") == 0) {
575 // pyOnUnsplit = callback;
579 // // If we get here, there was no match.
580 // Py_DECREF(callback);
585 ////----------------------------------------------------------------------
586 //// Helpers to assist in calling the python callable objects
587 ////----------------------------------------------------------------------
589 //PyObject* wxPyEvtHandlers::constructObject(void* ptr, char* className)
591 // char buff[64]; // should be big enough...
594 // sprintf(buff, "_%s_p", className);
595 // SWIG_MakePtr(swigptr, ptr, buff);
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);
608 //int wxPyEvtHandlers::callFunc(PyObject* func, PyObject* arglist)
611 // int retval = FALSE;
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...
625 ////---------------------------------------------------------------------------
626 //// Methods and helpers of the wxPy* classes
627 ////---------------------------------------------------------------------------
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);
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);
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);
651 //IMP_OnChar(wxTextWindow, wxPyTextWindow);
652 //IMP_OnDropFiles(wxTextWindow, wxPyTextWindow);
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);
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);
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);
685 //IMP_OnDoubleClickSash(wxSplitterWindow, wxPySplitterWindow);
686 //IMP_OnUnsplit(wxSplitterWindow, wxPySplitterWindow);
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));
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);
702 //// return wxToolBar::OnLeftClick(a,b);
704 //Bool wxPyToolBar::baseclass_OnLeftClick(int a, int b) {
705 // return wxToolBar::OnLeftClick(a,b);
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));
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);
721 //Bool wxPyButtonBar::baseclass_OnLeftClick(int a, int b) {
722 // return wxButtonBar::OnLeftClick(a,b);
727 //wxPyMenu::wxPyMenu(PyObject* _func)
728 // : wxMenu(NULL, (wxFunction)(func ? MenuCallback : NULL)), func(0) {
736 //wxPyMenu::~wxPyMenu() {
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
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);
762 //wxPyTimer::wxPyTimer(PyObject* callback) {
767 //wxPyTimer::~wxPyTimer() {
771 //void wxPyTimer::Notify() {
772 // wxPyEvtHandlers* peh= new wxPyEvtHandlers; // just for the helper methods
773 // peh->callFunc(func, Py_BuildValue("()"));
777 //----------------------------------------------------------------------
778 //----------------------------------------------------------------------
779 // Some helper functions for typemaps in my_typemaps.i, so they won't be
780 // imcluded in every file...
783 int* int_LIST_helper(PyObject
* source
) {
784 if (!PyList_Check(source
)) {
785 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
788 int count
= PyList_Size(source
);
789 int* temp
= new int[count
];
791 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
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.");
800 temp
[x
] = PyInt_AsLong(o
);
806 long* long_LIST_helper(PyObject
* source
) {
807 if (!PyList_Check(source
)) {
808 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
811 int count
= PyList_Size(source
);
812 long* temp
= new long[count
];
814 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
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.");
823 temp
[x
] = PyInt_AsLong(o
);
829 char** string_LIST_helper(PyObject
* source
) {
830 if (!PyList_Check(source
)) {
831 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
834 int count
= PyList_Size(source
);
835 char** temp
= new char*[count
];
837 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
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.");
846 temp
[x
] = PyString_AsString(o
);
853 wxPoint
* wxPoint_LIST_helper(PyObject
* source
) {
854 if (!PyList_Check(source
)) {
855 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
858 int count
= PyList_Size(source
);
859 wxPoint
* temp
= new wxPoint
[count
];
861 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
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
);
869 if (SWIG_GetPtr(st
,(void **) &pt
,"_wxPoint_p")) {
870 PyErr_SetString(PyExc_TypeError
,"Expected _wxPoint_p.");
875 else if (PyTuple_Check(o
)) {
876 PyObject
* o1
= PyTuple_GetItem(o
, 0);
877 PyObject
* o2
= PyTuple_GetItem(o
, 1);
879 temp
[x
].x
= PyInt_AsLong(o1
);
880 temp
[x
].y
= PyInt_AsLong(o2
);
883 PyErr_SetString(PyExc_TypeError
, "Expected a list of 2-tuples or wxPoints.");
891 wxBitmap
** wxBitmap_LIST_helper(PyObject
* source
) {
892 if (!PyList_Check(source
)) {
893 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
896 int count
= PyList_Size(source
);
897 wxBitmap
** temp
= new wxBitmap
*[count
];
899 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
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
);
907 if (SWIG_GetPtr(st
,(void **) &pt
,"_wxBitmap_p")) {
908 PyErr_SetString(PyExc_TypeError
,"Expected _wxBitmap_p.");
914 PyErr_SetString(PyExc_TypeError
, "Expected a list of wxBitmaps.");
923 wxString
* wxString_LIST_helper(PyObject
* source
) {
924 if (!PyList_Check(source
)) {
925 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
928 int count
= PyList_Size(source
);
929 wxString
* temp
= new wxString
[count
];
931 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
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.");
940 temp
[x
] = PyString_AsString(o
);
947 wxAcceleratorEntry
* wxAcceleratorEntry_LIST_helper(PyObject
* source
) {
948 if (!PyList_Check(source
)) {
949 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
952 int count
= PyList_Size(source
);
953 wxAcceleratorEntry
* temp
= new wxAcceleratorEntry
[count
];
955 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
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.");
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);
974 temp
[x
].m_flags
= PyInt_AsLong(o1
);
975 temp
[x
].m_keyCode
= PyInt_AsLong(o2
);
976 temp
[x
].m_command
= PyInt_AsLong(o3
);
979 PyErr_SetString(PyExc_TypeError
, "Expected a list of 3-tuples or wxAcceleratorEntry objects.");
988 //----------------------------------------------------------------------
989 // A WinMain for when wxWindows and Python are linked together in a single
990 // application, instead of as a dynamic module
993 //#if !defined(WIN_PYD) && defined(WIN32)
995 //extern "C" int Py_Main(int argc, char** argv);
997 //int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR m_lpCmdLine,
1003 // // Initialize wxWindows, but don't start the main loop
1004 // wxEntry(hInstance, hPrevInstance, m_lpCmdLine, nCmdShow, FALSE);
1007 // PyObject *argvList = PyList_New(0);
1009 // char* stderrfilename = "wxpstderr.log";
1011 // char* script = NULL;
1012 // int argc = wxPythonApp->argc;
1013 // char** argv = wxPythonApp->argv;
1015 // for (int i = 1; i < argc; i++) {
1016 // if (strncmp(argv[i], "wxpstderr=", 10) == 0)
1017 // stderrfilename = argv[i]+10;
1019 // PyList_Append(argvList, PyString_FromString(argv[i]));
1021 // script = argv[i];
1026 // PySys_SetObject("argv", argvList);
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);
1038 // FILE *fp = fopen(script, "r");
1040 // PyRun_SimpleFile(fp, script);// This returns after wxpApp constructor
1045 // sprintf(msg, "Cannot open %s", script);
1046 // wxMessageBox(msg);
1050 // PyRun_SimpleString("import wxpide");
1058 //----------------------------------------------------------------------
1060 /////////////////////////////////////////////////////////////////////////////
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.
1068 // - A few minor fixes.
1070 // Revision 1.2 1998/08/14 23:36:36 RD
1071 // Beginings of wxGTK compatibility
1073 // Revision 1.1 1998/08/09 08:25:51 RD