diff options
Diffstat (limited to 'sip')
30 files changed, 506 insertions, 856 deletions
diff --git a/sip/qt/qapplication.sip b/sip/qt/qapplication.sip index 367ac2c..dcf333d 100644 --- a/sip/qt/qapplication.sip +++ b/sip/qt/qapplication.sip @@ -64,6 +64,9 @@ This has been renamed to <Literal>exec_loop</Literal> in Python. </Sect2> %End +%ModuleHeaderCode +#include <tqapplication.h> +%End TQApplication *tqApp; @@ -128,7 +131,6 @@ public: } %End -%If (TQt_2_2_0 -) enum Type { Tty, GuiClient, @@ -160,7 +162,6 @@ public: updatePyArgv(a0,argc,argv); } %End -%End ~TQApplication(); %MethodCode @@ -209,7 +210,7 @@ public: sipIsErr = 1; else for (int a = 0; a < argc; ++a) - if (PyList_SetItem(sipRes,a,PyString_FromString(sipCpp -> argv()[a])) < 0) + if (PyList_SetItem(sipRes,a,SIPBytes_FromString(sipCpp -> argv()[a])) < 0) { Py_DECREF(sipRes); sipIsErr = 1; @@ -217,39 +218,17 @@ public: } %End -%If (TQt_2_3_0 -) Type type() const; -%End -%If (- TQt_2_00) - static GUIStyle style(); - static void setStyle(GUIStyle); -%End -%If (TQt_2_00 -) static TQStyle &style(); static void setStyle(TQStyle * /Transfer/); -%End -%If (TQt_3_0_0 -) static TQStyle *setStyle(const TQString &); -%End -%If (- TQt_2_00) - enum ColorSpec - { - NormalColor = 0, - CustomColor = 1, - PrivateColor = 4, - ManyColor = 4, - TrueColor = 4 - }; -%End -%If (TQt_2_00 -) enum ColorSpec { NormalColor = 0, CustomColor = 1, ManyColor = 2 }; -%End static int colorSpec(); static void setColorSpec(int); @@ -258,51 +237,26 @@ public: static void restoreOverrideCursor(); static bool hasGlobalMouseTracking(); static void setGlobalMouseTracking(bool); -%If (- TQt_2_00) - static TQPalette *palette(); - static void setPalette(TQPalette &,bool = 0); - static TQFont *font(); - static void setFont(const TQFont &,bool = 0); -%End -%If (TQt_2_00 -) static TQPalette palette(const TQWidget * = 0); static void setPalette(TQPalette &,bool = 0,const char * = 0); static TQFont font(const TQWidget * = 0); static void setFont(const TQFont &,bool = 0,const char * = 0); -%End static TQFontMetrics fontMetrics(); TQWidget *mainWidget() const; -%If (- TQt_2_00) - // We may not need the /Transfer/ now that the TQApplication dtor is - // instrumented, but we'll leave it in so as not to break old programs - // needlessly. - void setMainWidget(TQWidget * /Transfer/); -%End -%If (TQt_2_00 -) virtual void setMainWidget(TQWidget *); virtual void polish(TQWidget *); -%End static TQWidgetList *allWidgets(); static TQWidgetList *topLevelWidgets(); -%If (- TQt_3_0_0) - static TQWidget *desktop(); -%End -%If (TQt_3_0_0 -) static TQDesktopWidget *desktop(); -%End static TQWidget *activePopupWidget(); static TQWidget *activeModalWidget(); static TQClipboard *clipboard(); TQWidget *focusWidget() const; -%If (TQt_2_00 -) TQWidget *activeWindow() const; -%End static TQWidget *widgetAt(int,int,bool = 0); static TQWidget *widgetAt(const TQPoint &,bool = 0); -%If (TQt_3_1_0 -) static TQEventLoop *eventLoop(); -%End int exec() /PyName=exec_loop, ReleaseGIL, PreHook=__pyTQtPreEventLoopHook__, @@ -310,44 +264,27 @@ public: void processEvents() /ReleaseGIL/; void processEvents(int) /ReleaseGIL/; void processOneEvent() /ReleaseGIL/; -%If (TQt_3_0_0 -) bool hasPendingEvents(); -%End int enter_loop() /ReleaseGIL/; void exit_loop(); -%If (TQt_2_00 -) int loopLevel() const; -%End static void exit(int = 0); static bool sendEvent(TQObject *,TQEvent *) /ReleaseGIL/; static void postEvent(TQObject *,TQEvent * /Transfer/) /ReleaseGIL/; static void sendPostedEvents(TQObject *,int) /ReleaseGIL/; -%If (TQt_2_00 -) static void sendPostedEvents() /ReleaseGIL/; static void removePostedEvents(TQObject *); -%End virtual bool notify(TQObject *,TQEvent *) /ReleaseGIL/; static bool startingUp(); static bool closingDown(); static void flushX(); -%If (TQt_3_0_0 -) static void flush(); -%End static void syncX(); static void beep(); -%If (TQt_2_00 -) void setDefaultCodec(TQTextCodec *); TQTextCodec *defaultCodec() const; void installTranslator(TQTranslator *); void removeTranslator(TQTranslator *); -%End -%If (TQt_2_00 - TQt_3_0_0) - TQString translate(const char *,const char *) const; -%End -%If (TQt_2_2_0 - TQt_3_0_0) - TQString translate(const char *,const char *,const char *) const; -%End -%If (TQt_3_0_0 -) enum Encoding { DefaultCodec, UnicodeUTF8 @@ -355,98 +292,59 @@ public: TQString translate(const char *,const char *,const char * = 0, Encoding = DefaultCodec) const; -%End -%If (TQt_3_2_0 -) TQString applicationDirPath(); TQString applicationFilePath(); -%End -%If (- TQt_3_0_0) - static void setWinStyleHighlightColor(const TQColor &); - static const TQColor &winStyleHighlightColor(); -%End -%If (TQt_2_00 -) static void setDesktopSettingsAware(bool); static bool desktopSettingsAware(); static void setCursorFlashTime(int); static int cursorFlashTime(); -%End static void setDoubleClickInterval(int); static int doubleClickInterval(); -%If (TQt_2_1_0 -) static void setWheelScrollLines(int); static int wheelScrollLines(); -%If (TQt_2_2_0 -) static void setGlobalStrut(const TQSize &); static TQSize globalStrut(); -%End -%If (TQt_3_0_0 -) static void setLibraryPaths(const TQStringList &); static TQStringList libraryPaths(); static void addLibraryPath(const TQString &); static void removeLibraryPath(const TQString &); -%End static void setStartDragTime(int); static int startDragTime(); static void setStartDragDistance(int); static int startDragDistance(); -%If (TQt_3_0_0 -) static void setReverseLayout(bool); static bool reverseLayout(); static int horizontalAlignment(int); -%End -%If (TQt_2_2_0 -) static bool isEffectEnabled(TQt::UIEffect); static void setEffectEnabled(TQt::UIEffect,bool = 1); -%End -%End -%If (TQt_2_00 -) bool isSessionRestored() const; TQString sessionId() const; -%If (TQt_3_1_0 -) TQString sessionKey() const; -%End virtual void commitData(TQSessionManager &); virtual void saveState(TQSessionManager &); -%End -%If (TQt_2_1_0 -) void wakeUpGuiThread(); -%End %If (TQt_THREAD_SUPPORT) -%If (TQt_2_2_0 -) void lock() /ReleaseGIL/; void unlock(bool = 1); bool locked(); -%End -%If (TQt_3_0_0 -) bool tryLock(); %End -%End signals: void lastWindowClosed(); -%If (TQt_2_00 -) void aboutToQuit(); -%End -%If (TQt_2_1_0 -) void guiThreadAwake(); -%End public slots: void quit(); -%If (TQt_2_00 -) void closeAllWindows(); -%End -%If (TQt_3_2_0 -) void aboutTQt(); -%End protected: -%If (TQt_3_1_0 -) bool event(TQEvent *); -%End private: TQApplication(const TQApplication &); @@ -471,19 +369,26 @@ static char **pyArgvToC(PyObject *argvlist,int &argc) // Convert the list. for (int a = 0; a < argc; ++a) { + PyObject *argObject = PyList_GET_ITEM(argvlist, a); char *arg; - // Get the argument and allocate memory for it. - if ((arg = PyString_AsString(PyList_GetItem(argvlist,a))) == NULL || - (argv[a] = (char *)sipMalloc(strlen(arg) + 1)) == NULL) + if (PyUnicode_Check(argObject)) + { + arg = tqstrdup(sipString_AsLatin1String(&argObject)); + } + else if (SIPBytes_Check(argObject)) + { + arg = tqstrdup(SIPBytes_AS_STRING(argObject)); + } + else + { return NULL; + } - // Copy the argument and save a pointer to it. - strcpy(argv[a],arg); - argv[a + argc + 1] = argv[a]; + argv[a] = argv[a + argc + 1] = arg; } - argv[argc + argc + 1] = argv[argc] = NULL; + argv[argc] = argv[argc + argc + 1] = NULL; return argv; } @@ -544,19 +449,7 @@ static void pyqtMsgHandler(TQtMsgType type, const char *msg) SIP_BLOCK_THREADS -#if SIP_VERSION >= 0x040200 res = sipCallMethod(0, pyqtPyMsgHandler, "Es", type, sipEnum_TQtMsgType, msg); -#elif SIP_VERSION >= 0x040000 - res = sipCallMethod(0, pyqtPyMsgHandler, "es", type, msg); -#else - PyObject *args = Py_BuildValue("is", type, msg); - - if (args != NULL) - { - res = PyEval_CallObject(pyqtPyMsgHandler, args); - Py_DECREF(args); - } -#endif Py_XDECREF(res); diff --git a/sip/qt/qarray.sip b/sip/qt/qarray.sip index a7c34b8..6ce411e 100644 --- a/sip/qt/qarray.sip +++ b/sip/qt/qarray.sip @@ -52,7 +52,7 @@ converted to and from Python lists of the type. // Get it. for (uint i = 0; i < sipCpp -> count(); ++i) - if (PyList_SetItem(l,i,PyInt_FromLong((long)(sipCpp -> at(i)))) < 0) + if (PyList_SetItem(l,i,PyLong_FromLong((long)(sipCpp -> at(i)))) < 0) { Py_DECREF(l); @@ -74,7 +74,7 @@ converted to and from Python lists of the type. for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) { - qa[i] = (int)PyInt_AsLong(PyList_GET_ITEM(sipPy,i)); + qa[i] = PyLong_AsLong(PyList_GET_ITEM(sipPy,i)); if (PyErr_Occurred() != NULL) { diff --git a/sip/qt/qbuttongroup.sip b/sip/qt/qbuttongroup.sip index 72d4009..e593e28 100644 --- a/sip/qt/qbuttongroup.sip +++ b/sip/qt/qbuttongroup.sip @@ -19,6 +19,7 @@ // PyTQt; see the file LICENSE. If not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +%DefaultEncoding "UTF-8" %ExportedDoc <Sect2><Title>TQButtonGroup</Title> diff --git a/sip/qt/qbytearray.sip b/sip/qt/qbytearray.sip index db5d266..d975472 100644 --- a/sip/qt/qbytearray.sip +++ b/sip/qt/qbytearray.sip @@ -98,6 +98,36 @@ class TQByteArray #include <tqstring.h> %End +%TypeCode +// Convert a TQByteArray to a Python string or Py_None if there's +// no data +static PyObject* TQByteArray_To_String(TQByteArray *ba) +{ + // TQByteArrays aren't '\0' terminated so set the size + // explicitly. + char *data; + uint len; + + Py_BEGIN_ALLOW_THREADS + data = ba->data(); + len = ba->size(); + Py_END_ALLOW_THREADS + + if (data) + { +#if PY_MAJOR_VERSION >= 3 + return PyUnicode_FromStringAndSize(data, len); +#else + return SIPBytes_FromStringAndSize(data, len); +#endif + } + else + { + return Py_None; + } +} +%End + public: TQByteArray(); TQByteArray(int); @@ -105,27 +135,20 @@ public: SIP_PYOBJECT data() const; %MethodCode - // TQByteArrays aren't '\0' terminated so set the size - // explicitly. - - char *res; - uint len; - - Py_BEGIN_ALLOW_THREADS - res = sipCpp -> data(); - len = sipCpp -> size(); - Py_END_ALLOW_THREADS + PyObject* res = TQByteArray_To_String(sipCpp); - if (res) + if (res == Py_None) { - if ((sipRes = PyString_FromStringAndSize(res,len)) == NULL) - sipIsErr = 1; + Py_INCREF(Py_None); } - else + else if (res == NULL) { - Py_INCREF(Py_None); - sipRes = Py_None; + sipIsErr = 1; } + else + { + sipRes = res; + } %End // These are actually in TQMemArray, which isn't implemented so pretend @@ -151,36 +174,62 @@ public: SIP_PYOBJECT __str__(); %MethodCode - // TQByteArrays aren't '\0' terminated so set the size - // explicitly. + PyObject* res = TQByteArray_To_String(sipCpp); - char *data; - uint len; - - Py_BEGIN_ALLOW_THREADS - data = sipCpp -> data(); - len = sipCpp -> size(); - Py_END_ALLOW_THREADS - - if (data == NULL) - sipRes = PyString_FromString(""); + if (res == Py_None) + { + sipRes = SIPBytes_FromString(""); + } else - sipRes = PyString_FromStringAndSize(data,len); + { + sipRes = res; + } %End + %ConvertToTypeCode // Allow a Python string whenever a TQByteArray is expected. if (sipIsErr == NULL) - return (PyString_Check(sipPy) || + return (SIPBytes_Check(sipPy) || + PyUnicode_Check(sipPy) || sipCanConvertToInstance(sipPy,sipClass_TQByteArray,SIP_NO_CONVERTORS)); - if (PyString_Check(sipPy)) + if (PyUnicode_Check(sipPy)) + { + Py_BEGIN_ALLOW_THREADS + TQByteArray *ba = new TQByteArray(); + +#if PY_VERSION_HEX >= 0x03030000 + ba -> duplicate((char *)PyUnicode_1BYTE_DATA(sipPy),PyUnicode_GET_SIZE(sipPy)); +#else + ba -> duplicate((char *)PyUnicode_AS_DATA(sipPy),PyUnicode_GET_SIZE(sipPy)); +#endif + *sipCppPtr = ba; + Py_END_ALLOW_THREADS + + return sipGetState(sipTransferObj); + } +#if PY_VERSION_HEX >= 0x02060000 + else if (PyByteArray_Check(sipPy)) { Py_BEGIN_ALLOW_THREADS TQByteArray *ba = new TQByteArray(); - ba -> duplicate(PyString_AS_STRING(sipPy),PyString_GET_SIZE(sipPy)); + ba -> duplicate(PyByteArray_AS_STRING(sipPy),PyByteArray_GET_SIZE(sipPy)); + + *sipCppPtr = ba; + Py_END_ALLOW_THREADS + + return sipGetState(sipTransferObj); + } +#endif + else if (SIPBytes_Check(sipPy)) + { + Py_BEGIN_ALLOW_THREADS + TQByteArray *ba = new TQByteArray(); + + ba -> duplicate(SIPBytes_AS_STRING(sipPy),SIPBytes_GET_SIZE(sipPy)); *sipCppPtr = ba; Py_END_ALLOW_THREADS @@ -195,9 +244,7 @@ public: }; -%If (TQt_3_1_0 -) TQByteArray tqCompress(const uchar * /Array/,int /ArraySize/); TQByteArray tqCompress(const TQByteArray &); TQByteArray tqUncompress(const uchar * /Array/,int /ArraySize/); TQByteArray tqUncompress(const TQByteArray &); -%End diff --git a/sip/qt/qcstring.sip b/sip/qt/qcstring.sip index 5e877e6..9f076b6 100644 --- a/sip/qt/qcstring.sip +++ b/sip/qt/qcstring.sip @@ -197,19 +197,19 @@ public: if (s == NULL) s = ""; - sipRes = PyString_FromString(s); + sipRes = SIPBytes_FromString(s); %End %ConvertToTypeCode // Allow a Python string whenever a TQCString is expected. if (sipIsErr == NULL) - return (PyString_Check(sipPy) || + return (SIPBytes_Check(sipPy) || sipCanConvertToInstance(sipPy,sipClass_TQCString,SIP_NO_CONVERTORS)); - if (PyString_Check(sipPy)) + if (SIPBytes_Check(sipPy)) { - *sipCppPtr = new TQCString(PyString_AS_STRING(sipPy)); + *sipCppPtr = new TQCString(SIPBytes_AS_STRING(sipPy)); return sipGetState(sipTransferObj); } diff --git a/sip/qt/qdragobject.sip b/sip/qt/qdragobject.sip index f258596..fbd5e29 100644 --- a/sip/qt/qdragobject.sip +++ b/sip/qt/qdragobject.sip @@ -20,6 +20,7 @@ // PyTQt; see the file LICENSE. If not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +%DefaultEncoding "UTF-8" %ExportedDoc <Sect2><Title>TQColorDrag (TQt v2.1+)</Title> diff --git a/sip/qt/qfile.sip b/sip/qt/qfile.sip index f11da7f..38d91c3 100644 --- a/sip/qt/qfile.sip +++ b/sip/qt/qfile.sip @@ -167,7 +167,7 @@ public: Py_INCREF(Py_None); sipRes = Py_None; } - else if ((sipRes = PyString_FromStringAndSize(buf,actlen)) == NULL) + else if ((sipRes = SIPBytes_FromStringAndSize(buf,actlen)) == NULL) sipIsErr = 1; sipFree((void *)buf); @@ -196,7 +196,7 @@ public: Py_INCREF(Py_None); sipRes = Py_None; } - else if ((sipRes = PyString_FromStringAndSize(buf,actlen)) == NULL) + else if ((sipRes = SIPBytes_FromStringAndSize(buf,actlen)) == NULL) sipIsErr = 1; sipFree((void *)buf); @@ -238,7 +238,7 @@ public: } else { - sipRes = PyString_FromStringAndSize(buf,actlen); + sipRes = SIPBytes_FromStringAndSize(buf,actlen); sipFree((void *)buf); @@ -272,7 +272,7 @@ public: } else { - sipRes = PyString_FromStringAndSize(buf,actlen); + sipRes = SIPBytes_FromStringAndSize(buf,actlen); sipFree((void *)buf); diff --git a/sip/qt/qfontmetrics.sip b/sip/qt/qfontmetrics.sip index 294aedb..9ab3d89 100644 --- a/sip/qt/qfontmetrics.sip +++ b/sip/qt/qfontmetrics.sip @@ -201,7 +201,7 @@ static int intListToArray(PyObject *pl,int **ap) for (i = 0; i < nint; ++i) { - *ip++ = PyInt_AsLong(PyList_GetItem(pl,i)); + *ip++ = PyLong_AsLong(PyList_GetItem(pl,i)); if (PyErr_Occurred()) { diff --git a/sip/qt/qimage.sip b/sip/qt/qimage.sip index dc2c85a..47f44a0 100644 --- a/sip/qt/qimage.sip +++ b/sip/qt/qimage.sip @@ -515,7 +515,7 @@ const char **PyTQt_qt_ListToArray(PyObject *lst); // TQPixmap. const char **PyTQt_qt_ListToArray(PyObject *lst) { - int nstr; + SIP_SSIZE_T nstr; const char **str, **sp; nstr = PyList_Size(lst); @@ -528,15 +528,16 @@ const char **PyTQt_qt_ListToArray(PyObject *lst) for (int i = 0; i < nstr; ++i) { - char *s; + PyObject *item = PyList_GetItem(lst, i); + const char *item_ascii = sipString_AsASCIIString(&item); - if ((s = PyString_AsString(PyList_GetItem(lst,i))) == NULL) + if (item_ascii == NULL) { sipFree((void *)str); return NULL; } - *sp++ = s; + *sp++ = item_ascii; } return str; diff --git a/sip/qt/qiodevice.sip b/sip/qt/qiodevice.sip index 2f1f491..4fbbb05 100644 --- a/sip/qt/qiodevice.sip +++ b/sip/qt/qiodevice.sip @@ -151,7 +151,7 @@ public: } else { - sipRes = PyString_FromStringAndSize(buf,actlen); + sipRes = SIPBytes_FromStringAndSize(buf,actlen); sipFree((void *)buf); @@ -171,15 +171,15 @@ public: if (buf == Py_None) sipRes = -1; - else if (!PyString_Check(buf)) + else if (!SIPBytes_Check(buf)) { sipBadCatcherResult(sipMethod); sipIsErr = 1; } else { - memcpy(a0,PyString_AS_STRING(buf),PyString_GET_SIZE(buf)); - sipRes = PyString_GET_SIZE(buf); + memcpy(a0,SIPBytes_AS_STRING(buf),SIPBytes_GET_SIZE(buf)); + sipRes = SIPBytes_GET_SIZE(buf); } Py_DECREF(buf); @@ -211,7 +211,7 @@ public: } else { - sipRes = PyString_FromStringAndSize(buf,actlen); + sipRes = SIPBytes_FromStringAndSize(buf,actlen); sipFree((void *)buf); @@ -231,15 +231,15 @@ public: if (buf == Py_None) sipRes = -1L; - else if (!PyString_Check(buf)) + else if (!SIPBytes_Check(buf)) { sipBadCatcherResult(sipMethod); sipIsErr = 1; } else { - memcpy(a0,PyString_AS_STRING(buf),PyString_GET_SIZE(buf)); - sipRes = PyString_GET_SIZE(buf); + memcpy(a0,SIPBytes_AS_STRING(buf),SIPBytes_GET_SIZE(buf)); + sipRes = SIPBytes_GET_SIZE(buf); } Py_DECREF(buf); @@ -281,7 +281,7 @@ public: } else { - sipRes = PyString_FromStringAndSize(buf,actlen); + sipRes = SIPBytes_FromStringAndSize(buf,actlen); sipFree((void *)buf); @@ -301,15 +301,15 @@ public: if (buf == Py_None) sipRes = -1; - else if (!PyString_Check(buf)) + else if (!SIPBytes_Check(buf)) { sipBadCatcherResult(sipMethod); sipIsErr = 1; } else { - memcpy(a0,PyString_AS_STRING(buf),PyString_GET_SIZE(buf)); - sipRes = PyString_GET_SIZE(buf); + memcpy(a0,SIPBytes_AS_STRING(buf),SIPBytes_GET_SIZE(buf)); + sipRes = SIPBytes_GET_SIZE(buf); } Py_DECREF(buf); @@ -341,7 +341,7 @@ public: } else { - sipRes = PyString_FromStringAndSize(buf,actlen); + sipRes = SIPBytes_FromStringAndSize(buf,actlen); sipFree((void *)buf); @@ -361,15 +361,15 @@ public: if (buf == Py_None) sipRes = -1L; - else if (!PyString_Check(buf)) + else if (!SIPBytes_Check(buf)) { sipBadCatcherResult(sipMethod); sipIsErr = 1; } else { - memcpy(a0,PyString_AS_STRING(buf),PyString_GET_SIZE(buf)); - sipRes = PyString_GET_SIZE(buf); + memcpy(a0,SIPBytes_AS_STRING(buf),SIPBytes_GET_SIZE(buf)); + sipRes = SIPBytes_GET_SIZE(buf); } Py_DECREF(buf); diff --git a/sip/qt/qkeysequence.sip b/sip/qt/qkeysequence.sip index 8d8e32e..9293ffe 100644 --- a/sip/qt/qkeysequence.sip +++ b/sip/qt/qkeysequence.sip @@ -71,7 +71,7 @@ public: PyErr_Clear(); - PyInt_AsLong(sipPy); + PyLong_AsLong(sipPy); return !PyErr_Occurred(); } @@ -106,7 +106,7 @@ public: return sipGetState(sipTransferObj); } - int key = PyInt_AsLong(sipPy); + int key = (int)PyLong_AsLong(sipPy); Py_BEGIN_ALLOW_THREADS *sipCppPtr = new TQKeySequence(key); diff --git a/sip/qt/qlabel.sip b/sip/qt/qlabel.sip index 99ac8ac..a19541e 100644 --- a/sip/qt/qlabel.sip +++ b/sip/qt/qlabel.sip @@ -19,6 +19,7 @@ // PyTQt; see the file LICENSE. If not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +%DefaultEncoding "UTF-8" %ExportedDoc <Sect2><Title>TQLabel</Title> diff --git a/sip/qt/qlcdnumber.sip b/sip/qt/qlcdnumber.sip index c071f50..2127210 100644 --- a/sip/qt/qlcdnumber.sip +++ b/sip/qt/qlcdnumber.sip @@ -19,6 +19,7 @@ // PyTQt; see the file LICENSE. If not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +%DefaultEncoding "UTF-8" %ExportedDoc <Sect2><Title>TQLCDNumber</Title> diff --git a/sip/qt/qlistview.sip b/sip/qt/qlistview.sip index d7ef8a1..fa2a5ab 100644 --- a/sip/qt/qlistview.sip +++ b/sip/qt/qlistview.sip @@ -56,91 +56,6 @@ call <Literal>takeItem()</Literal> and then <Literal>del()</Literal>. %End -%If (- TQt_2_00) - -class TQListViewItem -{ -%TypeHeaderCode -#include <tqlistview.h> -%End - -public: - TQListViewItem(TQListView * /TransferThis/); - TQListViewItem(TQListViewItem * /TransferThis/); - TQListViewItem(TQListView * /TransferThis/,TQListViewItem *); - TQListViewItem(TQListViewItem * /TransferThis/,TQListViewItem *); - - TQListViewItem(TQListView * /TransferThis/, - const char *,const char * = 0, - const char * = 0,const char * = 0, - const char * = 0,const char * = 0, - const char * = 0,const char * = 0); - - TQListViewItem(TQListViewItem * /TransferThis/, - const char *,const char * = 0, - const char * = 0,const char * = 0, - const char * = 0,const char * = 0, - const char * = 0,const char * = 0); - - TQListViewItem(TQListView * /TransferThis/,TQListViewItem *, - const char *,const char * = 0, - const char * = 0,const char * = 0, - const char * = 0,const char * = 0, - const char * = 0,const char * = 0); - - TQListViewItem(TQListViewItem * /TransferThis/,TQListViewItem *, - const char *,const char * = 0, - const char * = 0,const char * = 0, - const char * = 0,const char * = 0, - const char * = 0,const char * = 0); - - virtual void insertItem(TQListViewItem * /Transfer/); - virtual void removeItem(TQListViewItem * /TransferBack/); - int height() const; - virtual void invalidateHeight(); - int totalHeight() const; - virtual int width(const TQFontMetrics &,const TQListView *,int) const; - void widthChanged(int = -1) const; - int depth() const; - virtual void setText(int,const char *); - virtual const char *text(int) const; - virtual void setPixmap(int,const TQPixmap &); - virtual const TQPixmap *pixmap(int) const; - virtual const char *key(int,bool) const; - virtual void sortChildItems(int,bool); - int childCount() const; - bool isOpen() const; - virtual void setOpen(bool); - virtual void setup(); - virtual void setSelected(bool); - bool isSelected() const; - virtual void paintCell(TQPainter *,const TQColorGroup &,int,int,int); - virtual void paintBranches(TQPainter *,const TQColorGroup &,int,int,int, - GUIStyle); - virtual void paintFocus(TQPainter *,const TQColorGroup &,const TQRect &); - TQListViewItem *firstChild() const; - TQListViewItem *nextSibling() const; - TQListViewItem *parent() const; - TQListViewItem *itemAbove(); - TQListViewItem *itemBelow(); - int itemPos() const; - TQListView *listView() const; - virtual void setSelectable(bool); - bool isSelectable() const; - virtual void setExpandable(bool); - bool isExpandable(); - void repaint() const; - -protected: - virtual void enforceSortOrder() const; - virtual void setHeight(int); - virtual void activate(); -}; - -%End - -%If (TQt_2_00 -) - class TQListViewItem : TQt { %TypeHeaderCode @@ -194,9 +109,7 @@ public: virtual const TQPixmap *pixmap(int) const; virtual TQString key(int,bool) const; -%If (TQt_3_0_0 -) virtual int compare(TQListViewItem *,int,bool) const; -%End virtual void sortChildItems(int,bool); int childCount() const; @@ -209,13 +122,7 @@ public: bool isSelected() const; virtual void paintCell(TQPainter *,const TQColorGroup &,int,int,int); -%If (- TQt_3_0_0) - virtual void paintBranches(TQPainter *,const TQColorGroup &,int,int,int, - GUIStyle); -%End -%If (TQt_3_0_0 -) virtual void paintBranches(TQPainter *,const TQColorGroup &,int,int,int); -%End virtual void paintFocus(TQPainter *,const TQColorGroup &,const TQRect &); TQListViewItem *firstChild() const; @@ -237,17 +144,9 @@ public: void repaint() const; -%If (TQt_2_1_0 - TQt_3_0_0) - void sort(); -%End -%If (TQt_3_0_0 -) virtual void sort(); -%End -%If (TQt_2_2_0 -) void moveItem(TQListViewItem *); -%End -%If (TQt_3_0_0 -) virtual void setDragEnabled(bool); virtual void setDropEnabled(bool); bool dragEnabled() const; @@ -268,17 +167,13 @@ public: virtual void setMultiLinesEnabled(bool); bool multiLinesEnabled() const; -%End protected: virtual void enforceSortOrder() const; virtual void setHeight(int); virtual void activate(); -%If (TQt_2_1_0 -) bool activatedPos(TQPoint &); -%End -%If (TQt_3_0_0 -) virtual void dropped(TQDropEvent *); virtual void dragEntered(); virtual void dragLeft(); @@ -286,11 +181,8 @@ protected: virtual void cancelRename(int); void ignoreDoubleClick(); -%End }; -%End - class TQListView : TQScrollView { @@ -299,44 +191,22 @@ class TQListView : TQScrollView %End public: -%If (TQt_2_2_0 - TQt_3_0_0) - TQListView(TQWidget * /TransferThis/,const char *,WFlags); -%End -%If (- TQt_3_0_0) - TQListView(TQWidget * /TransferThis/ = 0,const char * = 0); -%End -%If (TQt_3_0_0 -) TQListView(TQWidget * /TransferThis/ = 0,const char * = 0,WFlags = 0); -%End int treeStepSize() const; virtual void setTreeStepSize(int); virtual void insertItem(TQListViewItem * /Transfer/); -%If (TQt_2_00 -) virtual void takeItem(TQListViewItem * /TransferBack/); -%End -%If (- TQt_3_0_0) - virtual void clear(); -%End TQHeader *header() const; -%If (- TQt_2_00) - virtual int addColumn(const char *,int = -1); - virtual void setColumnText(int,const char *); - const char *columnText(int) const; -%End -%If (TQt_2_00 -) virtual int addColumn(const TQString &,int = -1); virtual int addColumn(const TQIconSet &,const TQString &,int = -1); -%If (TQt_2_1_0 -) void removeColumn(int); -%End virtual void setColumnText(int,const TQString &); virtual void setColumnText(int,const TQIconSet &,const TQString &); TQString columnText(int) const; -%End virtual void setColumnWidth(int,int); int columnWidth(int) const; @@ -348,9 +218,7 @@ public: virtual void setColumnWidthMode(int,WidthMode); WidthMode columnWidthMode(int) const; -%If (TQt_2_1_0 -) int columns() const; -%End virtual void setColumnAlignment(int,int); int columnAlignment(int) const; @@ -368,7 +236,6 @@ public: virtual void setMultiSelection(bool); bool isMultiSelection() const; -%If (TQt_2_1_0 -) enum SelectionMode { Single, Multi, @@ -378,19 +245,12 @@ public: void setSelectionMode(SelectionMode); SelectionMode selectionMode() const; -%End -%If (TQt_2_1_0 -) virtual void clearSelection(); -%End virtual void setSelected(TQListViewItem *,bool); -%If (TQt_3_2_0 -) void setSelectionAnchor(TQListViewItem *); -%End bool isSelected(TQListViewItem *) const; -%If (TQt_2_1_0 -) TQListViewItem *selectedItem() const; -%End virtual void setOpen(TQListViewItem *,bool); bool isOpen(TQListViewItem *) const; @@ -398,9 +258,7 @@ public: TQListViewItem *currentItem() const; TQListViewItem *firstChild() const; -%If (TQt_3_0_0 -) TQListViewItem *lastItem() const; -%End int childCount() const; @@ -414,43 +272,22 @@ public: bool rootIsDecorated() const; virtual void setSorting(int,bool = 1); -%If (TQt_3_1_0 -) int sortColumn() const; -%End -%If (TQt_3_2_0 -) void setSortColumn(int); SortOrder sortOrder() const; void setSortOrder(SortOrder); -%End -%If (TQt_3_0_0 -) virtual void sort(); -%End -%If (TQt_2_1_0 - TQt_3_0_0) - void sort(); -%End -%If (- TQt_2_00) - void setStyle(GUIStyle); - void setFont(const TQFont &); - void setPalette(const TQPalette &); -%End -%If (TQt_2_00 -) virtual void setFont(const TQFont &); virtual void setPalette(const TQPalette &); -%End bool eventFilter(TQObject *,TQEvent *); TQSize sizeHint() const; -%If (TQt_2_00 -) TQSize minimumSizeHint() const; -%End -%If (TQt_2_1_0 -) void setShowSortIndicator(bool); bool showSortIndicator() const; -%End -%If (TQt_3_0_0 -) virtual void setShowToolTips(bool); bool showToolTips() const; @@ -474,83 +311,51 @@ public: virtual void setDefaultRenameAction(RenameAction); RenameAction defaultRenameAction() const; bool isRenaming() const; -%End -%If (TQt_3_2_0 -) void hideColumn(int); -%End public slots: -%If (TQt_3_0_0 -) virtual void clear(); -%End -%If (TQt_2_1_0 -) void invertSelection(); void selectAll(bool); void setContentsPos(int,int); -%End void triggerUpdate(); -%If (TQt_3_2_0 -) void adjustColumn(int); -%End signals: void selectionChanged(); void selectionChanged(TQListViewItem *); void currentChanged(TQListViewItem *); -%If (TQt_2_1_0 -) void clicked(TQListViewItem *); void clicked(TQListViewItem *,const TQPoint &,int); void pressed(TQListViewItem *); void pressed(TQListViewItem *,const TQPoint &,int); -%End void doubleClicked(TQListViewItem *); -%If (TQt_3_2_0 -) void doubleClicked(TQListViewItem *,const TQPoint &,int); -%End void returnPressed(TQListViewItem *); -%If (TQt_3_0_0 -) void spacePressed(TQListViewItem *); -%End void rightButtonClicked(TQListViewItem *,const TQPoint &,int); void rightButtonPressed(TQListViewItem *,const TQPoint &,int); -%If (TQt_2_1_0 -) void mouseButtonPressed(int,TQListViewItem *,const TQPoint &,int); void mouseButtonClicked(int,TQListViewItem *,const TQPoint &,int); -%End -%If (TQt_3_0_0 -) void contextMenuRequested(TQListViewItem *,const TQPoint &,int); -%End -%If (TQt_2_1_0 -) void onItem(TQListViewItem *); void onViewport(); void expanded(TQListViewItem *); void collapsed(TQListViewItem *); -%End -%If (TQt_3_0_0 -) void dropped(TQDropEvent *); void itemRenamed(TQListViewItem *,int,const TQString &); void itemRenamed(TQListViewItem *,int); -%End protected: -%If (- TQt_2_00) - void mousePressEvent(TQMouseEvent *); - void mouseReleaseEvent(TQMouseEvent *); - void mouseMoveEvent(TQMouseEvent *); - void mouseDoubleClickEvent(TQMouseEvent *); -%End -%If (TQt_2_00 -) void contentsMousePressEvent(TQMouseEvent *); void contentsMouseReleaseEvent(TQMouseEvent *); void contentsMouseMoveEvent(TQMouseEvent *); void contentsMouseDoubleClickEvent(TQMouseEvent *); -%End -%If (TQt_3_0_0 -) void contentsContextMenuEvent(TQContextMenuEvent *); void contentsDragEnterEvent(TQDragEnterEvent *); void contentsDragMoveEvent(TQDragMoveEvent *); @@ -558,7 +363,6 @@ protected: void contentsDropEvent(TQDropEvent *); virtual TQDragObject *dragObject(); virtual void startDrag(); -%End void focusInEvent(TQFocusEvent *); void focusOutEvent(TQFocusEvent *); @@ -566,37 +370,22 @@ protected: void keyPressEvent(TQKeyEvent *); void resizeEvent(TQResizeEvent *); -%If (TQt_3_0_0 -) void viewportResizeEvent(TQResizeEvent *); -%End -%If (TQt_2_00 -) void showEvent(TQShowEvent *); -%End void drawContentsOffset(TQPainter *,int,int,int,int,int,int); virtual void paintEmptyArea(TQPainter *,const TQRect &); -%If (TQt_2_00 -) void styleChange(TQStyle &); -%End -%If (- TQt_3_0_0) - void enabledChange(bool); -%End -%If (TQt_3_0_0 -) void windowActivationChange(bool); -%End protected slots: void updateContents(); -%If (TQt_2_00 -) void doAutoScroll(); -%End private: -%If (TQt_2_1_0 -) TQListView(const TQWidget &); -%End }; @@ -611,21 +400,16 @@ public: RadioButton, CheckBox, Controller, -%If (TQt_3_2_0 -) RadioButtonController, CheckBoxController, -%End }; -%If (TQt_3_2_0 -) enum ToggleState { Off, NoChange, On }; -%End -%If (TQt_3_2_0 -) TQCheckListItem(TQCheckListItem * /TransferThis/,const TQString &, Type = RadioButtonController); TQCheckListItem(TQCheckListItem * /TransferThis/,TQListViewItem *, @@ -638,91 +422,36 @@ public: Type = RadioButtonController); TQCheckListItem(TQListView * /TransferThis/,TQListViewItem *, const TQString &,Type = RadioButtonController); -%End -%If (TQt_2_00 - TQt_3_2_0) - TQCheckListItem(TQCheckListItem * /TransferThis/,const TQString &, - Type = Controller); -%If (TQt_3_1_0 -) - TQCheckListItem(TQCheckListItem * /TransferThis/,TQListViewItem *, - const TQString &,Type = Controller); -%End - TQCheckListItem(TQListViewItem * /TransferThis/,const TQString &, - Type = Controller); -%If (TQt_3_1_0 -) - TQCheckListItem(TQListViewItem * /TransferThis/,TQListViewItem *, - const TQString &,Type = Controller); -%End - TQCheckListItem(TQListView * /TransferThis/,const TQString &, - Type = Controller); -%If (TQt_3_1_0 -) - TQCheckListItem(TQListView * /TransferThis/,TQListViewItem *, - const TQString &,Type = Controller); -%End -%End -%If (TQt_2_00 -) TQCheckListItem(TQListViewItem * /TransferThis/,const TQString &, const TQPixmap &); TQCheckListItem(TQListView * /TransferThis/,const TQString &, const TQPixmap &); -%End -%If (- TQt_2_00) - TQCheckListItem(TQCheckListItem * /TransferThis/,const char *, - Type = Controller); - TQCheckListItem(TQListView * /TransferThis/,const char *, - Type = Controller); - TQCheckListItem(TQListViewItem * /TransferThis/,const char *, - const TQPixmap &); - TQCheckListItem(TQListView * /TransferThis/,const char *, - const TQPixmap &); -%End void paintCell(TQPainter *,const TQColorGroup &,int,int,int); -%If (TQt_2_00 -) virtual void paintFocus(TQPainter *,const TQColorGroup &,const TQRect &); -%End int width(const TQFontMetrics &,const TQListView *,int) const; void setup(); -%If (- TQt_2_00) - void setOn(bool); -%End -%If (TQt_2_00 -) virtual void setOn(bool); -%End bool isOn() const; Type type() const; -%If (- TQt_2_00) - const char *text() const; - const char *text(int) const; -%End -%If (TQt_2_00 -) TQString text() const; TQString text(int) const; -%End -%If (TQt_3_2_0 -) void setTristate(bool); bool isTristate() const; ToggleState state() const; void setState(ToggleState); -%End -%If (TQt_3_0_0 -) int rtti() const; -%End protected: -%If (- TQt_3_0_0) - void paintBranches(TQPainter *,const TQColorGroup &,int,int,int,GUIStyle); -%End void activate(); void turnOffChild(); virtual void stateChange(bool); }; -%If (TQt_2_00 -) - class TQListViewItemIterator { %TypeHeaderCode @@ -730,7 +459,6 @@ class TQListViewItemIterator %End public: -%If (TQt_3_2_0 -) enum IteratorFlag { Visible, Invisible, @@ -747,24 +475,17 @@ public: Checked, NotChecked }; -%End TQListViewItemIterator(); TQListViewItemIterator(TQListViewItem *); -%If (TQt_3_2_0 -) TQListViewItemIterator(TQListViewItem *,int); -%End TQListViewItemIterator(const TQListViewItemIterator &); TQListViewItemIterator(TQListView *); -%If (TQt_3_2_0 -) TQListViewItemIterator(TQListView *,int); -%End TQListViewItemIterator &operator+=(int); TQListViewItemIterator &operator-=(int); TQListViewItem *current() const; }; - -%End diff --git a/sip/qt/qmainwindow.sip b/sip/qt/qmainwindow.sip index ca21ec4..19535ca 100644 --- a/sip/qt/qmainwindow.sip +++ b/sip/qt/qmainwindow.sip @@ -19,6 +19,7 @@ // PyTQt; see the file LICENSE. If not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +%DefaultEncoding "UTF-8" %ExportedDoc <Sect2><Title>TQMainWindow</Title> diff --git a/sip/qt/qmemarray.sip b/sip/qt/qmemarray.sip index 5fc5d02..d7a4a7b 100644 --- a/sip/qt/qmemarray.sip +++ b/sip/qt/qmemarray.sip @@ -50,7 +50,7 @@ converted to and from Python lists of the type. // Get it. for (uint i = 0; i < sipCpp -> size(); ++i) - if (PyList_SetItem(l,i,PyInt_FromLong((long)sipCpp -> at(i))) < 0) + if (PyList_SetItem(l,i,PyLong_FromLong((long)sipCpp -> at(i))) < 0) { Py_DECREF(l); @@ -72,7 +72,7 @@ converted to and from Python lists of the type. for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) { - (*qma)[i] = (int)PyInt_AsLong(PyList_GET_ITEM(sipPy,i)); + (*qma)[i] = (int)PyLong_AsLong(PyList_GET_ITEM(sipPy,i)); if (PyErr_Occurred() != NULL) { diff --git a/sip/qt/qobject.sip b/sip/qt/qobject.sip index 2ce5778..0f3a23e 100644 --- a/sip/qt/qobject.sip +++ b/sip/qt/qobject.sip @@ -403,7 +403,11 @@ public: // the true (Python) class name. SIP_PYOBJECT className() const; %MethodCode +#if PY_MAJOR_VERSION >= 3 + sipRes = PyUnicode_FromString(sipSelf->ob_type->tp_name); +#else sipRes = sipClassName(sipSelf); +#endif %End %If (- TQt_3_0_0) @@ -425,49 +429,69 @@ public: // trUtf8() methods for a Python sub-class instance in the sub-class's // ctor. - TQString tr(const char *,const char * = 0); + TQString tr(SIP_PYOBJECT sourceText /TypeHint="str"/,const char * = 0); %MethodCode - PyObject *nmobj; + if (tqApp) + { + const char *source = PyTQt_qt_encode(&a0, TQApplication::DefaultCodec); - if ((nmobj = sipClassName(sipSelf)) == NULL) - sipIsErr = 1; + if (source) + { + sipRes = new TQString(tqApp->translate(Py_TYPE(sipSelf)->tp_name, source, + a1, TQApplication::DefaultCodec)); + Py_DECREF(a0); + } + else + { + sipIsErr = 1; + } + } else { - char *cname = PyString_AsString(nmobj); + const char *source = sipString_AsLatin1String(&a0); - Py_BEGIN_ALLOW_THREADS - - if (cname && tqApp) - sipRes = new TQString(tqApp -> translate(cname,a0,a1,TQApplication::DefaultCodec)); + if (source) + { + sipRes = new TQString(QString::fromLatin1(source)); + Py_DECREF(a0); + } else - sipRes = new TQString(TQString::fromLatin1(a0)); - - Py_END_ALLOW_THREADS - - Py_DECREF(nmobj); + { + sipIsErr = 1; + } } %End - TQString trUtf8(const char *,const char * = 0); + TQString trUtf8(SIP_PYOBJECT sourceText /TypeHint="str"/,const char * = 0); %MethodCode - PyObject *nmobj; + if (tqApp) + { + const char *source = PyTQt_qt_encode(&a0, TQApplication::DefaultCodec); - if ((nmobj = sipClassName(sipSelf)) == NULL) - sipIsErr = 1; + if (source) + { + sipRes = new TQString(tqApp->translate(Py_TYPE(sipSelf)->tp_name, source, + a1, TQApplication::UnicodeUTF8)); + Py_DECREF(a0); + } + else + { + sipIsErr = 1; + } + } else { - char *cname = PyString_AsString(nmobj); - - Py_BEGIN_ALLOW_THREADS + const char *source = sipString_AsLatin1String(&a0); - if (cname && tqApp) - sipRes = new TQString(tqApp -> translate(cname,a0,a1,TQApplication::UnicodeUTF8)); + if (source) + { + sipRes = new TQString(TQString::fromLatin1(source)); + Py_DECREF(a0); + } else - sipRes = new TQString(TQString::fromUtf8(a0)); - - Py_END_ALLOW_THREADS - - Py_DECREF(nmobj); + { + sipIsErr = 1; + } } %End %End @@ -811,7 +835,11 @@ public: // it we can ignore it. SIP_PYOBJECT className() const; %MethodCode +#if PY_MAJOR_VERSION >= 3 + sipRes = PyUnicode_FromString(sipSelf->ob_type->tp_name); +#else sipRes = sipClassName(sipSelf); +#endif %End bool isA(const char *) const; @@ -866,7 +894,7 @@ private: %End -SIP_PYOBJECT SLOT(const char *); +SIP_PYOBJECT SLOT(const char * /Encoding="ASCII"/) /TypeHint="QT_SLOT"/; %MethodCode if (!a0) { @@ -877,11 +905,11 @@ SIP_PYOBJECT SLOT(const char *); { int len = strlen(a0); - if ((sipRes = PyString_FromStringAndSize(NULL,1 + len)) == NULL) + if ((sipRes = SIPBytes_FromStringAndSize(NULL,1 + len)) == NULL) sipIsErr = 1; else { - char *dp = PyString_AS_STRING(sipRes); + char *dp = SIPBytes_AS_STRING(sipRes); *dp++ = '1'; @@ -891,7 +919,7 @@ SIP_PYOBJECT SLOT(const char *); %End -SIP_PYOBJECT SIGNAL(const char *); +SIP_PYOBJECT SIGNAL(const char * /Encoding="ASCII"/) /TypeHint="QT_SIGNAL"/; %MethodCode if (!a0) { @@ -902,11 +930,11 @@ SIP_PYOBJECT SIGNAL(const char *); { int len = strlen(a0); - if ((sipRes = PyString_FromStringAndSize(NULL,1 + len)) == NULL) + if ((sipRes = SIPBytes_FromStringAndSize(NULL,1 + len)) == NULL) sipIsErr = 1; else { - char *dp = PyString_AS_STRING(sipRes); + char *dp = SIPBytes_AS_STRING(sipRes); *dp++ = '2'; @@ -916,7 +944,7 @@ SIP_PYOBJECT SIGNAL(const char *); %End -SIP_PYOBJECT PYSIGNAL(const char *); +SIP_PYOBJECT PYSIGNAL(const char * /Encoding="ASCII"/); %MethodCode if (!a0) { @@ -927,11 +955,11 @@ SIP_PYOBJECT PYSIGNAL(const char *); { int len = strlen(a0); - if ((sipRes = PyString_FromStringAndSize(NULL,1 + len)) == NULL) + if ((sipRes = SIPBytes_FromStringAndSize(NULL,1 + len)) == NULL) sipIsErr = 1; else { - char *dp = PyString_AS_STRING(sipRes); + char *dp = SIPBytes_AS_STRING(sipRes); *dp++ = '9'; @@ -992,16 +1020,30 @@ extern "C" { // The meta-type for PyTQt classes. It is just a marker type so that we can // safely cast to get access to PyTQt3-specific data structures. PyTypeObject pyqtWrapperType_Type = { +#if PY_MAJOR_VERSION >= 3 + PyVarObject_HEAD_INIT(NULL, 0) +#else PyObject_HEAD_INIT(NULL) 0, /* ob_size */ +#endif "qt.pyqtWrapperType", /* tp_name */ sizeof (sipWrapperType), /* tp_basicsize */ 0, /* tp_itemsize */ 0, /* tp_dealloc */ +#if PY_VERSION_HEX >= 0x03080000 + 0, /* tp_vectorcall_offset */ +#else 0, /* tp_print */ +#endif 0, /* tp_getattr */ 0, /* tp_setattr */ +#if PY_VERSION_HEX >= 0x03050000 + 0, /* tp_as_async */ +#elif PY_VERSION_HEX >= 0x03010000 + 0, /* tp_reserved */ +#else 0, /* tp_compare */ +#endif 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -1042,6 +1084,15 @@ PyTypeObject pyqtWrapperType_Type = { #if PY_VERSION_HEX >= 0x02060000 0, /* tp_version_tag */ #endif +#if PY_VERSION_HEX >= 0x03040000 + 0, /* tp_finalize */ +#endif +#if PY_VERSION_HEX >= 0x03080000 + 0, /* tp_vectorcall */ +#endif +#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 8 + 0, /* tp_print (deprecated) */ +#endif }; @@ -1196,16 +1247,30 @@ static sipWrapperType pyqtWrapper_Type = { { #endif { +#if PY_MAJOR_VERSION >= 3 + PyVarObject_HEAD_INIT(&pyqtWrapperType_Type, 0) +#else PyObject_HEAD_INIT(&pyqtWrapperType_Type) 0, /* ob_size */ +#endif "qt.pyqtWrapper", /* tp_name */ sizeof (pyqtWrapper), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)pyqtWrapper_dealloc, /* tp_dealloc */ +#if PY_VERSION_HEX >= 0x03080000 + 0, /* tp_vectorcall_offset */ +#else 0, /* tp_print */ +#endif 0, /* tp_getattr */ 0, /* tp_setattr */ +#if PY_VERSION_HEX >= 0x03050000 + 0, /* tp_as_async */ +#elif PY_VERSION_HEX >= 0x03010000 + 0, /* tp_reserved */ +#else 0, /* tp_compare */ +#endif 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -1246,6 +1311,15 @@ static sipWrapperType pyqtWrapper_Type = { #if PY_VERSION_HEX >= 0x02060000 0, /* tp_version_tag */ #endif +#if PY_VERSION_HEX >= 0x03040000 + 0, /* tp_finalize */ +#endif +#if PY_VERSION_HEX >= 0x03080000 + 0, /* tp_vectorcall */ +#endif +#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 8 + 0, /* tp_print (deprecated) */ +#endif }, #if !defined(STACKLESS) }, @@ -1500,17 +1574,17 @@ bool UniversalSlot::tqt_invoke(int id, TQUObject *qargs) case char_sat: case schar_sat: case uchar_sat: - arg = PyString_FromStringAndSize((char *)static_QUType_ptr.get(qargs), 1); + arg = SIPBytes_FromStringAndSize((char *)static_QUType_ptr.get(qargs), 1); break; case string_sat: case sstring_sat: case ustring_sat: - arg = PyString_FromString((char *)static_QUType_ptr.get(qargs)); + arg = SIPBytes_FromString((char *)static_QUType_ptr.get(qargs)); break; case short_sat: - arg = PyInt_FromLong(*(short *)static_QUType_ptr.get(qargs)); + arg = PyLong_FromLong(*(short *)static_QUType_ptr.get(qargs)); break; case ushort_sat: @@ -1519,9 +1593,9 @@ bool UniversalSlot::tqt_invoke(int id, TQUObject *qargs) case int_sat: if (qv) - arg = PyInt_FromLong(qv -> asInt()); + arg = PyLong_FromLong(qv -> asInt()); else - arg = PyInt_FromLong(static_QUType_int.get(qargs)); + arg = PyLong_FromLong(static_QUType_int.get(qargs)); break; case uint_sat: @@ -1557,7 +1631,7 @@ bool UniversalSlot::tqt_invoke(int id, TQUObject *qargs) break; case bool_sat: - arg = PyInt_FromLong(static_QUType_bool.get(qargs)); + arg = PyLong_FromLong(static_QUType_bool.get(qargs)); break; case void_sat: @@ -1628,7 +1702,14 @@ static void *sipTQtCreateUniversalSlot(sipWrapper *tx, const char *sig, pyqt3SlotConnection conn; /* Initialise the connection. */ - conn.sc_transmitter = (tx ? sipGetCppPtr((sipSimpleWrapper *)tx, 0) : 0); + if (sipGetAddress(&tx->super) == NULL) + { + conn.sc_transmitter = 0; + } + else + { + conn.sc_transmitter = (tx ? sipGetCppPtr(&tx->super, 0) : 0); + } /* Save the real slot. */ if (sipSaveSlot(&conn.sc_slot, rxObj, slot) < 0) diff --git a/sip/qt/qpainter.sip b/sip/qt/qpainter.sip index 15ef70b..17c359f 100644 --- a/sip/qt/qpainter.sip +++ b/sip/qt/qpainter.sip @@ -289,7 +289,7 @@ public: do { - if (PyList_SetItem(sipRes,len,PyInt_FromLong((long)*tp)) < 0) + if (PyList_SetItem(sipRes,len,PyLong_FromLong((long)*tp)) < 0) { Py_DECREF(sipRes); sipIsErr = 1; @@ -316,11 +316,11 @@ public: { // Convert the list. - int *tp = tabs; + long *tp = tabs; for (int i = 0; i < len; ++i) { - *tp++ = (int)PyInt_AsLong(PyList_GET_ITEM(a0,i)); + *tp++ = PyLong_AsLong(PyList_GET_ITEM(a0,i)); if (PyErr_Occurred() != NULL) { @@ -612,7 +612,7 @@ public: do { - if (PyList_SetItem(sipRes,len,PyInt_FromLong((long)*tp)) < 0) + if (PyList_SetItem(sipRes,len,PyLong_FromLong((long)*tp)) < 0) { Py_DECREF(sipRes); sipIsErr = 1; @@ -643,7 +643,7 @@ public: for (int i = 0; i < len; ++i) { - *tp++ = (int)PyInt_AsLong(PyList_GET_ITEM(a0,i)); + *tp++ = (int)PyLong_AsLong(PyList_GET_ITEM(a0,i)); if (PyErr_Occurred() != NULL) { diff --git a/sip/qt/qpair.sip b/sip/qt/qpair.sip index 22de053..5065d2a 100644 --- a/sip/qt/qpair.sip +++ b/sip/qt/qpair.sip @@ -51,8 +51,8 @@ converted to and from Python tuples of two elements. // Fill it. - PyTuple_SET_ITEM(t,0,PyInt_FromLong((long)sipCpp -> first)); - PyTuple_SET_ITEM(t,1,PyInt_FromLong((long)sipCpp -> second)); + PyTuple_SET_ITEM(t,0,PyLong_FromLong((long)sipCpp -> first)); + PyTuple_SET_ITEM(t,1,PyLong_FromLong((long)sipCpp -> second)); return t; %End @@ -65,8 +65,8 @@ converted to and from Python tuples of two elements. PyErr_Clear(); - int fst = (int)PyInt_AsLong(PyTuple_GET_ITEM(sipPy,0)); - int sec = (int)PyInt_AsLong(PyTuple_GET_ITEM(sipPy,1)); + int fst = (int)PyLong_AsLong(PyTuple_GET_ITEM(sipPy,0)); + int sec = (int)PyLong_AsLong(PyTuple_GET_ITEM(sipPy,1)); if (PyErr_Occurred() != NULL) { diff --git a/sip/qt/qpointarray.sip b/sip/qt/qpointarray.sip index 959963a..5112a2f 100644 --- a/sip/qt/qpointarray.sip +++ b/sip/qt/qpointarray.sip @@ -109,7 +109,7 @@ static TQCOORD *getPoints(int nrpnts,PyObject *pntlist) for (int i = 0; i < nrpnts; ++i) { - *pp++ = (TQCOORD)PyInt_AsLong(PyList_GetItem(pntlist,i)); + *pp++ = (TQCOORD)PyLong_AsLong(PyList_GetItem(pntlist,i)); if (PyErr_Occurred() != NULL) { diff --git a/sip/qt/qpushbutton.sip b/sip/qt/qpushbutton.sip index 69e961d..4fb26b1 100644 --- a/sip/qt/qpushbutton.sip +++ b/sip/qt/qpushbutton.sip @@ -19,6 +19,7 @@ // PyTQt; see the file LICENSE. If not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +%DefaultEncoding "UTF-8" %ExportedDoc <Sect2><Title>TQPushButton</Title> diff --git a/sip/qt/qstring.sip b/sip/qt/qstring.sip index ab30fa4..581bb0a 100644 --- a/sip/qt/qstring.sip +++ b/sip/qt/qstring.sip @@ -195,53 +195,8 @@ public: static const TQChar replacement; static const TQChar byteOrderMark; static const TQChar byteOrderSwapped; -%If (TQt_2_2_0 -) static const TQChar nbsp; -%End -%If (- TQt_3_0_0) - enum Category { - NoCategory, - - Mark_NonSpacing, - Mark_SpacingCombining, - Mark_Enclosing, - - Number_DecimalDigit, - Number_Letter, - Number_Other, - - Separator_Space, - Separator_Line, - Separator_Paragraph, - - Other_Control, - Other_Format, - Other_Surrogate, - Other_PrivateUse, - Other_NotAssigned, - - Letter_Uppercase, - Letter_Lowercase, - Letter_Titlecase, - Letter_Modifier, - Letter_Other, - - Punctuation_Connector, - Punctuation_Dask, - Punctuation_Open, - Punctuation_Close, - Punctuation_InitialQuote, - Punctuation_FinalQuote, - Punctuation_Other, - - Symbol_Math, - Symbol_Currency, - Symbol_Modifier, - Symbol_Other - }; -%End -%If (TQt_3_0_0 -) enum Category { NoCategory, @@ -282,24 +237,7 @@ public: Symbol_Modifier, Symbol_Other }; -%End -%If (- TQt_3_0_0) - enum Direction { - DirL, - DirR, - DirEN, - DirES, - DirET, - DirAN, - DirCS, - DirB, - DirS, - DirWS, - DirON - }; -%End -%If (TQt_3_0_0 -) enum Direction { DirL, DirR, @@ -321,7 +259,6 @@ public: DirNSM, DirBN }; -%End enum Decomposition { Single, @@ -351,7 +288,6 @@ public: Center }; -%If (TQt_3_0_0 -) enum CombiningClass { Combining_BelowLeftAttached, Combining_BelowAttached, @@ -375,7 +311,6 @@ public: Combining_DoubleAbove, Combining_IotaSubscript }; -%End int digitValue() const; TQChar lower() const; @@ -385,19 +320,10 @@ public: Direction direction() const; Joining joining() const; bool mirrored() const; -%If (TQt_2_1_0 -) TQChar mirroredChar() const; -%End -%If (- TQt_3_0_0) - TQString decomposition() const; -%End -%If (TQt_3_0_0 -) const TQString &decomposition() const; -%End Decomposition decompositionTag() const; -%If (TQt_3_0_0 -) unsigned char combiningClass() const; -%End char latin1() const; ushort unicode() const; @@ -409,22 +335,16 @@ public: bool isMark() const; bool isLetter() const; bool isNumber() const; -%If (TQt_2_1_0 -) bool isLetterOrNumber() const; -%End bool isDigit() const; -%If (TQt_3_0_0 -) bool isSymbol() const; -%End // uchar& cell(); // uchar& row(); uchar cell() const; uchar row() const; -%If (TQt_3_0_0 -) void setCell(uchar); void setRow(uchar); -%End static bool networkOrdered(); }; @@ -447,6 +367,7 @@ class TQString { %TypeHeaderCode #include <tqstring.h> +#include <tqtextcodec.h> %End public: @@ -457,18 +378,14 @@ public: // TQString(const TQChar *,uint); // TQString(const char *); -%If (TQt_2_1_0 -) // This is how we implement TQUrl::operator TQString() const. TQString(const TQUrl &); -%End -%If (TQt_3_0_0 -) // This is how we implement TQKeySequence::operator TQString() const. TQString(const TQKeySequence &); // This is how we implement TQUuid::operator TQString() const. TQString(const TQUuid &); -%End static const TQString null; @@ -476,20 +393,13 @@ public: bool isEmpty() const; uint length() const; void truncate(uint); -%If (- TQt_3_0_0) - void fill(TQChar,int = -1); -%End -%If (TQt_3_0_0 -) TQString &fill(TQChar,int = -1); -%End TQString copy() const; TQString arg(int /Constrained/,int = 0,int = 10) const; TQString arg(double /Constrained/,int = 0,char = 'g',int = -1) const; -%If (TQt_3_2_0 -) // TQString arg(TQ_LLONG,int = 0,int = 10) const; // TQString arg(TQ_ULLONG,int = 0,int = 10) const; -%End TQString arg(long,int = 0,int = 10) const; TQString arg(ulong,int = 0,int = 10) const; // TQString arg(uint,int = 0,int = 10) const; @@ -498,12 +408,10 @@ public: TQString arg(char,int = 0) const; TQString arg(TQChar,int = 0) const; TQString arg(const TQString&,int = 0) const; -%If (TQt_3_2_0 -) TQString arg(const TQString &,const TQString &) const; TQString arg(const TQString &,const TQString &,const TQString &) const; TQString arg(const TQString &,const TQString &,const TQString &, const TQString &) const; -%End // TQString &sprintf(const char *,...); @@ -523,7 +431,6 @@ public: int contains(const TQString &,bool = 1) const; int contains(const TQRegExp &) const; -%If (TQt_3_0_0 -) enum SectionFlags { SectionDefault, SectionSkipEmpty, @@ -540,7 +447,6 @@ public: int = SectionDefault) const; TQString section(const TQRegExp &,int,int = 0xffffffff, int = SectionDefault) const; -%End TQString left(uint) const; TQString right(uint) const; @@ -553,56 +459,36 @@ public: TQString simplifyWhiteSpace() const; TQString &insert(uint,const TQString &); -%If (TQt_3_2_0 -) TQString &insert(uint,const TQByteArray &); // TQString &insert(uint,const char *); -%End TQString &insert(uint,TQChar *,uint); TQString &insert(uint,TQChar); TQString &insert(uint,char); TQString &append(char); -%If (TQt_2_2_0 -) TQString &append(TQChar); -%End TQString &append(const TQString &); TQString &prepend(char); -%If (TQt_2_2_0 -) TQString &prepend(TQChar); -%End TQString &prepend(const TQString &); TQString &remove(uint,uint); -%If (TQt_3_1_0 -) TQString &remove(const TQString &); -%If (TQt_3_2_0 -) TQString &remove(const TQString &,bool); -%End TQString &remove(TQChar); TQString &remove(char); TQString &remove(const TQRegExp &); -%End TQString &replace(uint,uint,const TQString &); TQString &replace(uint,uint,const TQChar *,uint); -%If (TQt_3_1_0 -) TQString &replace(uint,uint,TQChar); TQString &replace(uint,uint,char); TQString &replace(TQChar,const TQString &); -%If (TQt_3_2_0 -) TQString &replace(TQChar,const TQString &,bool); -%End TQString &replace(char,const TQString &); -%If (TQt_3_2_0 -) TQString &replace(char,const TQString &,bool); -%End TQString &replace(const TQString &,const TQString &); -%If (TQt_3_2_0 -) TQString &replace(const TQString &,const TQString &,bool); -%End -%End TQString &replace(const TQRegExp &,const TQString &); -%If (TQt_3_1_0 -) TQString &replace(TQChar,TQChar); -%End short toShort(bool * = 0,int = 10) const; ushort toUShort(bool * = 0,int = 10) const; @@ -610,10 +496,8 @@ public: uint toUInt(bool * = 0,int = 10) const; long toLong(bool * = 0,int = 10) const; ulong toULong(bool * = 0,int = 10) const; -%If (TQt_3_2_0 -) // TQ_LLONG toLongLong(bool * = 0,int = 10) const; // TQ_ULLONG toULongLong(bool * = 0,int = 10) const; -%End float toFloat(bool * = 0) const; double toDouble(bool * = 0) const; @@ -624,28 +508,22 @@ public: // TQString &setNum(uint,int = 10); TQString &setNum(long,int = 10); TQString &setNum(ulong,int = 10); -%If (TQt_3_2_0 -) // TQString &setNum(TQ_LLONG,int = 10); // TQString &setNum(TQ_ULLONG,int = 10); -%End // TQString &setNum(float,char = 'g',int = 6); static TQString number(int /Constrained/,int = 10); static TQString number(double /Constrained/,char = 'g',int = 6); static TQString number(long,int = 10); static TQString number(ulong,int = 10); -%If (TQt_3_2_0 -) // static TQString number(TQ_LLONG,int = 10); // static TQString number(TQ_ULLONG,int = 10); -%End // static TQString number(uint,int = 10); void setExpand(uint,TQChar); TQString &operator+=(const TQString &); -%If (TQt_3_3_0 -) TQString &operator+=(const TQByteArray &); -%End TQString &operator+=(TQChar); //TQString &operator+=(char); @@ -673,9 +551,7 @@ public: // TQChar &ref(uint); // const TQChar *unicode() const; const char *ascii() const; -%If (TQt_3_1_0 -) static TQString fromAscii(const char *,int = -1); -%End const char *latin1() const; static TQString fromLatin1(const char *,int = -1); TQCString utf8() const; @@ -683,62 +559,34 @@ public: TQCString local8Bit() const; static TQString fromLocal8Bit(const char *,int = -1); -%If (TQt_3_1_0 -) // static TQString fromUcs2(const unsigned short *); // const unsigned short *ucs2() const; -%End -%If (TQt_2_1_0 -) // TQString &setUnicode(const TQChar *,uint); // TQString &setUnicodeCodes(const ushort *,uint); -%End -%If (TQt_3_1_0 -) TQString &setAscii(const char *,int = -1); -%End -%If (TQt_2_1_0 -) TQString &setLatin1(const char *,int = -1); -%End int compare(const TQString &) const; static int compare(const TQString &,const TQString &); -%If (TQt_3_0_0 -) int localeAwareCompare(const TQString &) const; static int localeAwareCompare(const TQString &,const TQString &); -%End void compose(); -%If (- TQt_3_0_0) - TQChar::Direction basicDirection(); - TQString visual(int = 0,int = -1); -%End -%If (TQt_2_2_0 -) bool startsWith(const TQString &) const; -%End -%If (TQt_3_2_0 -) bool startsWith(const TQString &,bool) const; -%End -%If (TQt_3_0_0 -) bool endsWith(const TQString &) const; -%End -%If (TQt_3_2_0 -) bool endsWith(const TQString &,bool) const; -%End -%If (TQt_3_0_0 -) void setLength(uint); -%End -%If (TQt_3_2_0 -) uint capacity() const; void reserve(uint); void squeeze(); -%End -%If (TQt_3_0_0 -) bool simpleText() const; bool isRightToLeft() const; -%End // Force the numeric interpretation so that str + TQString gets handled // as we want. @@ -792,81 +640,12 @@ public: SIP_PYOBJECT __unicode__(); %MethodCode -#if PY_VERSION_HEX >= 0x01060000 - sipRes = TQStringToPyUnicode(sipCpp); -#else - Py_INCREF(Py_None); - sipRes = Py_None; -#endif + sipRes = PyTQt_qt_PyObject_FromTQString(sipCpp); %End SIP_PYOBJECT __str__(); %MethodCode -#if PY_VERSION_HEX >= 0x01060000 - sipRes = TQStringToPyUnicode(sipCpp); -#else - const char *s; - - Py_BEGIN_ALLOW_THREADS - s = *sipCpp; - Py_END_ALLOW_THREADS - - if (s == NULL) - s = ""; - - sipRes = PyString_FromString(s); -#endif -%End - -%TypeCode -#include <tqtextcodec.h> - -#if PY_VERSION_HEX >= 0x01060000 -// Convenience function for converting a TQString to a Python Unicode object. -static PyObject *TQStringToPyUnicode(TQString *qs) -{ - PyObject *uobj; - - if ((uobj = PyUnicode_FromUnicode(NULL,qs -> length())) == NULL) - return NULL; - - Py_UNICODE *pyu = PyUnicode_AS_UNICODE(uobj); - - for (uint i = 0; i < qs -> length(); ++i) - *pyu++ = (qs -> at(i)).unicode(); - - return uobj; -} -#endif - -// Convenience function for converting a Python unicode or string object to a -// TQString on the heap. -static TQString *PyUnicodeStringToTQString(PyObject *py) -{ -#if PY_VERSION_HEX >= 0x01060000 - if (PyUnicode_Check(py)) - { - TQString *qs = new TQString; - -#if defined(Py_UNICODE_WIDE) - PY_UNICODE_TYPE *ucode = PyUnicode_AS_UNICODE(py); - int len = PyUnicode_GET_SIZE(py); - - for (int i = 0; i < len; ++i) - qs->ref(i) = (uint)ucode[i]; -#else - qs -> setUnicodeCodes((ushort *)PyUnicode_AS_UNICODE(py),PyUnicode_GET_SIZE(py)); -#endif - - return qs; - } -#endif - - if (PyString_Check(py)) - return new TQString(PyString_AS_STRING(py)); - - return 0; -} + sipRes = PyTQt_qt_PyObject_FromTQString(sipCpp); %End %ConvertToTypeCode @@ -874,13 +653,11 @@ static TQString *PyUnicodeStringToTQString(PyObject *py) // expected. if (sipIsErr == NULL) - return (PyString_Check(sipPy) || -#if PY_VERSION_HEX >= 0x01060000 + return (SIPBytes_Check(sipPy) || PyUnicode_Check(sipPy) || -#endif sipCanConvertToInstance(sipPy,sipClass_TQString,SIP_NO_CONVERTORS)); - *sipCppPtr = PyUnicodeStringToTQString(sipPy); + *sipCppPtr = PyTQt_qt_PyObject_AsTQString(sipPy); if (*sipCppPtr) return sipGetState(sipTransferObj); @@ -942,7 +719,7 @@ static TQString *PyUnicodeStringToTQString(PyObject *py) enc = codec->fromUnicode(*sipCpp); - if ((encobj = PyString_FromString(enc.data())) != NULL) + if ((encobj = SIPBytes_FromString(enc.data())) != NULL) { *sipPtrPtr = (void *)PyString_AS_STRING(encobj); sipRes = PyString_GET_SIZE(encobj); @@ -973,107 +750,227 @@ bool operator>=(const TQString &,const TQString &); %End -%If (- TQt_2_00) +%ModuleHeaderCode +extern PyObject *PyTQt_qt_PyObject_FromTQString(const TQString *qstr); +%End -class TQString : TQByteArray +%ModuleCode +// Convert a QString to a Python Unicode object. +PyObject *PyTQt_qt_PyObject_FromTQString(const TQString *qstr) { -%TypeHeaderCode -#include <tqstring.h> + PyObject *obj; + +#if PY_VERSION_HEX >= 0x03030000 + // We have to work out exactly which kind to use. We assume ASCII while we + // are checking so that we only go through the string once in the most + // common case. Note that we can't use PyUnicode_FromKindAndData() because + // it doesn't handle surrogates in UCS2 strings. + + int qt_len = qstr->length(); + Py_UCS4 maxchar = 0x007f; + + for (int qt_i = 0; qt_i < qt_len && maxchar < 0xffff; ++qt_i) + { + Py_UCS4 uch = qstr->at(qt_i).unicode(); + + if (uch > 0x00ff) + { + maxchar = 0xffff; + } + else if (uch > 0x007f) + { + maxchar = 0x00ff; + } + } + + // Create the correctly sized object. + if ((obj = PyUnicode_New(qt_len, maxchar)) == NULL) + return NULL; + + int kind = PyUnicode_KIND(obj); + void *data = PyUnicode_DATA(obj); + + for (int qt_i = 0; qt_i < qt_len; ++qt_i) + { + Py_UCS4 uch = qstr->at(qt_i).unicode(); + PyUnicode_WRITE(kind, data, qt_i, uch); + } +#elif defined(Py_UNICODE_WIDE) + // Note that this doesn't handle code points greater than 0xffff. It could + // but it's only an issue for old versions of Qt. + + if ((obj = PyUnicode_FromUnicode(NULL, qstr->length())) == NULL) + return NULL; + + Py_UNICODE *pyu = PyUnicode_AS_UNICODE(obj); + + for (unsigned int i = 0; i < qstr->length(); ++i) + *pyu++ = (qstr->at(i)).unicode(); +#else + if ((obj = PyUnicode_FromUnicode(NULL, qstr->length())) == NULL) + return NULL; + + memcpy(PyUnicode_AS_UNICODE(obj), qstr->ucs2(), + qstr->length() * sizeof (Py_UNICODE)); +#endif + + return obj; +} %End -public: - TQString(); - TQString(int); - TQString(const TQString &); - TQString(const char *); - TQString(const char *,uint); - bool isNull() const; - bool isEmpty() const; - uint length() const; - bool resize(uint); - bool truncate(uint); - bool fill(char,int = -1); - TQString copy() const; -// TQString &sprintf(const char *,...); - int find(char,int = 0,bool = 1) const; - int find(const char *,int = 0,bool = 1) const; - int find(const TQRegExp &,int = 0) const; - int findRev(char,int = -1,bool = 1) const; - int findRev(const char *,int = -1,bool = 1) const; - int findRev(const TQRegExp &,int = -1) const; - int contains(char,bool = 1) const; - int contains(const char *,bool = 1) const; - int contains(const TQRegExp &) const; - TQString left(uint) const; - TQString right(uint) const; - TQString mid(uint,uint) const; - TQString leftJustify(uint,char = ' ',bool = 0) const; - TQString rightJustify(uint,char = ' ',bool = 0) const; - TQString lower() const; - TQString upper() const; - TQString stripWhiteSpace() const; - TQString simplifyWhiteSpace() const; - TQString &insert(uint,const char *); - TQString &insert(uint,char); - TQString &append(const char *); - TQString &prepend(const char *); - TQString &remove(uint,uint); - TQString &replace(uint,uint,const char *); - TQString &replace(const TQRegExp &,const char *); - - short toShort(bool * = 0) const; - ushort toUShort(bool * = 0) const; - int toInt(bool * = 0) const; - uint toUInt(bool * = 0) const; - long toLong(bool * = 0) const; - ulong toULong(bool * = 0) const; - float toFloat(bool * = 0) const; - double toDouble(bool * = 0) const; +%ModuleHeaderCode +extern TQString *PyTQt_qt_PyObject_AsTQString(PyObject *obj); +%End - TQString &setStr(const char *); -// TQString &setNum(short); -// TQString &setNum(ushort); - TQString &setNum(int /Constrained/); -// TQString &setNum(uint); -// TQString &setNum(long); -// TQString &setNum(ulong); -// TQString &setNum(float,char = 'g',int = 6); - TQString &setNum(double,char = 'g',int = 6); - bool setExpand(uint,char); +%ModuleCode +// Convert a Python Unicode object to a QString. +TQString *PyTQt_qt_PyObject_AsTQString(PyObject *obj) +{ + if (PyUnicode_Check(obj)) + { +#if PY_VERSION_HEX >= 0x03030000 + SIP_SSIZE_T len = PyUnicode_GET_LENGTH(obj); - SIP_PYOBJECT __str__(); -%MethodCode - const char *s; + switch (PyUnicode_KIND(obj)) + { + case PyUnicode_1BYTE_KIND: + return new TQString(TQString::fromLatin1((char *)PyUnicode_1BYTE_DATA(obj), len)); - Py_BEGIN_ALLOW_THREADS - s = *sipCpp; - Py_END_ALLOW_THREADS + case PyUnicode_2BYTE_KIND: + // The (TQChar *) cast should be safe. + return new TQString((TQChar *)PyUnicode_2BYTE_DATA(obj), len); - if (s == NULL) - s = ""; + case PyUnicode_4BYTE_KIND: + // Note that this doesn't handle code points greater than 0xffff. It + // could but it's only an issue for old versions of Qt. - sipRes = PyString_FromString(s); -%End + TQString *qstr = new TQString; -%ConvertToTypeCode - // Allow a Python string whenever a TQString is expected. + Py_UCS4 *ucode = PyUnicode_4BYTE_DATA(obj); - if (sipIsErr == NULL) - return (PyString_Check(sipPy) || - sipCanConvertToInstance(sipPy,sipClass_TQString,SIP_NO_CONVERTORS)); + for (SIP_SSIZE_T i = 0; i < len; ++i) + qstr->append(TQChar((uint)ucode[i])); - if (PyString_Check(sipPy)) - { - *sipCppPtr = new TQString(PyString_AS_STRING(sipPy)); + return qstr; + } - return sipGetState(sipTransferObj); - } + return NULL; +#else + TQString *qstr = new TQString; - *sipCppPtr = reinterpret_cast<TQString *>(sipConvertToInstance(sipPy,sipClass_TQString,sipTransferObj,SIP_NO_CONVERTORS,0,sipIsErr)); +# ifdef Py_UNICODE_WIDE + Py_UNICODE *ucode = PyUnicode_AS_UNICODE(obj); + SIP_SSIZE_T len = PyUnicode_GET_SIZE(obj); - return 0; + for (SIP_SSIZE_T i = 0; i < len; ++i) + qstr->append(TQChar((uint)ucode[i])); +# else + qstr->setUnicodeCodes((ushort *)PyUnicode_AS_UNICODE(obj),PyUnicode_GET_SIZE(obj)); +# endif + + return qstr; +#endif + } + else if (PyBytes_Check(obj)) + { + return new TQString(SIPBytes_AS_STRING(obj)); + } +#if PY_MAJOR_VERSION < 3 + else if (PyString_Check(obj)) + { + return new TQString(PyString_AS_STRING(obj)); + } +#endif + + return NULL; +} +%End + + +%ModuleHeaderCode +extern const char *PyTQt_qt_encode(PyObject **s, TQApplication::Encoding encoding); %End -}; +%ModuleCode +// Convert a Python unicode/string/bytes object to a character string encoded +// according to the given encoding. Update the object with a new reference to +// the object that owns the data. +const char *PyTQt_qt_encode(PyObject **s, TQApplication::Encoding encoding) +{ + PyObject *obj = *s; + const char *es = 0; + SIP_SSIZE_T sz; + + if (PyUnicode_Check(obj)) + { + if (encoding == TQApplication::UnicodeUTF8) + { + obj = PyUnicode_AsUTF8String(obj); + } + else + { + TQTextCodec *codec = TQTextCodec::codecForTr(); + + if (codec) + { + // Use the Qt codec to get to a byte string, and then to a + // Python object. + TQString *qstr = PyTQt_qt_PyObject_AsTQString(obj); + TQString qs = *qstr; + TQByteArray ba = codec->fromUnicode(qs); + delete qstr; + +#if PY_MAJOR_VERSION >= 3 + obj = PyBytes_FromStringAndSize(ba.data(), ba.size()); +#else + obj = PyString_FromStringAndSize(ba.data(), ba.size()); +#endif + } + else + { + obj = PyUnicode_AsLatin1String(obj); + } + } + + if (obj) + { +#if PY_MAJOR_VERSION >= 3 + es = PyBytes_AS_STRING(obj); +#else + es = PyString_AS_STRING(obj); +#endif + } + } +#if PY_MAJOR_VERSION >= 3 + else if (PyBytes_Check(obj)) + { + es = PyBytes_AS_STRING(obj); + Py_INCREF(obj); + } +#else + else if (PyString_Check(obj)) + { + es = PyString_AS_STRING(obj); + Py_INCREF(obj); + } +#endif + else if (PyObject_AsCharBuffer(obj, &es, &sz) >= 0) + { + Py_INCREF(obj); + } + + if (es) + { + *s = obj; + } + else + { + PyErr_Format(PyExc_UnicodeEncodeError, + "unable to convert '%s' to requested encoding", + Py_TYPE(*s)->tp_name); + } + + return es; +} %End diff --git a/sip/qt/qstringlist.sip b/sip/qt/qstringlist.sip index 23ef47b..ead39dc 100644 --- a/sip/qt/qstringlist.sip +++ b/sip/qt/qstringlist.sip @@ -188,7 +188,7 @@ public: sipRes = new TQString((*sipCpp)[a0]); %End - TQStringList operator[](SIP_PYSLICE); + TQStringList operator[](SIP_PYSLICE slice); %MethodCode #if PY_VERSION_HEX >= 0x02050000 Py_ssize_t len, start, stop, step, slicelength, i; diff --git a/sip/qt/qstrlist.sip b/sip/qt/qstrlist.sip index 0fd3976..695c872 100644 --- a/sip/qt/qstrlist.sip +++ b/sip/qt/qstrlist.sip @@ -57,7 +57,7 @@ is used instead. { PyObject *ps; - if ((ps = PyString_FromString(s)) == NULL || PyList_SetItem(l,i,ps) < 0) + if ((ps = SIPBytes_FromString(s)) == NULL || PyList_SetItem(l,i,ps) < 0) { Py_XDECREF(ps); Py_DECREF(l); @@ -80,13 +80,17 @@ is used instead. for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) { + PyObject *object = PyList_GET_ITEM(sipPy, i); char *s; - if ((s = PyString_AsString(PyList_GET_ITEM(sipPy,i))) == NULL) + if (PyUnicode_Check(object)) + { + s = tqstrdup(sipString_AsLatin1String(&object)); + } + else if ((s = (char *)sipBytes_AsString(object)) == NULL) { *sipIsErr = 1; delete qsl; - return 0; } diff --git a/sip/qt/qvaluelist.sip b/sip/qt/qvaluelist.sip index e64fb30..e2a1d9b 100644 --- a/sip/qt/qvaluelist.sip +++ b/sip/qt/qvaluelist.sip @@ -139,7 +139,7 @@ template<Type> // Get it. for (uint i = 0; i < sipCpp -> count(); ++i) - if (PyList_SetItem(l,i,PyInt_FromLong((long)(*sipCpp)[i])) < 0) + if (PyList_SetItem(l,i,PyLong_FromLong((long)(*sipCpp)[i])) < 0) { Py_DECREF(l); @@ -161,7 +161,7 @@ template<Type> for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) { - qvl -> append((int)PyInt_AsLong(PyList_GET_ITEM(sipPy,i))); + qvl -> append(PyLong_AsLong(PyList_GET_ITEM(sipPy,i))); if (PyErr_Occurred() != NULL) { diff --git a/sip/qtnetwork/qftp.sip b/sip/qtnetwork/qftp.sip index e5f46d8..94aed30 100644 --- a/sip/qtnetwork/qftp.sip +++ b/sip/qtnetwork/qftp.sip @@ -130,7 +130,7 @@ public: Py_INCREF(Py_None); sipRes = Py_None; } - else if ((sipRes = PyString_FromStringAndSize(buf,actlen)) == NULL) + else if ((sipRes = SIPBytes_FromStringAndSize(buf,actlen)) == NULL) sipIsErr = 1; sipFree((void *)buf); diff --git a/sip/qtnetwork/qhttp.sip b/sip/qtnetwork/qhttp.sip index 8fbeae7..4762c30 100644 --- a/sip/qtnetwork/qhttp.sip +++ b/sip/qtnetwork/qhttp.sip @@ -226,7 +226,7 @@ public: Py_INCREF(Py_None); sipRes = Py_None; } - else if ((sipRes = PyString_FromStringAndSize(buf,actlen)) == NULL) + else if ((sipRes = SIPBytes_FromStringAndSize(buf,actlen)) == NULL) sipIsErr = 1; sipFree((void *)buf); diff --git a/sip/qtnetwork/qsocket.sip b/sip/qtnetwork/qsocket.sip index 077443e..b97f243 100644 --- a/sip/qtnetwork/qsocket.sip +++ b/sip/qtnetwork/qsocket.sip @@ -194,7 +194,7 @@ public: } else { - sipRes = PyString_FromStringAndSize(buf,actlen); + sipRes = SIPBytes_FromStringAndSize(buf,actlen); sipFree((void *)buf); @@ -229,7 +229,7 @@ public: } else { - sipRes = PyString_FromStringAndSize(buf,actlen); + sipRes = SIPBytes_FromStringAndSize(buf,actlen); sipFree((void *)buf); @@ -263,7 +263,7 @@ public: } else { - sipRes = PyString_FromStringAndSize(buf,actlen); + sipRes = SIPBytes_FromStringAndSize(buf,actlen); sipFree((void *)buf); @@ -299,7 +299,7 @@ public: } else { - sipRes = PyString_FromStringAndSize(buf,actlen); + sipRes = SIPBytes_FromStringAndSize(buf,actlen); sipFree((void *)buf); diff --git a/sip/qtnetwork/qsocketdevice.sip b/sip/qtnetwork/qsocketdevice.sip index 41da2f5..bbaa008 100644 --- a/sip/qtnetwork/qsocketdevice.sip +++ b/sip/qtnetwork/qsocketdevice.sip @@ -145,7 +145,7 @@ public: Py_INCREF(Py_None); sipRes = Py_None; } - else if ((sipRes = PyString_FromStringAndSize(buf,actlen)) == NULL) + else if ((sipRes = SIPBytes_FromStringAndSize(buf,actlen)) == NULL) sipIsErr = 1; sipFree((void *)buf); @@ -176,7 +176,7 @@ public: Py_INCREF(Py_None); sipRes = Py_None; } - else if ((sipRes = PyString_FromStringAndSize(buf,actlen)) == NULL) + else if ((sipRes = SIPBytes_FromStringAndSize(buf,actlen)) == NULL) sipIsErr = 1; sipFree((void *)buf); diff --git a/sip/qtpe/qpeapplication.sip b/sip/qtpe/qpeapplication.sip index 5b76b22..9e6b99b 100644 --- a/sip/qtpe/qpeapplication.sip +++ b/sip/qtpe/qpeapplication.sip @@ -186,7 +186,7 @@ static char **pyArgvToC(PyObject *argvlist,int *argcp) char *arg; // Get the argument and allocate memory for it. - if ((arg = PyString_AsString(PyList_GetItem(argvlist,a))) == NULL || + if ((arg = (char *)sipBytes_AsString(PyList_GetItem(argvlist,a))) == NULL || (argv[a] = (char *)sipMalloc(strlen(arg) + 1)) == NULL) return NULL; |