X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bb0054cda81e7a6a6e1f33f4b47e46f529110f14..4afd752902ae7c44f4b3dc2edb11d7c24f95ed54:/utils/wxPython/src/printfw.i diff --git a/utils/wxPython/src/printfw.i b/utils/wxPython/src/printfw.i index d4da779032..b5b4c91e70 100644 --- a/utils/wxPython/src/printfw.i +++ b/utils/wxPython/src/printfw.i @@ -16,6 +16,8 @@ #include "helpers.h" #include #include + +#include "printfw.h" %} //---------------------------------------------------------------------- @@ -198,65 +200,63 @@ public: //---------------------------------------------------------------------- // Custom wxPrintout class that knows how to call python %{ -class wxPyPrintout : public wxPrintout { -public: - wxPyPrintout(const wxString& title) : wxPrintout(title) {} - - PYCALLBACK_BOOL_INTINT(wxPrintout, OnBeginDocument); - PYCALLBACK__(wxPrintout, OnEndDocument); - PYCALLBACK__(wxPrintout, OnBeginPrinting); - PYCALLBACK__(wxPrintout, OnEndPrinting); - PYCALLBACK__(wxPrintout, OnPreparePrinting); - PYCALLBACK_BOOL_INT_pure(wxPrintout, OnPrintPage); - PYCALLBACK_BOOL_INT(wxPrintout, HasPage); - - - // Since this one would be tough and ugly to do with the Macros... - void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) { - bool hadErr = false; - - if (m_myInst.findCallback("GetPageInfo")) { - PyObject* result = m_myInst.callCallbackObj(Py_BuildValue("()")); - if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) { - PyObject* val; - - val = PyTuple_GetItem(result, 0); - if (PyInt_Check(val)) *minPage = PyInt_AsLong(val); - else hadErr = true; - - val = PyTuple_GetItem(result, 1); - if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val); - else hadErr = true; - - val = PyTuple_GetItem(result, 2); - if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val); - else hadErr = true; - - val = PyTuple_GetItem(result, 3); - if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val); - else hadErr = true; - } - else - hadErr = true; - - if (hadErr) { - PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers."); - PyErr_Print(); - } - Py_DECREF(result); -#ifdef WXP_WITH_THREAD - PyEval_SaveThread(); -#endif + + +// Since this one would be tough and ugly to do with the Macros... +void wxPyPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) { + bool hadErr = false; + + bool doSave = wxPyRestoreThread(); + if (m_myInst.findCallback("GetPageInfo")) { + PyObject* result = m_myInst.callCallbackObj(Py_BuildValue("()")); + if (result && PyTuple_Check(result) && PyTuple_Size(result) == 4) { + PyObject* val; + + val = PyTuple_GetItem(result, 0); + if (PyInt_Check(val)) *minPage = PyInt_AsLong(val); + else hadErr = true; + + val = PyTuple_GetItem(result, 1); + if (PyInt_Check(val)) *maxPage = PyInt_AsLong(val); + else hadErr = true; + + val = PyTuple_GetItem(result, 2); + if (PyInt_Check(val)) *pageFrom = PyInt_AsLong(val); + else hadErr = true; + + val = PyTuple_GetItem(result, 3); + if (PyInt_Check(val)) *pageTo = PyInt_AsLong(val); + else hadErr = true; } else - wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo); + hadErr = true; + + if (hadErr) { + PyErr_SetString(PyExc_TypeError, "GetPageInfo should return a tuple of 4 integers."); + PyErr_Print(); + } + Py_DECREF(result); } - void base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) { + else wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo); - } - PYPRIVATE; -}; + wxPySaveThread(doSave); +} + +void wxPyPrintout::base_GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) { + wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo); +} + + +IMP_PYCALLBACK_BOOL_INTINT(wxPyPrintout, wxPrintout, OnBeginDocument); +IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndDocument); +IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnBeginPrinting); +IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnEndPrinting); +IMP_PYCALLBACK__(wxPyPrintout, wxPrintout, OnPreparePrinting); +IMP_PYCALLBACK_BOOL_INT_pure(wxPyPrintout, wxPrintout, OnPrintPage); +IMP_PYCALLBACK_BOOL_INT(wxPyPrintout, wxPrintout, HasPage); + + %} @@ -269,9 +269,7 @@ public: %pragma(python) addtomethod = "__init__:self._setSelf(self)" %addmethods { - void Destroy() { - delete self; - } + void Destroy() { delete self; } } wxDC* GetDC();