1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Helper functions/classes for the wxPython extension module
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
13 #include <stdio.h> // get the correct definition of NULL
20 #include <wx/msw/private.h>
23 #undef LoadAccelerators
30 #include <gdk/gdkprivate.h>
31 #include <wx/gtk/win_gtk.h>
32 //#include <gdk/gdk.h>
33 //#include <gdk/gdkx.h>
34 //#include <gtk/gtkwindow.h>
36 //extern GtkWidget *wxRootWindow;
41 //---------------------------------------------------------------------------
43 //wxHashTable* wxPyWindows = NULL;
46 wxPoint wxPyDefaultPosition
; //wxDefaultPosition);
47 wxSize wxPyDefaultSize
; //wxDefaultSize);
48 wxString
wxPyEmptyStr("");
52 #ifdef __WXMSW__ // If building for win32...
53 //----------------------------------------------------------------------
54 // This gets run when the DLL is loaded. We just need to save a handle.
55 //----------------------------------------------------------------------
58 HINSTANCE hinstDLL
, // handle to DLL module
59 DWORD fdwReason
, // reason for calling function
60 LPVOID lpvReserved
// reserved
63 wxSetInstance(hinstDLL
);
68 //----------------------------------------------------------------------
69 // Class for implementing the wxp main application shell.
70 //----------------------------------------------------------------------
72 wxPyApp
*wxPythonApp
= NULL
; // Global instance of application object
76 // printf("**** ctor\n");
80 // printf("**** dtor\n");
84 // This one isn't acutally called... See __wxStart()
85 bool wxPyApp::OnInit(void) {
89 int wxPyApp::MainLoop(void) {
92 DeletePendingObjects();
94 m_initialized
= wxTopLevelWindows
.GetCount() != 0;
98 retval
= wxApp::MainLoop();
99 wxPythonApp
->OnExit();
105 //---------------------------------------------------------------------
106 //----------------------------------------------------------------------
109 #include "wx/msw/msvcrt.h"
113 int WXDLLEXPORT
wxEntryStart( int argc
, char** argv
);
114 int WXDLLEXPORT
wxEntryInitGui();
115 void WXDLLEXPORT
wxEntryCleanup();
118 #ifdef WXP_WITH_THREAD
119 PyThreadState
* wxPyEventThreadState
= NULL
;
121 static char* __nullArgv
[1] = { 0 };
124 // This is where we pick up the first part of the wxEntry functionality...
125 // The rest is in __wxStart and __wxCleanup. This function is called when
126 // wxcmodule is imported. (Before there is a wxApp object.)
131 // wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
134 #ifdef WXP_WITH_THREAD
135 PyEval_InitThreads();
136 wxPyEventThreadState
= PyThreadState_Get();
139 // Bail out if there is already windows created. This means that the
140 // toolkit has already been initialized, as in embedding wxPython in
141 // a C++ wxWindows app.
142 if (wxTopLevelWindows
.Number() > 0)
146 PyObject
* sysargv
= PySys_GetObject("argv");
147 int argc
= PyList_Size(sysargv
);
148 char** argv
= new char*[argc
+1];
150 for(x
=0; x
<argc
; x
++)
151 argv
[x
] = PyString_AsString(PyList_GetItem(sysargv
, x
));
154 wxEntryStart(argc
, argv
);
160 // Start the user application, user App's OnInit method is a parameter here
161 PyObject
* __wxStart(PyObject
* /* self */, PyObject
* args
)
163 PyObject
* onInitFunc
= NULL
;
168 if (!PyArg_ParseTuple(args
, "O", &onInitFunc
))
171 #if 0 // Try it out without this check, soo how it does...
172 if (wxTopLevelWindows
.Number() > 0) {
173 PyErr_SetString(PyExc_TypeError
, "Only 1 wxApp per process!");
178 // This is the next part of the wxEntry functionality...
179 PyObject
* sysargv
= PySys_GetObject("argv");
180 int argc
= PyList_Size(sysargv
);
181 char** argv
= new char*[argc
+1];
183 for(x
=0; x
<argc
; x
++)
184 argv
[x
] = copystring(PyString_AsString(PyList_GetItem(sysargv
, x
)));
187 wxPythonApp
->argc
= argc
;
188 wxPythonApp
->argv
= argv
;
192 // Call the Python App's OnInit function
193 arglist
= PyTuple_New(0);
194 result
= PyEval_CallObject(onInitFunc
, arglist
);
195 if (!result
) { // an exception was raised.
199 if (! PyInt_Check(result
)) {
200 PyErr_SetString(PyExc_TypeError
, "OnInit should return a boolean value");
203 bResult
= PyInt_AS_LONG(result
);
205 PyErr_SetString(PyExc_SystemExit
, "OnInit returned FALSE, exiting...");
210 wxTheApp
->m_initialized
= (wxTopLevelWindows
.GetCount() > 0);
223 PyObject
* wxPython_dict
;
224 PyObject
* __wxSetDictionary(PyObject
* /* self */, PyObject
* args
)
227 if (!PyArg_ParseTuple(args
, "O", &wxPython_dict
))
230 if (!PyDict_Check(wxPython_dict
)) {
231 PyErr_SetString(PyExc_TypeError
, "_wxSetDictionary must have dictionary object!");
235 #define wxPlatform "__WXMOTIF__"
238 #define wxPlatform "__WXQT__"
241 #define wxPlatform "__WXGTK__"
243 #if defined(__WIN32__) || defined(__WXMSW__)
244 #define wxPlatform "__WXMSW__"
247 #define wxPlatform "__WXMAC__"
250 PyDict_SetItemString(wxPython_dict
, "wxPlatform", PyString_FromString(wxPlatform
));
257 //---------------------------------------------------------------------------
259 PyObject
* wxPyConstructObject(void* ptr
,
260 const char* className
,
270 char buff
[64]; // should always be big enough...
273 sprintf(buff
, "_%s_p", className
);
274 SWIG_MakePtr(swigptr
, ptr
, buff
);
276 sprintf(buff
, "%sPtr", className
);
277 PyObject
* classobj
= PyDict_GetItemString(wxPython_dict
, buff
);
279 //Py_INCREF(Py_None);
283 "*** Unknown class name %s, tell Robin about it please ***",
285 obj
= PyString_FromString(temp
);
289 arg
= Py_BuildValue("(s)", swigptr
);
290 obj
= PyInstance_New(classobj
, arg
, NULL
);
294 PyObject
* one
= PyInt_FromLong(1);
295 PyObject_SetAttrString(obj
, "thisown", one
);
302 //---------------------------------------------------------------------------
304 static unsigned int _wxPyNestCount
= 0;
306 static PyThreadState
* myPyThreadState_Get() {
307 PyThreadState
* current
;
308 current
= PyThreadState_Swap(NULL
);
309 PyThreadState_Swap(current
);
314 HELPEREXPORT
bool wxPyRestoreThread() {
315 // NOTE: The Python API docs state that if a thread already has the
316 // interpreter lock and calls PyEval_RestoreThread again a deadlock
317 // occurs, so I put in this code as a guard condition since there are
318 // many possibilites for nested events and callbacks in wxPython. If
319 // The current thread is our thread, then we can assume that we
320 // already have the lock. (I hope!)
322 #ifdef WXP_WITH_THREAD
324 if (wxPyEventThreadState
!= myPyThreadState_Get()) {
325 PyEval_RestoreThread(wxPyEventThreadState
);
334 HELPEREXPORT
void wxPySaveThread(bool doSave
) {
335 #ifdef WXP_WITH_THREAD
337 wxPyEventThreadState
= PyEval_SaveThread();
343 //---------------------------------------------------------------------------
346 IMPLEMENT_ABSTRACT_CLASS(wxPyCallback
, wxObject
);
348 wxPyCallback::wxPyCallback(PyObject
* func
) {
353 wxPyCallback::wxPyCallback(const wxPyCallback
& other
) {
354 m_func
= other
.m_func
;
358 wxPyCallback::~wxPyCallback() {
359 bool doSave
= wxPyRestoreThread();
361 wxPySaveThread(doSave
);
366 // This function is used for all events destined for Python event handlers.
367 void wxPyCallback::EventThunker(wxEvent
& event
) {
368 wxPyCallback
* cb
= (wxPyCallback
*)event
.m_callbackUserData
;
369 PyObject
* func
= cb
->m_func
;
375 bool doSave
= wxPyRestoreThread();
376 wxString className
= event
.GetClassInfo()->GetClassName();
378 if (className
== "wxPyEvent")
379 arg
= ((wxPyEvent
*)&event
)->GetSelf();
380 else if (className
== "wxPyCommandEvent")
381 arg
= ((wxPyCommandEvent
*)&event
)->GetSelf();
383 arg
= wxPyConstructObject((void*)&event
, className
);
385 tuple
= PyTuple_New(1);
386 PyTuple_SET_ITEM(tuple
, 0, arg
);
387 result
= PyEval_CallObject(func
, tuple
);
395 wxPySaveThread(doSave
);
399 //----------------------------------------------------------------------
401 wxPyCallbackHelper::wxPyCallbackHelper() {
409 wxPyCallbackHelper::~wxPyCallbackHelper() {
410 bool doSave
= wxPyRestoreThread();
415 wxPySaveThread(doSave
);
418 wxPyCallbackHelper::wxPyCallbackHelper(const wxPyCallbackHelper
& other
) {
420 m_self
= other
.m_self
;
421 m_class
= other
.m_class
;
429 void wxPyCallbackHelper::setSelf(PyObject
* self
, PyObject
* klass
, int incref
) {
440 // If the object (m_self) has an attibute of the given name, and if that
441 // attribute is a method, and if that method's class is not from a base class,
442 // then we'll save a pointer to the method so callCallback can call it.
443 bool wxPyCallbackHelper::findCallback(const char* name
) const {
444 wxPyCallbackHelper
* self
= (wxPyCallbackHelper
*)this; // cast away const
445 self
->m_lastFound
= NULL
;
446 if (m_self
&& PyObject_HasAttrString(m_self
, (char*)name
)) {
448 method
= PyObject_GetAttrString(m_self
, (char*)name
);
450 if (PyMethod_Check(method
) &&
451 ((PyMethod_GET_CLASS(method
) == m_class
) ||
452 PyClass_IsSubclass(PyMethod_GET_CLASS(method
), m_class
))) {
454 self
->m_lastFound
= method
;
460 return m_lastFound
!= NULL
;
464 int wxPyCallbackHelper::callCallback(PyObject
* argTuple
) const {
468 result
= callCallbackObj(argTuple
);
469 if (result
) { // Assumes an integer return type...
470 retval
= PyInt_AsLong(result
);
472 PyErr_Clear(); // forget about it if it's not...
477 // Invoke the Python callable object, returning the raw PyObject return
478 // value. Caller should DECREF the return value and also call PyEval_SaveThread.
479 PyObject
* wxPyCallbackHelper::callCallbackObj(PyObject
* argTuple
) const {
480 wxPyCallbackHelper
* self
= (wxPyCallbackHelper
*)this; // cast away const
483 // Save a copy of the pointer in case the callback generates another
484 // callback. In that case m_lastFound will have a different value when
485 // it gets back here...
486 PyObject
* method
= m_lastFound
;
488 result
= PyEval_CallObject(method
, argTuple
);
499 //---------------------------------------------------------------------------
500 //---------------------------------------------------------------------------
501 // These classes can be derived from in Python and passed through the event
502 // system without losing anything. They do this by keeping a reference to
503 // themselves and some special case handling in wxPyCallback::EventThunker.
506 wxPyEvtSelfRef::wxPyEvtSelfRef() {
507 //m_self = Py_None; // **** We don't do normal ref counting to prevent
508 //Py_INCREF(m_self); // circular loops...
512 wxPyEvtSelfRef::~wxPyEvtSelfRef() {
513 bool doSave
= wxPyRestoreThread();
516 wxPySaveThread(doSave
);
519 void wxPyEvtSelfRef::SetSelf(PyObject
* self
, bool clone
) {
520 bool doSave
= wxPyRestoreThread();
528 wxPySaveThread(doSave
);
531 PyObject
* wxPyEvtSelfRef::GetSelf() const {
537 wxPyEvent::wxPyEvent(int id
)
541 wxPyEvent::~wxPyEvent() {
544 // This one is so the event object can be Cloned...
545 void wxPyEvent::CopyObject(wxObject
& dest
) const {
546 wxEvent::CopyObject(dest
);
547 ((wxPyEvent
*)&dest
)->SetSelf(m_self
, TRUE
);
551 IMPLEMENT_DYNAMIC_CLASS(wxPyEvent
, wxEvent
);
554 wxPyCommandEvent::wxPyCommandEvent(wxEventType commandType
, int id
)
555 : wxCommandEvent(commandType
, id
) {
558 wxPyCommandEvent::~wxPyCommandEvent() {
561 void wxPyCommandEvent::CopyObject(wxObject
& dest
) const {
562 wxCommandEvent::CopyObject(dest
);
563 ((wxPyCommandEvent
*)&dest
)->SetSelf(m_self
, TRUE
);
567 IMPLEMENT_DYNAMIC_CLASS(wxPyCommandEvent
, wxCommandEvent
);
571 //---------------------------------------------------------------------------
572 //---------------------------------------------------------------------------
575 wxPyTimer::wxPyTimer(PyObject
* callback
) {
580 wxPyTimer::~wxPyTimer() {
581 bool doSave
= wxPyRestoreThread();
583 wxPySaveThread(doSave
);
586 void wxPyTimer::Notify() {
587 if (!func
|| func
== Py_None
) {
591 bool doSave
= wxPyRestoreThread();
594 PyObject
* args
= Py_BuildValue("()");
596 result
= PyEval_CallObject(func
, args
);
605 wxPySaveThread(doSave
);
611 //---------------------------------------------------------------------------
612 //---------------------------------------------------------------------------
613 // Convert a wxList to a Python List
615 PyObject
* wxPy_ConvertList(wxListBase
* list
, const char* className
) {
619 wxNode
* node
= list
->First();
621 bool doSave
= wxPyRestoreThread();
622 pyList
= PyList_New(0);
624 wxObj
= node
->Data();
625 pyObj
= wxPyConstructObject(wxObj
, className
);
626 PyList_Append(pyList
, pyObj
);
629 wxPySaveThread(doSave
);
633 //----------------------------------------------------------------------
635 long wxPyGetWinHandle(wxWindow
* win
) {
637 return (long)win
->GetHandle();
640 // Find and return the actual X-Window.
642 if (win
->m_wxwindow
) {
643 GdkWindowPrivate
* bwin
= (GdkWindowPrivate
*)GTK_PIZZA(win
->m_wxwindow
)->bin_window
;
645 return (long)bwin
->xwindow
;
652 //----------------------------------------------------------------------
653 // Some helper functions for typemaps in my_typemaps.i, so they won't be
654 // included in every file...
657 byte
* byte_LIST_helper(PyObject
* source
) {
658 if (!PyList_Check(source
)) {
659 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
662 int count
= PyList_Size(source
);
663 byte
* temp
= new byte
[count
];
665 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
668 for (int x
=0; x
<count
; x
++) {
669 PyObject
* o
= PyList_GetItem(source
, x
);
670 if (! PyInt_Check(o
)) {
671 PyErr_SetString(PyExc_TypeError
, "Expected a list of integers.");
674 temp
[x
] = (byte
)PyInt_AsLong(o
);
680 int* int_LIST_helper(PyObject
* source
) {
681 if (!PyList_Check(source
)) {
682 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
685 int count
= PyList_Size(source
);
686 int* temp
= new int[count
];
688 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
691 for (int x
=0; x
<count
; x
++) {
692 PyObject
* o
= PyList_GetItem(source
, x
);
693 if (! PyInt_Check(o
)) {
694 PyErr_SetString(PyExc_TypeError
, "Expected a list of integers.");
697 temp
[x
] = PyInt_AsLong(o
);
703 long* long_LIST_helper(PyObject
* source
) {
704 if (!PyList_Check(source
)) {
705 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
708 int count
= PyList_Size(source
);
709 long* temp
= new long[count
];
711 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
714 for (int x
=0; x
<count
; x
++) {
715 PyObject
* o
= PyList_GetItem(source
, x
);
716 if (! PyInt_Check(o
)) {
717 PyErr_SetString(PyExc_TypeError
, "Expected a list of integers.");
720 temp
[x
] = PyInt_AsLong(o
);
726 char** string_LIST_helper(PyObject
* source
) {
727 if (!PyList_Check(source
)) {
728 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
731 int count
= PyList_Size(source
);
732 char** temp
= new char*[count
];
734 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
737 for (int x
=0; x
<count
; x
++) {
738 PyObject
* o
= PyList_GetItem(source
, x
);
739 if (! PyString_Check(o
)) {
740 PyErr_SetString(PyExc_TypeError
, "Expected a list of strings.");
743 temp
[x
] = PyString_AsString(o
);
750 wxPoint
* wxPoint_LIST_helper(PyObject
* source
) {
751 if (!PyList_Check(source
)) {
752 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
755 int count
= PyList_Size(source
);
756 wxPoint
* temp
= new wxPoint
[count
];
758 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
761 for (int x
=0; x
<count
; x
++) {
762 PyObject
* o
= PyList_GetItem(source
, x
);
763 if (PyTuple_Check(o
)) {
764 PyObject
* o1
= PyTuple_GetItem(o
, 0);
765 PyObject
* o2
= PyTuple_GetItem(o
, 1);
767 temp
[x
].x
= PyInt_AsLong(o1
);
768 temp
[x
].y
= PyInt_AsLong(o2
);
770 else if (PyInstance_Check(o
)) {
772 if (SWIG_GetPtrObj(o
,(void **) &pt
,"_wxPoint_p")) {
773 PyErr_SetString(PyExc_TypeError
,"Expected _wxPoint_p.");
779 PyErr_SetString(PyExc_TypeError
, "Expected a list of 2-tuples or wxPoints.");
787 wxBitmap
** wxBitmap_LIST_helper(PyObject
* source
) {
788 if (!PyList_Check(source
)) {
789 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
792 int count
= PyList_Size(source
);
793 wxBitmap
** temp
= new wxBitmap
*[count
];
795 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
798 for (int x
=0; x
<count
; x
++) {
799 PyObject
* o
= PyList_GetItem(source
, x
);
800 if (PyInstance_Check(o
)) {
802 if (SWIG_GetPtrObj(o
, (void **) &pt
,"_wxBitmap_p")) {
803 PyErr_SetString(PyExc_TypeError
,"Expected _wxBitmap_p.");
809 PyErr_SetString(PyExc_TypeError
, "Expected a list of wxBitmaps.");
818 wxString
* wxString_LIST_helper(PyObject
* source
) {
819 if (!PyList_Check(source
)) {
820 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
823 int count
= PyList_Size(source
);
824 wxString
* temp
= new wxString
[count
];
826 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
829 for (int x
=0; x
<count
; x
++) {
830 PyObject
* o
= PyList_GetItem(source
, x
);
831 if (! PyString_Check(o
)) {
832 PyErr_SetString(PyExc_TypeError
, "Expected a list of strings.");
835 temp
[x
] = PyString_AsString(o
);
841 wxAcceleratorEntry
* wxAcceleratorEntry_LIST_helper(PyObject
* source
) {
842 if (!PyList_Check(source
)) {
843 PyErr_SetString(PyExc_TypeError
, "Expected a list object.");
846 int count
= PyList_Size(source
);
847 wxAcceleratorEntry
* temp
= new wxAcceleratorEntry
[count
];
849 PyErr_SetString(PyExc_MemoryError
, "Unable to allocate temporary array");
852 for (int x
=0; x
<count
; x
++) {
853 PyObject
* o
= PyList_GetItem(source
, x
);
854 if (PyInstance_Check(o
)) {
855 wxAcceleratorEntry
* ae
;
856 if (SWIG_GetPtrObj(o
, (void **) &ae
,"_wxAcceleratorEntry_p")) {
857 PyErr_SetString(PyExc_TypeError
,"Expected _wxAcceleratorEntry_p.");
862 else if (PyTuple_Check(o
)) {
863 PyObject
* o1
= PyTuple_GetItem(o
, 0);
864 PyObject
* o2
= PyTuple_GetItem(o
, 1);
865 PyObject
* o3
= PyTuple_GetItem(o
, 2);
867 temp
[x
].m_flags
= PyInt_AsLong(o1
);
868 temp
[x
].m_keyCode
= PyInt_AsLong(o2
);
869 temp
[x
].m_command
= PyInt_AsLong(o3
);
872 PyErr_SetString(PyExc_TypeError
, "Expected a list of 3-tuples or wxAcceleratorEntry objects.");
881 //----------------------------------------------------------------------
883 bool wxSize_helper(PyObject
* source
, wxSize
** obj
) {
885 // If source is an object instance then it may already be the right type
886 if (PyInstance_Check(source
)) {
888 if (SWIG_GetPtrObj(source
, (void **)&ptr
, "_wxSize_p"))
893 // otherwise a 2-tuple of integers is expected
894 else if (PySequence_Check(source
) && PyObject_Length(source
) == 2) {
895 PyObject
* o1
= PySequence_GetItem(source
, 0);
896 PyObject
* o2
= PySequence_GetItem(source
, 1);
897 **obj
= wxSize(PyInt_AsLong(o1
), PyInt_AsLong(o2
));
902 PyErr_SetString(PyExc_TypeError
, "Expected a 2-tuple of integers or a wxSize object.");
906 bool wxPoint_helper(PyObject
* source
, wxPoint
** obj
) {
908 // If source is an object instance then it may already be the right type
909 if (PyInstance_Check(source
)) {
911 if (SWIG_GetPtrObj(source
, (void **)&ptr
, "_wxPoint_p"))
916 // otherwise a 2-tuple of integers is expected
917 else if (PySequence_Check(source
) && PyObject_Length(source
) == 2) {
918 PyObject
* o1
= PySequence_GetItem(source
, 0);
919 PyObject
* o2
= PySequence_GetItem(source
, 1);
920 **obj
= wxPoint(PyInt_AsLong(o1
), PyInt_AsLong(o2
));
925 PyErr_SetString(PyExc_TypeError
, "Expected a 2-tuple of integers or a wxPoint object.");
931 bool wxRealPoint_helper(PyObject
* source
, wxRealPoint
** obj
) {
933 // If source is an object instance then it may already be the right type
934 if (PyInstance_Check(source
)) {
936 if (SWIG_GetPtrObj(source
, (void **)&ptr
, "_wxRealPoint_p"))
941 // otherwise a 2-tuple of floats is expected
942 else if (PySequence_Check(source
) && PyObject_Length(source
) == 2) {
943 PyObject
* o1
= PySequence_GetItem(source
, 0);
944 PyObject
* o2
= PySequence_GetItem(source
, 1);
945 **obj
= wxRealPoint(PyFloat_AsDouble(o1
), PyFloat_AsDouble(o2
));
950 PyErr_SetString(PyExc_TypeError
, "Expected a 2-tuple of floats or a wxRealPoint object.");
957 bool wxRect_helper(PyObject
* source
, wxRect
** obj
) {
959 // If source is an object instance then it may already be the right type
960 if (PyInstance_Check(source
)) {
962 if (SWIG_GetPtrObj(source
, (void **)&ptr
, "_wxRect_p"))
967 // otherwise a 4-tuple of integers is expected
968 else if (PySequence_Check(source
) && PyObject_Length(source
) == 4) {
969 PyObject
* o1
= PySequence_GetItem(source
, 0);
970 PyObject
* o2
= PySequence_GetItem(source
, 1);
971 PyObject
* o3
= PySequence_GetItem(source
, 2);
972 PyObject
* o4
= PySequence_GetItem(source
, 3);
973 **obj
= wxRect(PyInt_AsLong(o1
), PyInt_AsLong(o2
),
974 PyInt_AsLong(o3
), PyInt_AsLong(o4
));
979 PyErr_SetString(PyExc_TypeError
, "Expected a 4-tuple of integers or a wxRect object.");
985 bool wxColour_helper(PyObject
* source
, wxColour
** obj
) {
987 // If source is an object instance then it may already be the right type
988 if (PyInstance_Check(source
)) {
990 if (SWIG_GetPtrObj(source
, (void **)&ptr
, "_wxColour_p"))
995 // otherwise a string is expected
996 else if (PyString_Check(source
)) {
997 wxString spec
= PyString_AS_STRING(source
);
998 if (spec
[0] == '#' && spec
.Length() == 7) { // It's #RRGGBB
1000 int red
= strtol(spec
.Mid(1,2), &junk
, 16);
1001 int green
= strtol(spec
.Mid(3,2), &junk
, 16);
1002 int blue
= strtol(spec
.Mid(5,2), &junk
, 16);
1003 **obj
= wxColour(red
, green
, blue
);
1006 else { // it's a colour name
1007 **obj
= wxColour(spec
);
1013 PyErr_SetString(PyExc_TypeError
, "Expected a wxColour object or a string containing a colour name or '#RRGGBB'.");
1018 //----------------------------------------------------------------------
1019 //----------------------------------------------------------------------
1020 //----------------------------------------------------------------------