Gui: remove py2 code

This commit is contained in:
luz paz
2021-04-23 17:44:15 -04:00
committed by wwmayer
parent 086063f75e
commit 81918da613
4 changed files with 0 additions and 159 deletions

View File

@@ -236,11 +236,7 @@ QMap<QString, CallTip> CallTipsList::extractTips(const QString& context) const
PyObject* eval = 0;
if (PyCode_Check(code)) {
#if PY_MAJOR_VERSION >= 3
eval = PyEval_EvalCode(code, dict.ptr(), dict.ptr());
#else
eval = PyEval_EvalCode(reinterpret_cast<PyCodeObject*>(code), dict.ptr(), dict.ptr());
#endif
}
Py_DECREF(code);
if (!eval) {
@@ -276,14 +272,6 @@ QMap<QString, CallTip> CallTipsList::extractTips(const QString& context) const
else if (PyObject_IsSubclass(type.ptr(), typeobj.o) == 1) {
obj = type;
}
#if PY_MAJOR_VERSION < 3
else if (PyInstance_Check(obj.ptr())) {
// instances of old style classes
PyInstanceObject* inst = reinterpret_cast<PyInstanceObject*>(obj.ptr());
PyObject* classobj = reinterpret_cast<PyObject*>(inst->in_class);
obj = Py::Object(classobj);
}
#endif
else if (PyObject_IsInstance(obj.ptr(), basetype.o) == 1) {
// New style class which can be a module, type, list, tuple, int, float, ...
// Make sure it's not a type object

View File

@@ -649,11 +649,7 @@ void Command::printPyCaller() {
if(!frame)
return;
int line = PyFrame_GetLineNumber(frame);
#if PY_MAJOR_VERSION >= 3
const char *file = PyUnicode_AsUTF8(frame->f_code->co_filename);
#else
const char *file = PyString_AsString(frame->f_code->co_filename);
#endif
printCaller(file?file:"<no file>",line);
}
@@ -1239,19 +1235,11 @@ const char* PythonCommand::getResource(const char* sName) const
pcTemp = PyDict_GetItemString(_pcPyResourceDict,sName);
if (!pcTemp)
return "";
#if PY_MAJOR_VERSION >= 3
if (!PyUnicode_Check(pcTemp)) {
#else
if (!PyString_Check(pcTemp)) {
#endif
throw Base::TypeError("PythonCommand::getResource(): Method GetResources() of the Python "
"command object returns a dictionary which holds not only strings");
}
#if PY_MAJOR_VERSION >= 3
return PyUnicode_AsUTF8(pcTemp);
#else
return PyString_AsString(pcTemp);
#endif
}
void PythonCommand::activated(int iMsg)
@@ -1314,17 +1302,9 @@ const char* PythonCommand::getHelpUrl(void) const
pcTemp = Interpreter().runMethodObject(_pcPyCommand, "CmdHelpURL");
if (! pcTemp )
return "";
#if PY_MAJOR_VERSION >= 3
if (! PyUnicode_Check(pcTemp) )
#else
if (! PyString_Check(pcTemp) )
#endif
throw Base::TypeError("PythonCommand::CmdHelpURL(): Method CmdHelpURL() of the Python command object returns no string");
#if PY_MAJOR_VERSION >= 3
return PyUnicode_AsUTF8(pcTemp);
#else
return PyString_AsString(pcTemp);
#endif
}
Action * PythonCommand::createAction(void)
@@ -1647,19 +1627,11 @@ const char* PythonGroupCommand::getResource(const char* sName) const
pcTemp = PyDict_GetItemString(_pcPyResource, sName);
if (!pcTemp)
return "";
#if PY_MAJOR_VERSION >= 3
if (!PyUnicode_Check(pcTemp)) {
#else
if (!PyString_Check(pcTemp)) {
#endif
throw Base::ValueError("PythonGroupCommand::getResource(): Method GetResources() of the Python "
"group command object returns a dictionary which holds not only strings");
}
#if PY_MAJOR_VERSION >= 3
return PyUnicode_AsUTF8(pcTemp);
#else
return PyString_AsString(pcTemp);
#endif
}
const char* PythonGroupCommand::getWhatsThis() const

View File

@@ -63,36 +63,15 @@ PyObject* PythonWorkbenchPy::appendMenu(PyObject *args)
for (int j=0; j<nDepth;++j) {
PyObject* item = PyList_GetItem(pPath, j);
if (PyUnicode_Check(item)) {
#if PY_MAJOR_VERSION >= 3
const char* pItem = PyUnicode_AsUTF8(item);
path.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0);
char* pItem = PyString_AsString(unicode);
path.push_back(pItem);
Py_DECREF(unicode);
} else if (PyString_Check(item)) {
char* pItem = PyString_AsString(item);
path.push_back(pItem);
#endif
} else {
continue;
}
}
} else if (PyUnicode_Check(pPath)) {
#if PY_MAJOR_VERSION >= 3
const char* pItem = PyUnicode_AsUTF8(pPath);
path.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(pPath, "utf-8", 0);
char* pItem = PyString_AsString(unicode);
path.push_back(pItem);
Py_DECREF(unicode);
} else if (PyString_Check(pPath)) {
// one single item
char* pItem = PyString_AsString(pPath);
path.push_back(pItem);
#endif
} else {
PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument");
return nullptr;
@@ -105,36 +84,15 @@ PyObject* PythonWorkbenchPy::appendMenu(PyObject *args)
for (int i=0; i<nItems;++i) {
PyObject* item = PyList_GetItem(pItems, i);
if (PyUnicode_Check(item)) {
#if PY_MAJOR_VERSION >= 3
const char* pItem = PyUnicode_AsUTF8(item);
items.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0);
char* pItem = PyString_AsString(unicode);
items.push_back(pItem);
Py_DECREF(unicode);
} else if (PyString_Check(item)) {
char* pItem = PyString_AsString(item);
items.push_back(pItem);
#endif
} else {
continue;
}
}
} else if (PyUnicode_Check(pItems)) {
#if PY_MAJOR_VERSION >= 3
const char* pItem = PyUnicode_AsUTF8(pItems);
items.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(pItems, "utf-8", 0);
char* pItem = PyString_AsString(unicode);
items.push_back(pItem);
Py_DECREF(unicode);
} else if (PyString_Check(pItems)) {
// one single item
char* pItem = PyString_AsString(pItems);
items.push_back(pItem);
#endif
} else {
PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument");
return nullptr;
@@ -175,36 +133,15 @@ PyObject* PythonWorkbenchPy::appendContextMenu(PyObject *args)
for (int j=0; j<nDepth;++j) {
PyObject* item = PyList_GetItem(pPath, j);
if (PyUnicode_Check(item)) {
#if PY_MAJOR_VERSION >= 3
const char* pItem = PyUnicode_AsUTF8(item);
path.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0);
char* pItem = PyString_AsString(unicode);
path.push_back(pItem);
Py_DECREF(unicode);
} else if (PyString_Check(item)) {
char* pItem = PyString_AsString(item);
path.push_back(pItem);
#endif
} else {
continue;
}
}
} else if (PyUnicode_Check(pPath)) {
#if PY_MAJOR_VERSION >= 3
const char* pItem = PyUnicode_AsUTF8(pPath);
path.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(pPath, "utf-8", 0);
char* pItem = PyString_AsString(unicode);
path.push_back(pItem);
Py_DECREF(unicode);
} else if (PyString_Check(pPath)) {
// one single item
char* pItem = PyString_AsString(pPath);
path.push_back(pItem);
#endif
} else {
PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument");
return nullptr;
@@ -217,36 +154,15 @@ PyObject* PythonWorkbenchPy::appendContextMenu(PyObject *args)
for (int i=0; i<nItems;++i) {
PyObject* item = PyList_GetItem(pItems, i);
if (PyUnicode_Check(item)) {
#if PY_MAJOR_VERSION >= 3
const char* pItem = PyUnicode_AsUTF8(item);
items.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0);
char* pItem = PyString_AsString(unicode);
items.push_back(pItem);
Py_DECREF(unicode);
} else if (PyString_Check(item)) {
char* pItem = PyString_AsString(item);
items.push_back(pItem);
#endif
} else {
continue;
}
}
} else if (PyUnicode_Check(pItems)) {
#if PY_MAJOR_VERSION >= 3
const char* pItem = PyUnicode_AsUTF8(pItems);
items.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(pItems, "utf-8", 0);
char* pItem = PyString_AsString(unicode);
items.push_back(pItem);
Py_DECREF(unicode);
} else if (PyString_Check(pItems)) {
// one single item
char* pItem = PyString_AsString(pItems);
items.push_back(pItem);
#endif
} else {
PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument");
return nullptr;
@@ -289,18 +205,8 @@ PyObject* PythonWorkbenchPy::appendToolbar(PyObject *args)
for (int i=0; i<nSize;++i) {
PyObject* item = PyList_GetItem(pObject, i);
if (PyUnicode_Check(item)) {
#if PY_MAJOR_VERSION >= 3
const char* pItem = PyUnicode_AsUTF8(item);
items.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0);
char* pItem = PyString_AsString(unicode);
items.push_back(pItem);
Py_DECREF(unicode);
} else if (PyString_Check(item)) {
char* pItem = PyString_AsString(item);
items.push_back(pItem);
#endif
} else {
continue;
}
@@ -342,18 +248,8 @@ PyObject* PythonWorkbenchPy::appendCommandbar(PyObject *args)
for (int i=0; i<nSize;++i) {
PyObject* item = PyList_GetItem(pObject, i);
if (PyUnicode_Check(item)) {
#if PY_MAJOR_VERSION >= 3
const char* pItem = PyUnicode_AsUTF8(item);
items.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0);
char* pItem = PyString_AsString(unicode);
items.push_back(pItem);
Py_DECREF(unicode);
} else if (PyString_Check(item)) {
char* pItem = PyString_AsString(item);
items.push_back(pItem);
#endif
} else {
continue;
}

View File

@@ -320,11 +320,7 @@ PyObject* ViewProviderPy::listDisplayModes(PyObject *args)
int i=0;
for ( std::vector<std::string>::iterator it = modes.begin(); it != modes.end(); ++it ) {
#if PY_MAJOR_VERSION >= 3
PyObject* str = PyUnicode_FromString(it->c_str());
#else
PyObject* str = PyString_FromString(it->c_str());
#endif
PyList_SetItem(pyList, i++, str);
}
@@ -400,19 +396,8 @@ PyObject* ViewProviderPy::partialRender(PyObject* args)
for (Py_ssize_t i = 0; i < nSize; ++i) {
if(value) item = PySequence_GetItem(value, i);
if (PyUnicode_Check(item)) {
#if PY_MAJOR_VERSION >= 3
values[i] = PyUnicode_AsUTF8(item);
#else
PyObject* unicode = PyUnicode_AsUTF8String(item);
values[i] = PyString_AsString(unicode);
Py_DECREF(unicode);
#endif
}
#if PY_MAJOR_VERSION < 3
else if (PyString_Check(item)) {
values[i] = PyString_AsString(item);
}
#endif
else {
std::string error = std::string("type must be str or unicode");
error += " not, ";