Skip to content

Commit

Permalink
py3/py2: use exec as function
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed May 10, 2019
1 parent 1fb7ed4 commit e25cd6c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Gui/WidgetFactory.cpp
Expand Up @@ -680,7 +680,10 @@ Py::Object PySideUicModule::loadUiType(const Py::Tuple& args)
str << "import pyside2uic\n"
<< "from PySide2 import QtCore, QtGui, QtWidgets\n"
<< "import xml.etree.ElementTree as xml\n"
<< "from cStringIO import StringIO\n"
<< "try:\n"
<< " from cStringIO import StringIO\n"
<< "except:\n"
<< " from io import StringIO\n"
<< "\n"
<< "uiFile = \"" << file.c_str() << "\"\n"
<< "parsed = xml.parse(uiFile)\n"
Expand All @@ -691,15 +694,18 @@ Py::Object PySideUicModule::loadUiType(const Py::Tuple& args)
<< " frame = {}\n"
<< " pyside2uic.compileUi(f, o, indent=0)\n"
<< " pyc = compile(o.getvalue(), '<string>', 'exec')\n"
<< " exec pyc in frame\n"
<< " exec(pyc, frame)\n"
<< " #Fetch the base_class and form class based on their type in the xml from designer\n"
<< " form_class = frame['Ui_%s'%form_class]\n"
<< " base_class = eval('QtWidgets.%s'%widget_class)\n";
#else
str << "import pysideuic\n"
<< "from PySide import QtCore, QtGui\n"
<< "import xml.etree.ElementTree as xml\n"
<< "from cStringIO import StringIO\n"
<< "try:\n"
<< " from cStringIO import StringIO\n"
<< "except:\n"
<< " from io import StringIO\n"
<< "\n"
<< "uiFile = \"" << file.c_str() << "\"\n"
<< "parsed = xml.parse(uiFile)\n"
Expand All @@ -710,7 +716,7 @@ Py::Object PySideUicModule::loadUiType(const Py::Tuple& args)
<< " frame = {}\n"
<< " pysideuic.compileUi(f, o, indent=0)\n"
<< " pyc = compile(o.getvalue(), '<string>', 'exec')\n"
<< " exec pyc in frame\n"
<< " exec(pyc, frame)\n"
<< " #Fetch the base_class and form class based on their type in the xml from designer\n"
<< " form_class = frame['Ui_%s'%form_class]\n"
<< " base_class = eval('QtGui.%s'%widget_class)\n";
Expand Down

0 comments on commit e25cd6c

Please sign in to comment.