[TD] remove Py2 code from TD

This commit is contained in:
luz paz
2021-04-21 22:06:59 -04:00
committed by wwmayer
parent ba99b72984
commit 738a697d94
11 changed files with 0 additions and 91 deletions

View File

@@ -781,17 +781,10 @@ private:
try {
Py::Sequence list(pEdgeList);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_Check((*it).ptr())) {
std::string temp = PyUnicode_AsUTF8((*it).ptr());
edgeList.push_back(temp);
}
#else
if (PyString_Check((*it).ptr())) {
std::string temp = PyString_AsString((*it).ptr()); //py2 only!!!
edgeList.push_back(temp);
}
#endif
}
}
catch (Standard_Failure& e) {
@@ -829,15 +822,9 @@ private:
else {
throw Py::TypeError("expected (DrawViewPart, dimType, from, to");
}
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_Check(pDimType) ) {
dimType = PyUnicode_AsUTF8(pDimType);
}
#else
if (PyString_Check(pDimType) ) {
dimType = PyString_AsString(pDimType);
}
#endif
if (PyObject_TypeCheck(pFrom, &(Base::VectorPy::Type))) {
from = static_cast<Base::VectorPy*>(pFrom)->value();
@@ -877,15 +864,9 @@ private:
else {
throw Py::TypeError("expected (DrawViewPart, dimType, from, to");
}
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_Check(pDimType)) {
dimType = PyUnicode_AsUTF8(pDimType);
}
#else
if (PyString_Check(pDimType)) {
dimType = PyString_AsString(pDimType);
}
#endif
if (PyObject_TypeCheck(pFrom, &(Base::VectorPy::Type))) {
from = static_cast<Base::VectorPy*>(pFrom)->value();
}

View File

@@ -321,17 +321,10 @@ void CenterLinePy::setEdges(Py::Object arg)
int i = 0;
for ( ; i < tSize; i++) {
PyObject* item = PyList_GetItem(pList, (Py_ssize_t) i);
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_Check(item)) {
std::string s = PyUnicode_AsUTF8(item); //py3 only!!!
temp.push_back(s);
}
#else
if (PyString_Check(item)) {
std::string s = PyString_AsString(item); //py2 only!!!
temp.push_back(s);
}
#endif
}
cl->m_edges = temp;
} else {
@@ -367,17 +360,10 @@ void CenterLinePy::setFaces(Py::Object arg)
int i = 0;
for ( ; i < tSize; i++) {
PyObject* item = PyList_GetItem(pList, (Py_ssize_t) i);
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_Check(item)) {
std::string s = PyUnicode_AsUTF8(item); //py3 only!!!
temp.push_back(s);
}
#else
if (PyString_Check(item)) {
std::string s = PyString_AsString(item); //py2 only!!!
temp.push_back(s);
}
#endif
}
cl->m_faces = temp;
} else {
@@ -414,17 +400,10 @@ void CenterLinePy::setPoints(Py::Object arg)
int i = 0;
for ( ; i < tSize; i++) {
PyObject* item = PyList_GetItem(pList, (Py_ssize_t) i);
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_Check(item)) {
std::string s = PyUnicode_AsUTF8(item); //py3 only!!!
temp.push_back(s);
}
#else
if (PyString_Check(item)) {
std::string s = PyString_AsString(item); //py2 only!!!
temp.push_back(s);
}
#endif
}
cl->m_verts = temp;
} else {

View File

@@ -44,11 +44,7 @@ PyObject* DrawPagePy::addView(PyObject* args)
DrawView* view = pyView->getDrawViewPtr(); //get DrawView for pyView
int rc = page->addView(view);
#if PY_MAJOR_VERSION < 3
return PyInt_FromLong((long) rc);
#else
return PyLong_FromLong((long) rc);
#endif
}
PyObject* DrawPagePy::removeView(PyObject* args)
@@ -69,11 +65,7 @@ PyObject* DrawPagePy::removeView(PyObject* args)
int rc = page->removeView(view);
#if PY_MAJOR_VERSION < 3
return PyInt_FromLong((long) rc);
#else
return PyLong_FromLong((long) rc);
#endif
}
PyObject* DrawPagePy::getAllViews(PyObject* args)

View File

@@ -72,11 +72,7 @@ PyObject* DrawProjGroupPy::removeProjection(PyObject* args)
DrawProjGroup* projGroup = getDrawProjGroupPtr();
int i = projGroup->removeProjection(projType);
#if PY_MAJOR_VERSION < 3
return PyInt_FromLong((long) i);
#else
return PyLong_FromLong((long) i);
#endif
}
PyObject* DrawProjGroupPy::purgeProjections(PyObject* /*args*/)
@@ -84,11 +80,7 @@ PyObject* DrawProjGroupPy::purgeProjections(PyObject* /*args*/)
DrawProjGroup* projGroup = getDrawProjGroupPtr();
int i = projGroup->purgeProjections();
#if PY_MAJOR_VERSION < 3
return PyInt_FromLong((long) i);
#else
return PyLong_FromLong((long) i);
#endif
}
PyObject* DrawProjGroupPy::getItemByLabel(PyObject* args)

View File

@@ -71,11 +71,7 @@ PyObject* DrawSVGTemplatePy::getEditFieldContent(PyObject* args)
}
std::string content = getDrawSVGTemplatePtr()->EditableTexts[fieldName];
if (!content.empty()) {
#if PY_MAJOR_VERSION < 3
result = PyString_FromString(content.c_str());
#else
result = PyUnicode_FromString(content.c_str());
#endif
}
return result;
}

View File

@@ -50,11 +50,7 @@ PyObject* DrawViewCollectionPy::addView(PyObject* args)
int i = collect->addView(view);
#if PY_MAJOR_VERSION < 3
return PyInt_FromLong((long) i);
#else
return PyLong_FromLong((long) i);
#endif
}
PyObject* DrawViewCollectionPy::removeView(PyObject* args)
@@ -72,11 +68,7 @@ PyObject* DrawViewCollectionPy::removeView(PyObject* args)
int i = collect->removeView(view);
#if PY_MAJOR_VERSION < 3
return PyInt_FromLong((long) i);
#else
return PyLong_FromLong((long) i);
#endif
}

View File

@@ -553,17 +553,10 @@ PyObject* DrawViewPartPy::makeCenterLine(PyObject *args)
int i = 0;
for ( ; i < size; i++) {
PyObject* po = PyList_GetItem(pSubs, i);
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_Check(po)) {
std::string s = PyUnicode_AsUTF8(po); //py3 only!!!
subs.push_back(s);
}
#else
if (PyString_Check(po)) {
std::string s = PyString_AsString(po); //py2 only!!!
subs.push_back(s);
}
#endif
}
}
CenterLine* cl = nullptr;

View File

@@ -1082,11 +1082,7 @@ void CmdTechDrawSymbol::activated(int iMsg)
std::string FeatName = getUniqueObjectName("Symbol");
filename = Base::Tools::escapeEncodeFilename(filename);
openCommand(QT_TRANSLATE_NOOP("Command", "Create Symbol"));
#if PY_MAJOR_VERSION < 3
doCommand(Doc,"f = open(unicode(\"%s\",'utf-8'),'r')",(const char*)filename.toUtf8());
#else
doCommand(Doc,"f = open(\"%s\",'r')",(const char*)filename.toUtf8());
#endif
doCommand(Doc,"svg = f.read()");
doCommand(Doc,"f.close()");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSymbol','%s')",FeatName.c_str());

View File

@@ -86,11 +86,7 @@ QGITile::QGITile(TechDraw::DrawTileWeld* dtw) :
m_fontName = prefTextFont();
m_font = QFont(m_fontName);
#if PY_MAJOR_VERSION < 3
setHandlesChildEvents(true); //qt4 deprecated in qt5
#else
setFiltersChildEvents(true); //qt5
#endif
setAcceptHoverEvents(true);
setFlag(QGraphicsItem::ItemIsSelectable, false);
setFlag(QGraphicsItem::ItemIsMovable, false);

View File

@@ -86,11 +86,7 @@ QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent) :
m_qgLead(myParent),
m_blockDraw(false)
{
#if PY_MAJOR_VERSION < 3
setHandlesChildEvents(true); //qt4 deprecated in qt5
#else
setFiltersChildEvents(true); //qt5
#endif
setFlag(QGraphicsItem::ItemIsMovable, false);
setCacheMode(QGraphicsItem::NoCache);

View File

@@ -151,11 +151,7 @@ TechDraw::DrawViewSymbol* TaskActiveView::createActiveView(void)
ui->qsbWeight->rawValue(),
ui->qsbBorder->rawValue(),
ui->cbMode->currentIndex());
#if PY_MAJOR_VERSION < 3
Command::doCommand(Command::Doc,"f = open(unicode(\"%s\",'utf-8'),'r')",(const char*)fileSpec.c_str());
#else
Command::doCommand(Command::Doc,"f = open(\"%s\",'r')",(const char*)fileSpec.c_str());
#endif
Command::doCommand(Command::Doc,"svg = f.read()");
// Command::doCommand(Command::Doc,"print('length of svg: {}'.format(len(svg)))");