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...");
161 wxTheApp
->m_initialized
= (wxTopLevelWindows
.Number() > 0);
168 //PyObject* __wxMainLoop(PyObject* /* self */, PyObject* /* args */)
170 // wxPythonApp->MainLoop();
171 // if (wxPythonApp->wx_frame) {
172 // wxPythonApp->wx_frame->GetEventHandler()->OnClose();
173 // delete wxPythonApp->wx_frame;
177 // Py_INCREF(Py_None);
182 //PyObject* __wxExitMainLoop(PyObject* /* self */, PyObject* /* args */)
184 // wxPythonApp->ExitMainLoop();
185 // Py_INCREF(Py_None);
191 //PyObject* __wxAddCallback(PyObject* /* self */, PyObject* args)
195 // PyObject* callback;
197 // wxPyEvtHandlers* evtHdlr;
199 // if (!PyArg_ParseTuple(args, "ssO", &swigPtr, &name, &callback))
202 // if (!PyCallable_Check(callback)) {
203 // PyErr_SetString(PyExc_TypeError, "Expected a callable object.");
207 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
208 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
212 // evtHdlr = (wxPyEvtHandlers*)win->GetClientData();
213 // if (! evtHdlr->addCallback(name, callback)) {
214 // PyErr_SetString(PyExc_TypeError, "Unknown callback name.");
218 // Py_INCREF(Py_None);
224 //PyObject* __wxSetWinEvtHdlr(PyObject* /* self */, PyObject* args)
228 // wxPyEvtHandlers* evtHdlr;
230 // if (!PyArg_ParseTuple(args, "s", &swigPtr))
233 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
234 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
238 // evtHdlr = new wxPyEvtHandlers;
239 // win->SetClientData((char*)evtHdlr);
241 // Py_INCREF(Py_None);
247 //PyObject* __wxDelWinEvtHdlr(PyObject* /* self */, PyObject* args)
251 // wxPyEvtHandlers* evtHdlr;
253 // if (!PyArg_ParseTuple(args, "s", &swigPtr))
256 // if (SWIG_GetPtr(swigPtr, (void **)&win, "_wxWindow_p")) {
257 // PyErr_SetString(PyExc_TypeError, "Expected class derived from wxWindow.");
261 // evtHdlr = (wxPyEvtHandlers*)win->GetClientData();
262 // printf("__wxDelWinEvtHdlr: %p\n", evtHdlr);
265 // Py_INCREF(Py_None);
271 PyObject
* wxPython_dict
;
272 PyObject
* __wxSetDictionary(PyObject
* /* self */, PyObject
* args
)
275 if (!PyArg_ParseTuple(args
, "O", &wxPython_dict
))
278 if (!PyDict_Check(wxPython_dict
)) {
279 PyErr_SetString(PyExc_TypeError
, "_wxSetDictionary must have dictionary object!");
283 #define wxPlatform "__MOTIF__"
286 #define wxPlatform "__GTK__"
288 #if defined(__WIN32__) || defined(__WXMSW__)
289 #define wxPlatform "__WXMSW__"
292 #define wxPlatform "__MAC__"
295 PyDict_SetItemString(wxPython_dict
, "wxPlatform", PyString_FromString(wxPlatform
));
302 //---------------------------------------------------------------------------
306 PyObject
* wxPyConstructObject(void* ptr
, char* className
)
308 char buff
[64]; // should be big enough...
311 sprintf(buff
, "_%s_p", className
);
312 SWIG_MakePtr(swigptr
, ptr
, buff
);
314 sprintf(buff
, "%sPtr", className
);
315 PyObject
* classobj
= PyDict_GetItemString(wxPython_dict
, buff
);
321 PyObject
* arg
= Py_BuildValue("(s)", swigptr
);
322 PyObject
* obj
= PyInstance_New(classobj
, arg
, NULL
);
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
;
337 arg
= wxPyConstructObject((void*)&event
, event
.GetClassInfo()->GetClassName());
339 tuple
= PyTuple_New(1);
340 PyTuple_SET_ITEM(tuple
, 0, arg
);
341 result
= PyEval_CallObject(func
, tuple
);
353 //---------------------------------------------------------------------------
355 wxPyMenu::wxPyMenu(const wxString
& title
, PyObject
* _func
)
356 : wxMenu(title
, (wxFunction
)(func
? MenuCallback
: NULL
)), func(0) {
364 wxPyMenu::~wxPyMenu() {
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
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
);
389 //---------------------------------------------------------------------------
391 wxPyTimer::wxPyTimer(PyObject
* callback
) {
396 wxPyTimer::~wxPyTimer() {
400 void wxPyTimer::Notify() {
402 PyObject
* args
= Py_BuildValue("()");
404 result
= PyEval_CallObject(func
, args
);
416 //----------------------------------------------------------------------
417 // wxPyEvtHandlers class
418 //----------------------------------------------------------------------
420 //wxPyEvtHandlers::wxPyEvtHandlers()
421 // : pyOnActivate(0),
427 // pyOnDefaultAction(0),
429 // pyOnInitMenuPopup(0),
431 // pyOnMenuCommand(0),
432 // pyOnMenuSelect(0),
438 // pyOnSysColourChange(0),
440 // pyOnMouseEnter(0),
441 // pyOnRightClick(0),
442 // pyOnDoubleClickSash(0),
448 //wxPyEvtHandlers::~wxPyEvtHandlers()
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);
474 // wxNode* node = cleanupList.First();
476 // delete (wxPyEvtHandlers*)node->Data();
478 // node = cleanupList.First();
481 // node = decrefList.First();
483 // PyObject* obj = (PyObject*)node->Data();
486 // node = decrefList.First();
488 //// printf("~wxPyEvtHandlers: %p\n", this);
491 ////----------------------------------------------------------------------
493 //Bool wxPyEvtHandlers::addCallback(char* name, PyObject* callback)
495 // Py_INCREF(callback);
497 // if (strcmp(name, "OnActivate") == 0) {
498 // pyOnActivate = callback;
501 // if (strcmp(name, "OnChar") == 0) {
502 // pyOnChar = callback;
505 // if (strcmp(name, "OnCharHook") == 0) {
506 // pyOnCharHook = callback;
509 // if (strcmp(name, "OnClose") == 0) {
510 // pyOnClose = callback;
513 // if (strcmp(name, "OnCommand") == 0) {
514 // pyOnCommand = callback;
517 // if (strcmp(name, "OnDropFiles") == 0) {
518 // pyOnDropFiles = callback;
521 // if (strcmp(name, "OnDefaultAction") == 0) {
522 // pyOnDefaultAction = callback;
525 // if (strcmp(name, "OnEvent") == 0) {
526 // pyOnEvent = callback;
529 // if (strcmp(name, "OnInitMenuPopup") == 0) {
530 // pyOnInitMenuPopup = callback;
533 // if (strcmp(name, "OnKillFocus") == 0) {
534 // pyOnKillFocus = callback;
537 // if (strcmp(name, "OnMenuCommand") == 0) {
538 // pyOnMenuCommand = callback;
541 // if (strcmp(name, "OnMenuSelect") == 0) {
542 // pyOnMenuSelect = callback;
545 // if (strcmp(name, "OnMove") == 0) {
546 // pyOnMove = callback;
549 // if (strcmp(name, "OnPaint") == 0) {
550 // pyOnPaint = callback;
553 // if (strcmp(name, "OnScroll") == 0) {
554 // pyOnScroll = callback;
557 // if (strcmp(name, "OnSetFocus") == 0) {
558 // pyOnSetFocus = callback;
561 // if (strcmp(name, "OnSize") == 0) {
562 // pyOnSize = callback;
565 // if (strcmp(name, "OnSysColourChange") == 0) {
566 // pyOnSysColourChange = callback;
569 // if (strcmp(name, "OnLeftClick") == 0) {
570 // pyOnLeftClick = callback;
573 // if (strcmp(name, "OnMouseEnter") == 0) {
574 // pyOnMouseEnter = callback;
577 // if (strcmp(name, "OnRightClick") == 0) {
578 // pyOnRightClick = callback;
581 // if (strcmp(name, "OnDoubleClickSash") == 0) {
582 // pyOnDoubleClickSash = callback;
585 // if (strcmp(name, "OnUnsplit") == 0) {
586 // pyOnUnsplit = callback;
590 // // If we get here, there was no match.
591 // Py_DECREF(callback);
596 ////----------------------------------------------------------------------
597 //// Helpers to assist in calling the python callable objects
598 ////----------------------------------------------------------------------
600 //PyObject* wxPyEvtHandlers::constructObject(void* ptr, char* className)
602 // char buff[64]; // should be big enough...
605 // sprintf(buff, "_%s_p", className);
606 // SWIG_MakePtr(swigptr, ptr, buff);
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);
619 //int wxPyEvtHandlers::callFunc(PyObject* func, PyObject* arglist)
622 // int retval = FALSE;
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...
636 ////---------------------------------------------------------------------------
637 //// Methods and helpers of the wxPy* classes
638 ////---------------------------------------------------------------------------
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);
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);
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);
662 //IMP_OnChar(wxTextWindow, wxPyTextWindow);
663 //IMP_OnDropFiles(wxTextWindow, wxPyTextWindow);
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);
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);
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);
696 //IMP_OnDoubleClickSash(wxSplitterWindow, wxPySplitterWindow);
697 //IMP_OnUnsplit(wxSplitterWindow, wxPySplitterWindow);
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));
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);
713 //// return wxToolBar::OnLeftClick(a,b);
715 //Bool wxPyToolBar::baseclass_OnLeftClick(int a, int b) {
716 // return wxToolBar::OnLeftClick(a,b);
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));
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);
732 //Bool wxPyButtonBar::baseclass_OnLeftClick(int a, int b) {
733 // return wxButtonBar::OnLeftClick(a,b);
738 //wxPyMenu::wxPyMenu(PyObject* _func)
739 // : wxMenu(NULL, (wxFunction)(func ? MenuCallback : NULL)), func(0) {
747 //wxPyMenu::~wxPyMenu() {
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
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);
773 //wxPyTimer::wxPyTimer(PyObject* callback) {
778 //wxPyTimer::~wxPyTimer() {
782 //void wxPyTimer::Notify() {
783 // wxPyEvtHandlers* peh= new wxPyEvtHandlers; // just for the helper methods
784 // peh->callFunc(func, Py_BuildValue("()"));
788 //----------------------------------------------------------------------
789 //----------------------------------------------------------------------
790 // Some helper functions for typemaps in my_typemaps.i, so they won't be
791 // imcluded in every file...
794 int* int_LIST_helper(PyObject
* source
) {
795 if (!PyList_Check(source
)) {
796 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
799 int count
= PyList_Size(source
);
800 int* temp
= new int[count
];
802 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
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.");
811 temp
[x
] = PyInt_AsLong(o
);
817 long* long_LIST_helper(PyObject
* source
) {
818 if (!PyList_Check(source
)) {
819 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
822 int count
= PyList_Size(source
);
823 long* temp
= new long[count
];
825 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
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.");
834 temp
[x
] = PyInt_AsLong(o
);
840 char** string_LIST_helper(PyObject
* source
) {
841 if (!PyList_Check(source
)) {
842 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
845 int count
= PyList_Size(source
);
846 char** temp
= new char*[count
];
848 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
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.");
857 temp
[x
] = PyString_AsString(o
);
864 wxPoint
* wxPoint_LIST_helper(PyObject
* source
) {
865 if (!PyList_Check(source
)) {
866 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
869 int count
= PyList_Size(source
);
870 wxPoint
* temp
= new wxPoint
[count
];
872 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
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
);
880 if (SWIG_GetPtr(st
,(void **) &pt
,"_wxPoint_p")) {
881 PyErr_SetString(PyExc_TypeError
,"Expected _wxPoint_p.");
886 else if (PyTuple_Check(o
)) {
887 PyObject
* o1
= PyTuple_GetItem(o
, 0);
888 PyObject
* o2
= PyTuple_GetItem(o
, 1);
890 temp
[x
].x
= PyInt_AsLong(o1
);
891 temp
[x
].y
= PyInt_AsLong(o2
);
894 PyErr_SetString(PyExc_TypeError
, "Expected a list of 2-tuples or wxPoints.");
902 wxBitmap
** wxBitmap_LIST_helper(PyObject
* source
) {
903 if (!PyList_Check(source
)) {
904 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
907 int count
= PyList_Size(source
);
908 wxBitmap
** temp
= new wxBitmap
*[count
];
910 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
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
);
918 if (SWIG_GetPtr(st
,(void **) &pt
,"_wxBitmap_p")) {
919 PyErr_SetString(PyExc_TypeError
,"Expected _wxBitmap_p.");
925 PyErr_SetString(PyExc_TypeError
, "Expected a list of wxBitmaps.");
934 wxString
* wxString_LIST_helper(PyObject
* source
) {
935 if (!PyList_Check(source
)) {
936 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
939 int count
= PyList_Size(source
);
940 wxString
* temp
= new wxString
[count
];
942 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
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.");
951 temp
[x
] = PyString_AsString(o
);
958 wxAcceleratorEntry
* wxAcceleratorEntry_LIST_helper(PyObject
* source
) {
959 if (!PyList_Check(source
)) {
960 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
963 int count
= PyList_Size(source
);
964 wxAcceleratorEntry
* temp
= new wxAcceleratorEntry
[count
];
966 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
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.");
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);
985 temp
[x
].m_flags
= PyInt_AsLong(o1
);
986 temp
[x
].m_keyCode
= PyInt_AsLong(o2
);
987 temp
[x
].m_command
= PyInt_AsLong(o3
);
990 PyErr_SetString(PyExc_TypeError
, "Expected a list of 3-tuples or wxAcceleratorEntry objects.");
999 //----------------------------------------------------------------------
1000 // A WinMain for when wxWindows and Python are linked together in a single
1001 // application, instead of as a dynamic module
1004 //#if !defined(WIN_PYD) && defined(WIN32)
1006 //extern "C" int Py_Main(int argc, char** argv);
1008 //int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR m_lpCmdLine,
1014 // // Initialize wxWindows, but don't start the main loop
1015 // wxEntry(hInstance, hPrevInstance, m_lpCmdLine, nCmdShow, FALSE);
1018 // PyObject *argvList = PyList_New(0);
1020 // char* stderrfilename = "wxpstderr.log";
1022 // char* script = NULL;
1023 // int argc = wxPythonApp->argc;
1024 // char** argv = wxPythonApp->argv;
1026 // for (int i = 1; i < argc; i++) {
1027 // if (strncmp(argv[i], "wxpstderr=", 10) == 0)
1028 // stderrfilename = argv[i]+10;
1030 // PyList_Append(argvList, PyString_FromString(argv[i]));
1032 // script = argv[i];
1037 // PySys_SetObject("argv", argvList);
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);
1049 // FILE *fp = fopen(script, "r");
1051 // PyRun_SimpleFile(fp, script);// This returns after wxpApp constructor
1056 // sprintf(msg, "Cannot open %s", script);
1057 // wxMessageBox(msg);
1061 // PyRun_SimpleString("import wxpide");
1069 //----------------------------------------------------------------------
1071 /////////////////////////////////////////////////////////////////////////////
1074 // Revision 1.5 1998/08/18 19:48:17 RD
1075 // more wxGTK compatibility things.
1077 // It builds now but there are serious runtime problems...
1079 // Revision 1.4 1998/08/16 04:31:06 RD
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.
1087 // - A few minor fixes.
1089 // Revision 1.2 1998/08/14 23:36:36 RD
1090 // Beginings of wxGTK compatibility
1092 // Revision 1.1 1998/08/09 08:25:51 RD