]>
Commit | Line | Data |
---|---|---|
7bf85405 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: helpers.cpp | |
03e9bead | 3 | // Purpose: Helper functions/classes for the wxPython extension module |
7bf85405 RD |
4 | // |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 7/1/97 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 1998 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
21f4bf45 | 13 | |
08127323 RD |
14 | #ifdef __WXGTK__ |
15 | #include "gtk/gtk.h" | |
16 | #endif | |
17 | ||
7bf85405 RD |
18 | #undef DEBUG |
19 | #include <Python.h> | |
20 | #include "helpers.h" | |
af309447 RD |
21 | #ifdef __WXMSW__ |
22 | #include <wx/msw/private.h> | |
23 | #undef FindWindow | |
24 | #undef GetCharWidth | |
25 | #undef LoadAccelerators | |
26 | #undef GetClassInfo | |
27 | #undef GetClassName | |
28 | #endif | |
dd9a3de8 | 29 | #include <wx/module.h> |
7bf85405 | 30 | |
cf694132 | 31 | |
7bf85405 RD |
32 | //--------------------------------------------------------------------------- |
33 | ||
34 | //wxHashTable* wxPyWindows = NULL; | |
35 | ||
36 | ||
37 | wxPoint wxPyDefaultPosition; //wxDefaultPosition); | |
38 | wxSize wxPyDefaultSize; //wxDefaultSize); | |
39 | wxString wxPyEmptyStr(""); | |
40 | ||
41 | ||
42 | ||
21f4bf45 | 43 | #ifdef __WXMSW__ // If building for win32... |
21f4bf45 RD |
44 | //---------------------------------------------------------------------- |
45 | // This gets run when the DLL is loaded. We just need to save a handle. | |
46 | //---------------------------------------------------------------------- | |
9c039d08 | 47 | |
21f4bf45 RD |
48 | BOOL WINAPI DllMain( |
49 | HINSTANCE hinstDLL, // handle to DLL module | |
50 | DWORD fdwReason, // reason for calling function | |
51 | LPVOID lpvReserved // reserved | |
52 | ) | |
53 | { | |
af309447 | 54 | wxSetInstance(hinstDLL); |
21f4bf45 RD |
55 | return 1; |
56 | } | |
57 | #endif | |
58 | ||
7bf85405 RD |
59 | //---------------------------------------------------------------------- |
60 | // Class for implementing the wxp main application shell. | |
61 | //---------------------------------------------------------------------- | |
62 | ||
63 | wxPyApp *wxPythonApp = NULL; // Global instance of application object | |
64 | ||
65 | ||
cf694132 RD |
66 | wxPyApp::wxPyApp() { |
67 | // printf("**** ctor\n"); | |
68 | } | |
69 | ||
70 | wxPyApp::~wxPyApp() { | |
71 | // printf("**** dtor\n"); | |
72 | } | |
73 | ||
74 | ||
7bf85405 RD |
75 | // This one isn't acutally called... See __wxStart() |
76 | bool wxPyApp::OnInit(void) { | |
77 | return false; | |
78 | } | |
79 | ||
80 | int wxPyApp::MainLoop(void) { | |
81 | int retval = wxApp::MainLoop(); | |
82 | AfterMainLoop(); | |
83 | return retval; | |
84 | } | |
85 | ||
af309447 | 86 | |
7bf85405 RD |
87 | void wxPyApp::AfterMainLoop(void) { |
88 | // more stuff from wxEntry... | |
0d6f9504 | 89 | |
7bf85405 RD |
90 | if (wxPythonApp->GetTopWindow()) { |
91 | // Forcibly delete the window. | |
92 | if (wxPythonApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame)) || | |
93 | wxPythonApp->GetTopWindow()->IsKindOf(CLASSINFO(wxDialog))) { | |
94 | ||
95 | wxPythonApp->GetTopWindow()->Close(TRUE); | |
96 | wxPythonApp->DeletePendingObjects(); | |
97 | } | |
98 | else { | |
99 | delete wxPythonApp->GetTopWindow(); | |
100 | wxPythonApp->SetTopWindow(NULL); | |
101 | } | |
102 | } | |
0d6f9504 RD |
103 | #ifdef __WXGTK__ |
104 | wxPythonApp->DeletePendingObjects(); | |
105 | #endif | |
7bf85405 RD |
106 | |
107 | wxPythonApp->OnExit(); | |
7bf85405 | 108 | wxApp::CleanUp(); |
b8b8dda7 | 109 | // delete wxPythonApp; |
7bf85405 RD |
110 | } |
111 | ||
112 | ||
fb5e0af0 | 113 | //--------------------------------------------------------------------- |
7bf85405 RD |
114 | // a few native methods to add to the module |
115 | //---------------------------------------------------------------------- | |
116 | ||
117 | ||
0d6f9504 | 118 | // This is where we pick up the first part of the wxEntry functionality... |
4464bbee | 119 | // The rest is in __wxStart and AfterMainLoop. This function is called when |
0d6f9504 RD |
120 | // wxpc is imported. (Before there is a wxApp object.) |
121 | void __wxPreStart() | |
7bf85405 | 122 | { |
0d6f9504 RD |
123 | // Bail out if there is already windows created. This means that the |
124 | // toolkit has already been initialized, as in embedding wxPython in | |
125 | // a C++ wxWindows app. | |
126 | if (wxTopLevelWindows.Number() > 0) | |
127 | return; | |
7bf85405 | 128 | |
7bf85405 | 129 | #ifdef __WXMSW__ |
9c039d08 | 130 | wxApp::Initialize(); |
7bf85405 | 131 | #endif |
21f4bf45 | 132 | |
08127323 | 133 | #ifdef __WXGTK__ |
fb5e0af0 RD |
134 | PyObject* sysargv = PySys_GetObject("argv"); |
135 | int argc = PyList_Size(sysargv); | |
136 | char** argv = new char*[argc+1]; | |
137 | int x; | |
138 | for(x=0; x<argc; x++) | |
139 | argv[x] = PyString_AsString(PyList_GetItem(sysargv, x)); | |
140 | argv[argc] = NULL; | |
141 | ||
08127323 | 142 | gtk_set_locale(); |
0d6f9504 RD |
143 | gtk_init( &argc, &argv ); |
144 | delete [] argv; | |
7bf85405 | 145 | |
08127323 | 146 | wxApp::Initialize(); // may return FALSE. Should we check? |
7bf85405 RD |
147 | #endif |
148 | ||
0d6f9504 RD |
149 | } |
150 | ||
151 | ||
cf694132 RD |
152 | #ifdef WXP_WITH_THREAD |
153 | static PyThreadState *event_tstate = NULL; | |
154 | #endif | |
0d6f9504 RD |
155 | static char* __nullArgv[1] = { 0 }; |
156 | ||
157 | // Start the user application, user App's OnInit method is a parameter here | |
158 | PyObject* __wxStart(PyObject* /* self */, PyObject* args) | |
159 | { | |
160 | PyObject* onInitFunc = NULL; | |
161 | PyObject* arglist; | |
162 | PyObject* result; | |
163 | long bResult; | |
164 | ||
cf694132 RD |
165 | #ifdef WXP_WITH_THREAD |
166 | event_tstate = PyThreadState_Get(); | |
167 | #endif | |
0d6f9504 RD |
168 | |
169 | if (!PyArg_ParseTuple(args, "O", &onInitFunc)) | |
170 | return NULL; | |
171 | ||
172 | if (wxTopLevelWindows.Number() > 0) { | |
173 | PyErr_SetString(PyExc_TypeError, "Only 1 wxApp per process!"); | |
174 | return NULL; | |
175 | } | |
176 | ||
177 | ||
178 | // This is the next part of the wxEntry functionality... | |
179 | wxPythonApp->argc = 0; | |
cf694132 | 180 | wxPythonApp->argv = NULL; |
0d6f9504 RD |
181 | wxPythonApp->OnInitGui(); |
182 | ||
7bf85405 RD |
183 | |
184 | // Call the Python App's OnInit function | |
185 | arglist = PyTuple_New(0); | |
cf694132 RD |
186 | |
187 | // Py_END_ALLOW_THREADS; **** __wxStart was called from Python, | |
188 | // should already have the lock | |
7bf85405 | 189 | result = PyEval_CallObject(onInitFunc, arglist); |
cf694132 RD |
190 | // Py_BEGIN_ALLOW_THREADS; |
191 | ||
7bf85405 RD |
192 | if (!result) { |
193 | PyErr_Print(); | |
194 | exit(1); | |
195 | } | |
196 | ||
197 | if (! PyInt_Check(result)) { | |
198 | PyErr_SetString(PyExc_TypeError, "OnInit should return a boolean value"); | |
199 | return NULL; | |
200 | } | |
201 | bResult = PyInt_AS_LONG(result); | |
202 | if (! bResult) { | |
203 | wxPythonApp->DeletePendingObjects(); | |
204 | wxPythonApp->OnExit(); | |
fb5e0af0 | 205 | wxApp::CleanUp(); |
7bf85405 RD |
206 | PyErr_SetString(PyExc_SystemExit, "OnInit returned false, exiting..."); |
207 | return NULL; | |
208 | } | |
209 | ||
13dfc243 | 210 | #ifdef __WXGTK__ |
fb5e0af0 | 211 | wxTheApp->m_initialized = (wxTopLevelWindows.Number() > 0); |
13dfc243 | 212 | #endif |
fb5e0af0 | 213 | |
7bf85405 RD |
214 | Py_INCREF(Py_None); |
215 | return Py_None; | |
216 | } | |
217 | ||
218 | ||
7bf85405 RD |
219 | |
220 | ||
221 | ||
222 | PyObject* wxPython_dict; | |
223 | PyObject* __wxSetDictionary(PyObject* /* self */, PyObject* args) | |
224 | { | |
225 | ||
226 | if (!PyArg_ParseTuple(args, "O", &wxPython_dict)) | |
227 | return NULL; | |
228 | ||
229 | if (!PyDict_Check(wxPython_dict)) { | |
230 | PyErr_SetString(PyExc_TypeError, "_wxSetDictionary must have dictionary object!"); | |
231 | return NULL; | |
232 | } | |
233 | #ifdef __WXMOTIF__ | |
21f4bf45 RD |
234 | #define wxPlatform "__WXMOTIF__" |
235 | #endif | |
236 | #ifdef __WXQT__ | |
237 | #define wxPlatform "__WXQT__" | |
7bf85405 RD |
238 | #endif |
239 | #ifdef __WXGTK__ | |
21f4bf45 | 240 | #define wxPlatform "__WXGTK__" |
7bf85405 RD |
241 | #endif |
242 | #if defined(__WIN32__) || defined(__WXMSW__) | |
fb5e0af0 | 243 | #define wxPlatform "__WXMSW__" |
7bf85405 RD |
244 | #endif |
245 | #ifdef __WXMAC__ | |
21f4bf45 | 246 | #define wxPlatform "__WXMAC__" |
7bf85405 RD |
247 | #endif |
248 | ||
249 | PyDict_SetItemString(wxPython_dict, "wxPlatform", PyString_FromString(wxPlatform)); | |
250 | ||
251 | Py_INCREF(Py_None); | |
252 | return Py_None; | |
253 | } | |
254 | ||
255 | ||
256 | //--------------------------------------------------------------------------- | |
257 | ||
258 | ||
259 | static | |
260 | PyObject* wxPyConstructObject(void* ptr, char* className) | |
261 | { | |
9c039d08 | 262 | char buff[64]; // should always be big enough... |
7bf85405 RD |
263 | char swigptr[64]; |
264 | ||
265 | sprintf(buff, "_%s_p", className); | |
266 | SWIG_MakePtr(swigptr, ptr, buff); | |
267 | ||
268 | sprintf(buff, "%sPtr", className); | |
269 | PyObject* classobj = PyDict_GetItemString(wxPython_dict, buff); | |
270 | if (! classobj) { | |
271 | Py_INCREF(Py_None); | |
272 | return Py_None; | |
273 | } | |
274 | ||
275 | PyObject* arg = Py_BuildValue("(s)", swigptr); | |
276 | PyObject* obj = PyInstance_New(classobj, arg, NULL); | |
277 | Py_DECREF(arg); | |
278 | ||
279 | return obj; | |
280 | } | |
281 | ||
282 | ||
cf694132 RD |
283 | |
284 | wxPyCallback::wxPyCallback(PyObject* func) { | |
285 | m_func = func; | |
286 | Py_INCREF(m_func); | |
287 | } | |
288 | ||
289 | wxPyCallback::~wxPyCallback() { | |
290 | #ifdef WXP_WITH_THREAD | |
291 | PyEval_RestoreThread(event_tstate); | |
292 | #endif | |
293 | ||
294 | Py_DECREF(m_func); | |
295 | ||
296 | #ifdef WXP_WITH_THREAD | |
297 | PyEval_SaveThread(); | |
298 | #endif | |
299 | } | |
300 | ||
301 | ||
302 | ||
303 | ||
7bf85405 RD |
304 | // This function is used for all events destined for Python event handlers. |
305 | void wxPyCallback::EventThunker(wxEvent& event) { | |
306 | wxPyCallback* cb = (wxPyCallback*)event.m_callbackUserData; | |
307 | PyObject* func = cb->m_func; | |
308 | PyObject* result; | |
309 | PyObject* arg; | |
310 | PyObject* tuple; | |
311 | ||
cf694132 RD |
312 | |
313 | #ifdef WXP_WITH_THREAD | |
314 | PyEval_RestoreThread(event_tstate); | |
315 | #endif | |
7bf85405 RD |
316 | arg = wxPyConstructObject((void*)&event, event.GetClassInfo()->GetClassName()); |
317 | ||
318 | tuple = PyTuple_New(1); | |
319 | PyTuple_SET_ITEM(tuple, 0, arg); | |
320 | result = PyEval_CallObject(func, tuple); | |
7bf85405 RD |
321 | Py_DECREF(tuple); |
322 | if (result) { | |
323 | Py_DECREF(result); | |
324 | PyErr_Clear(); | |
325 | } else { | |
326 | PyErr_Print(); | |
327 | } | |
cf694132 RD |
328 | #ifdef WXP_WITH_THREAD |
329 | PyEval_SaveThread(); | |
330 | #endif | |
7bf85405 RD |
331 | } |
332 | ||
333 | ||
334 | //--------------------------------------------------------------------------- | |
335 | ||
336 | wxPyMenu::wxPyMenu(const wxString& title, PyObject* _func) | |
337 | : wxMenu(title, (wxFunction)(func ? MenuCallback : NULL)), func(0) { | |
338 | ||
339 | if (_func) { | |
340 | func = _func; | |
341 | Py_INCREF(func); | |
342 | } | |
343 | } | |
344 | ||
345 | wxPyMenu::~wxPyMenu() { | |
346 | if (func) | |
347 | Py_DECREF(func); | |
348 | } | |
349 | ||
350 | ||
351 | void wxPyMenu::MenuCallback(wxMenu& menu, wxCommandEvent& evt) { | |
cf694132 RD |
352 | #ifdef WXP_WITH_THREAD |
353 | PyEval_RestoreThread(event_tstate); | |
354 | #endif | |
7bf85405 RD |
355 | PyObject* evtobj = wxPyConstructObject((void*)&evt, "wxCommandEvent"); |
356 | PyObject* menuobj = wxPyConstructObject((void*)&menu, "wxMenu"); | |
357 | if (PyErr_Occurred()) { | |
358 | // bail out if a problem | |
359 | PyErr_Print(); | |
360 | return; | |
361 | } | |
362 | // Now call the callback... | |
363 | PyObject* func = ((wxPyMenu*)&menu)->func; | |
d5c9047a RD |
364 | PyObject* args = PyTuple_New(2); |
365 | PyTuple_SET_ITEM(args, 0, menuobj); | |
366 | PyTuple_SET_ITEM(args, 1, evtobj); | |
7bf85405 RD |
367 | PyObject* res = PyEval_CallObject(func, args); |
368 | Py_DECREF(args); | |
d5c9047a | 369 | Py_XDECREF(res); /* In case res is a NULL pointer */ |
cf694132 RD |
370 | #ifdef WXP_WITH_THREAD |
371 | PyEval_SaveThread(); | |
372 | #endif | |
7bf85405 | 373 | } |
714e6a9e | 374 | |
7bf85405 RD |
375 | |
376 | //--------------------------------------------------------------------------- | |
377 | ||
378 | wxPyTimer::wxPyTimer(PyObject* callback) { | |
379 | func = callback; | |
380 | Py_INCREF(func); | |
381 | } | |
382 | ||
383 | wxPyTimer::~wxPyTimer() { | |
384 | Py_DECREF(func); | |
385 | } | |
386 | ||
387 | void wxPyTimer::Notify() { | |
cf694132 RD |
388 | #ifdef WXP_WITH_THREAD |
389 | PyEval_RestoreThread(event_tstate); | |
390 | #endif | |
7bf85405 RD |
391 | PyObject* result; |
392 | PyObject* args = Py_BuildValue("()"); | |
393 | ||
394 | result = PyEval_CallObject(func, args); | |
395 | Py_DECREF(args); | |
396 | if (result) { | |
397 | Py_DECREF(result); | |
398 | PyErr_Clear(); | |
399 | } else { | |
400 | PyErr_Print(); | |
401 | } | |
cf694132 RD |
402 | #ifdef WXP_WITH_THREAD |
403 | PyEval_SaveThread(); | |
404 | #endif | |
7bf85405 RD |
405 | } |
406 | ||
407 | ||
cf694132 RD |
408 | //---------------------------------------------------------------------- |
409 | ||
410 | IMPLEMENT_DYNAMIC_CLASS(wxPyEvent, wxCommandEvent) | |
411 | ||
412 | wxPyEvent::wxPyEvent(wxEventType commandType, PyObject* userData) | |
413 | : wxCommandEvent(commandType), m_userData(Py_None) | |
414 | { | |
415 | m_userData = userData; | |
416 | if (m_userData != Py_None) { | |
417 | Py_INCREF(m_userData); | |
418 | } | |
419 | } | |
420 | ||
421 | ||
422 | wxPyEvent::~wxPyEvent() { | |
423 | if (m_userData != Py_None) { | |
424 | Py_DECREF(m_userData); | |
425 | m_userData = Py_None; | |
426 | } | |
427 | } | |
428 | ||
429 | ||
430 | void wxPyEvent::SetUserData(PyObject* userData) { | |
431 | if (m_userData != Py_None) { | |
432 | Py_DECREF(m_userData); | |
433 | m_userData = Py_None; | |
434 | } | |
435 | m_userData = userData; | |
436 | if (m_userData != Py_None) { | |
437 | Py_INCREF(m_userData); | |
438 | } | |
439 | } | |
440 | ||
441 | ||
442 | PyObject* wxPyEvent::GetUserData() { | |
443 | return m_userData; | |
444 | } | |
7bf85405 | 445 | |
7bf85405 RD |
446 | //---------------------------------------------------------------------- |
447 | //---------------------------------------------------------------------- | |
448 | // Some helper functions for typemaps in my_typemaps.i, so they won't be | |
449 | // imcluded in every file... | |
450 | ||
451 | ||
b639c3c5 RD |
452 | byte* byte_LIST_helper(PyObject* source) { |
453 | if (!PyList_Check(source)) { | |
454 | PyErr_SetString(PyExc_TypeError, "Expected a list object."); | |
455 | return NULL; | |
456 | } | |
457 | int count = PyList_Size(source); | |
458 | byte* temp = new byte[count]; | |
459 | if (! temp) { | |
460 | PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array"); | |
461 | return NULL; | |
462 | } | |
463 | for (int x=0; x<count; x++) { | |
464 | PyObject* o = PyList_GetItem(source, x); | |
465 | if (! PyInt_Check(o)) { | |
466 | PyErr_SetString(PyExc_TypeError, "Expected a list of integers."); | |
467 | return NULL; | |
468 | } | |
469 | temp[x] = (byte)PyInt_AsLong(o); | |
470 | } | |
471 | return temp; | |
472 | } | |
473 | ||
474 | ||
7bf85405 RD |
475 | int* int_LIST_helper(PyObject* source) { |
476 | if (!PyList_Check(source)) { | |
477 | PyErr_SetString(PyExc_TypeError, "Expected a list object."); | |
478 | return NULL; | |
479 | } | |
480 | int count = PyList_Size(source); | |
481 | int* temp = new int[count]; | |
482 | if (! temp) { | |
483 | PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array"); | |
484 | return NULL; | |
485 | } | |
486 | for (int x=0; x<count; x++) { | |
487 | PyObject* o = PyList_GetItem(source, x); | |
488 | if (! PyInt_Check(o)) { | |
489 | PyErr_SetString(PyExc_TypeError, "Expected a list of integers."); | |
490 | return NULL; | |
491 | } | |
492 | temp[x] = PyInt_AsLong(o); | |
493 | } | |
494 | return temp; | |
495 | } | |
496 | ||
497 | ||
498 | long* long_LIST_helper(PyObject* source) { | |
499 | if (!PyList_Check(source)) { | |
500 | PyErr_SetString(PyExc_TypeError, "Expected a list object."); | |
501 | return NULL; | |
502 | } | |
503 | int count = PyList_Size(source); | |
504 | long* temp = new long[count]; | |
505 | if (! temp) { | |
506 | PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array"); | |
507 | return NULL; | |
508 | } | |
509 | for (int x=0; x<count; x++) { | |
510 | PyObject* o = PyList_GetItem(source, x); | |
511 | if (! PyInt_Check(o)) { | |
512 | PyErr_SetString(PyExc_TypeError, "Expected a list of integers."); | |
513 | return NULL; | |
514 | } | |
515 | temp[x] = PyInt_AsLong(o); | |
516 | } | |
517 | return temp; | |
518 | } | |
519 | ||
520 | ||
521 | char** string_LIST_helper(PyObject* source) { | |
522 | if (!PyList_Check(source)) { | |
523 | PyErr_SetString(PyExc_TypeError, "Expected a list object."); | |
524 | return NULL; | |
525 | } | |
526 | int count = PyList_Size(source); | |
527 | char** temp = new char*[count]; | |
528 | if (! temp) { | |
529 | PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array"); | |
530 | return NULL; | |
531 | } | |
532 | for (int x=0; x<count; x++) { | |
533 | PyObject* o = PyList_GetItem(source, x); | |
534 | if (! PyString_Check(o)) { | |
535 | PyErr_SetString(PyExc_TypeError, "Expected a list of strings."); | |
536 | return NULL; | |
537 | } | |
538 | temp[x] = PyString_AsString(o); | |
539 | } | |
540 | return temp; | |
541 | } | |
542 | ||
543 | ||
544 | ||
545 | wxPoint* wxPoint_LIST_helper(PyObject* source) { | |
546 | if (!PyList_Check(source)) { | |
547 | PyErr_SetString(PyExc_TypeError, "Expected a list object."); | |
548 | return NULL; | |
549 | } | |
550 | int count = PyList_Size(source); | |
551 | wxPoint* temp = new wxPoint[count]; | |
552 | if (! temp) { | |
553 | PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array"); | |
554 | return NULL; | |
555 | } | |
556 | for (int x=0; x<count; x++) { | |
557 | PyObject* o = PyList_GetItem(source, x); | |
558 | if (PyString_Check(o)) { | |
559 | char* st = PyString_AsString(o); | |
560 | wxPoint* pt; | |
561 | if (SWIG_GetPtr(st,(void **) &pt,"_wxPoint_p")) { | |
562 | PyErr_SetString(PyExc_TypeError,"Expected _wxPoint_p."); | |
563 | return NULL; | |
564 | } | |
565 | temp[x] = *pt; | |
566 | } | |
567 | else if (PyTuple_Check(o)) { | |
568 | PyObject* o1 = PyTuple_GetItem(o, 0); | |
569 | PyObject* o2 = PyTuple_GetItem(o, 1); | |
570 | ||
571 | temp[x].x = PyInt_AsLong(o1); | |
572 | temp[x].y = PyInt_AsLong(o2); | |
573 | } | |
574 | else { | |
575 | PyErr_SetString(PyExc_TypeError, "Expected a list of 2-tuples or wxPoints."); | |
576 | return NULL; | |
577 | } | |
578 | } | |
579 | return temp; | |
580 | } | |
581 | ||
582 | ||
583 | wxBitmap** wxBitmap_LIST_helper(PyObject* source) { | |
584 | if (!PyList_Check(source)) { | |
585 | PyErr_SetString(PyExc_TypeError, "Expected a list object."); | |
586 | return NULL; | |
587 | } | |
588 | int count = PyList_Size(source); | |
589 | wxBitmap** temp = new wxBitmap*[count]; | |
590 | if (! temp) { | |
591 | PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array"); | |
592 | return NULL; | |
593 | } | |
594 | for (int x=0; x<count; x++) { | |
595 | PyObject* o = PyList_GetItem(source, x); | |
596 | if (PyString_Check(o)) { | |
597 | char* st = PyString_AsString(o); | |
598 | wxBitmap* pt; | |
599 | if (SWIG_GetPtr(st,(void **) &pt,"_wxBitmap_p")) { | |
600 | PyErr_SetString(PyExc_TypeError,"Expected _wxBitmap_p."); | |
601 | return NULL; | |
602 | } | |
603 | temp[x] = pt; | |
604 | } | |
605 | else { | |
606 | PyErr_SetString(PyExc_TypeError, "Expected a list of wxBitmaps."); | |
607 | return NULL; | |
608 | } | |
609 | } | |
610 | return temp; | |
611 | } | |
612 | ||
613 | ||
614 | ||
615 | wxString* wxString_LIST_helper(PyObject* source) { | |
616 | if (!PyList_Check(source)) { | |
617 | PyErr_SetString(PyExc_TypeError, "Expected a list object."); | |
618 | return NULL; | |
619 | } | |
620 | int count = PyList_Size(source); | |
621 | wxString* temp = new wxString[count]; | |
622 | if (! temp) { | |
623 | PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array"); | |
624 | return NULL; | |
625 | } | |
626 | for (int x=0; x<count; x++) { | |
627 | PyObject* o = PyList_GetItem(source, x); | |
628 | if (! PyString_Check(o)) { | |
629 | PyErr_SetString(PyExc_TypeError, "Expected a list of strings."); | |
630 | return NULL; | |
631 | } | |
632 | temp[x] = PyString_AsString(o); | |
633 | } | |
634 | return temp; | |
635 | } | |
636 | ||
637 | ||
638 | wxAcceleratorEntry* wxAcceleratorEntry_LIST_helper(PyObject* source) { | |
639 | if (!PyList_Check(source)) { | |
640 | PyErr_SetString(PyExc_TypeError, "Expected a list object."); | |
641 | return NULL; | |
642 | } | |
643 | int count = PyList_Size(source); | |
644 | wxAcceleratorEntry* temp = new wxAcceleratorEntry[count]; | |
645 | if (! temp) { | |
646 | PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array"); | |
647 | return NULL; | |
648 | } | |
649 | for (int x=0; x<count; x++) { | |
650 | PyObject* o = PyList_GetItem(source, x); | |
651 | if (PyString_Check(o)) { | |
652 | char* st = PyString_AsString(o); | |
653 | wxAcceleratorEntry* ae; | |
654 | if (SWIG_GetPtr(st,(void **) &ae,"_wxAcceleratorEntry_p")) { | |
655 | PyErr_SetString(PyExc_TypeError,"Expected _wxAcceleratorEntry_p."); | |
656 | return NULL; | |
657 | } | |
658 | temp[x] = *ae; | |
659 | } | |
660 | else if (PyTuple_Check(o)) { | |
661 | PyObject* o1 = PyTuple_GetItem(o, 0); | |
662 | PyObject* o2 = PyTuple_GetItem(o, 1); | |
663 | PyObject* o3 = PyTuple_GetItem(o, 2); | |
664 | ||
665 | temp[x].m_flags = PyInt_AsLong(o1); | |
666 | temp[x].m_keyCode = PyInt_AsLong(o2); | |
667 | temp[x].m_command = PyInt_AsLong(o3); | |
668 | } | |
669 | else { | |
670 | PyErr_SetString(PyExc_TypeError, "Expected a list of 3-tuples or wxAcceleratorEntry objects."); | |
671 | return NULL; | |
672 | } | |
673 | } | |
674 | return temp; | |
675 | } | |
676 | ||
7bf85405 | 677 | //---------------------------------------------------------------------- |
7bf85405 | 678 | |
7bf85405 | 679 | |
7bf85405 RD |
680 | |
681 | ///////////////////////////////////////////////////////////////////////////// | |
682 | // | |
683 | // $Log$ | |
cf694132 RD |
684 | // Revision 1.20 1999/04/30 03:29:18 RD |
685 | // wxPython 2.0b9, first phase (win32) | |
686 | // Added gobs of stuff, see wxPython/README.txt for details | |
687 | // | |
688 | // Revision 1.19.4.1 1999/03/27 23:29:14 RD | |
689 | // | |
690 | // wxPython 2.0b8 | |
691 | // Python thread support | |
692 | // various minor additions | |
693 | // various minor fixes | |
694 | // | |
af309447 RD |
695 | // Revision 1.19 1999/02/20 09:02:59 RD |
696 | // Added wxWindow_FromHWND(hWnd) for wxMSW to construct a wxWindow from a | |
697 | // window handle. If you can get the window handle into the python code, | |
698 | // it should just work... More news on this later. | |
699 | // | |
700 | // Added wxImageList, wxToolTip. | |
701 | // | |
702 | // Re-enabled wxConfig.DeleteAll() since it is reportedly fixed for the | |
703 | // wxRegConfig class. | |
704 | // | |
705 | // As usual, some bug fixes, tweaks, etc. | |
706 | // | |
dd9a3de8 | 707 | // Revision 1.18 1999/01/30 08:17:27 RD |
af309447 | 708 | // |
dd9a3de8 RD |
709 | // Added wxSashWindow, wxSashEvent, wxLayoutAlgorithm, etc. |
710 | // | |
711 | // Various cleanup, tweaks, minor additions, etc. to maintain | |
712 | // compatibility with the current wxWindows. | |
713 | // | |
08127323 | 714 | // Revision 1.17 1999/01/30 07:30:12 RD |
dd9a3de8 | 715 | // |
08127323 RD |
716 | // Added wxSashWindow, wxSashEvent, wxLayoutAlgorithm, etc. |
717 | // | |
718 | // Various cleanup, tweaks, minor additions, etc. to maintain | |
719 | // compatibility with the current wxWindows. | |
720 | // | |
4f22cf8d | 721 | // Revision 1.16 1998/12/17 14:07:39 RR |
08127323 | 722 | // |
4f22cf8d RR |
723 | // Removed minor differences between wxMSW and wxGTK |
724 | // | |
b8b8dda7 RD |
725 | // Revision 1.15 1998/12/15 20:41:19 RD |
726 | // Changed the import semantics from "from wxPython import *" to "from | |
727 | // wxPython.wx import *" This is for people who are worried about | |
728 | // namespace pollution, they can use "from wxPython import wx" and then | |
729 | // prefix all the wxPython identifiers with "wx." | |
730 | // | |
731 | // Added wxTaskbarIcon for wxMSW. | |
732 | // | |
733 | // Made the events work for wxGrid. | |
734 | // | |
735 | // Added wxConfig. | |
736 | // | |
737 | // Added wxMiniFrame for wxGTK, (untested.) | |
738 | // | |
739 | // Changed many of the args and return values that were pointers to gdi | |
740 | // objects to references to reflect changes in the wxWindows API. | |
741 | // | |
742 | // Other assorted fixes and additions. | |
743 | // | |
b639c3c5 | 744 | // Revision 1.14 1998/11/25 08:45:25 RD |
b8b8dda7 | 745 | // |
b639c3c5 RD |
746 | // Added wxPalette, wxRegion, wxRegionIterator, wxTaskbarIcon |
747 | // Added events for wxGrid | |
748 | // Other various fixes and additions | |
749 | // | |
faf3cb35 RD |
750 | // Revision 1.13 1998/11/15 23:03:45 RD |
751 | // Removing some ifdef's for wxGTK | |
752 | // | |
4464bbee RD |
753 | // Revision 1.12 1998/11/03 09:21:08 RD |
754 | // fixed a typo | |
755 | // | |
d5c9047a RD |
756 | // Revision 1.11 1998/10/20 06:43:58 RD |
757 | // New wxTreeCtrl wrappers (untested) | |
758 | // some changes in helpers | |
759 | // etc. | |
760 | // | |
9c039d08 | 761 | // Revision 1.10 1998/10/02 06:40:39 RD |
d5c9047a | 762 | // |
9c039d08 RD |
763 | // Version 0.4 of wxPython for MSW. |
764 | // | |
47d67540 | 765 | // Revision 1.9 1998/09/25 13:28:52 VZ |
9c039d08 | 766 | // |
47d67540 VZ |
767 | // USE_xxx constants renamed to wxUSE_xxx. This is an incompatible change, you |
768 | // must recompile everything after upgrading! | |
769 | // | |
0d6f9504 RD |
770 | // Revision 1.8 1998/08/27 21:59:08 RD |
771 | // Some chicken-and-egg problems solved for wxPython on wxGTK | |
772 | // | |
21f4bf45 RD |
773 | // Revision 1.7 1998/08/27 00:00:26 RD |
774 | // - more tweaks | |
775 | // - have discovered some problems but not yet discovered solutions... | |
776 | // | |
13dfc243 | 777 | // Revision 1.6 1998/08/18 21:54:12 RD |
21f4bf45 | 778 | // |
13dfc243 RD |
779 | // ifdef out some wxGTK specific code |
780 | // | |
fb5e0af0 RD |
781 | // Revision 1.5 1998/08/18 19:48:17 RD |
782 | // more wxGTK compatibility things. | |
783 | // | |
784 | // It builds now but there are serious runtime problems... | |
785 | // | |
714e6a9e RD |
786 | // Revision 1.4 1998/08/16 04:31:06 RD |
787 | // More wxGTK work. | |
788 | // | |
03e9bead RD |
789 | // Revision 1.3 1998/08/15 07:36:36 RD |
790 | // - Moved the header in the .i files out of the code that gets put into | |
791 | // the .cpp files. It caused CVS conflicts because of the RCS ID being | |
792 | // different each time. | |
793 | // | |
794 | // - A few minor fixes. | |
795 | // | |
853b255a RD |
796 | // Revision 1.2 1998/08/14 23:36:36 RD |
797 | // Beginings of wxGTK compatibility | |
798 | // | |
7bf85405 RD |
799 | // Revision 1.1 1998/08/09 08:25:51 RD |
800 | // Initial version | |
801 | // | |
802 | // |