From afa37847b5082a3677a33809be0f950cfd8d5647 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 15 Sep 2016 23:14:31 +0200 Subject: [PATCH] remove Application::runPythonCode --- src/Gui/Application.cpp | 58 ++-------- src/Gui/Application.h | 2 - src/Gui/Command.cpp | 1 + src/Gui/Command.h | 2 + src/Gui/DlgProjectUtility.cpp | 5 +- src/Gui/DocumentRecovery.cpp | 3 +- src/Gui/Placement.cpp | 3 +- src/Gui/Tree.cpp | 5 +- src/Gui/ViewProviderDocumentObjectGroup.cpp | 4 +- src/Gui/propertyeditor/PropertyItem.cpp | 18 +++- src/Mod/Part/Gui/CrossSections.cpp | 12 +-- src/Mod/Part/Gui/DlgFilletEdges.cpp | 4 +- src/Mod/Part/Gui/DlgRevolution.cpp | 2 +- src/Mod/Part/Gui/Mirroring.cpp | 2 +- src/Mod/Part/Gui/TaskLoft.cpp | 7 +- src/Mod/Part/Gui/TaskOffset.cpp | 4 +- src/Mod/Part/Gui/TaskShapeBuilder.cpp | 114 ++++++++++---------- src/Mod/Part/Gui/TaskSweep.cpp | 7 +- src/Mod/Part/Gui/TaskThickness.cpp | 5 +- 19 files changed, 118 insertions(+), 140 deletions(-) diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 42064609e..873b0278f 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -622,16 +622,15 @@ void Application::exportTo(const char* FileName, const char* DocName, const char std::string code = str.str(); // the original file name is required - if (runPythonCode(code.c_str(), false)) { - // search for a module that is able to open the exported file because otherwise - // it doesn't need to be added to the recent files list (#0002047) - std::map importMap = App::GetApplication().getImportFilters(te.c_str()); - if (!importMap.empty()) - getMainWindow()->appendRecentFile(QString::fromUtf8(File.filePath().c_str())); - } + Gui::Command::runCommand(Gui::Command::App, code.c_str()); + // search for a module that is able to open the exported file because otherwise + // it doesn't need to be added to the recent files list (#0002047) + std::map importMap = App::GetApplication().getImportFilters(te.c_str()); + if (!importMap.empty()) + getMainWindow()->appendRecentFile(QString::fromUtf8(File.filePath().c_str())); // allow exporters to pass _objs__ to submodules before deleting it - runPythonCode("del __objs__", false); + Gui::Command::runCommand(Gui::Command::App, "del __objs__"); } catch (const Base::PyException& e){ // Usually thrown if the file is invalid somehow @@ -1363,49 +1362,6 @@ CommandManager &Application::commandManager(void) return d->commandManager; } -bool Application::runPythonCode(const char* cmd, bool gui, bool pyexc) -{ - if (gui) - d->macroMngr->addLine(MacroManager::Gui,cmd); - else - d->macroMngr->addLine(MacroManager::App,cmd); - - try { - Base::Interpreter().runString(cmd); - return true; - } - catch (Base::PyException &e) { - if (pyexc) { - e.ReportException(); - Base::Console().Error("Stack Trace: %s\n",e.getStackTrace().c_str()); - } - else { - throw; // re-throw to handle in calling instance - } - } - catch (Base::AbortException&) { - } - catch (Base::Exception &e) { - e.ReportException(); - } - catch (std::exception &e) { - std::string str; - str += "C++ exception thrown ("; - str += e.what(); - str += ")"; - Base::Console().Error(str.c_str()); - } - catch (const char* e) { - Base::Console().Error("%s\n", e); - } -#ifndef FC_DEBUG - catch (...) { - Base::Console().Error("Unknown C++ exception in command thrown\n"); - } -#endif - return false; -} - //************************************************************************** // Init, Destruct and ingleton diff --git a/src/Gui/Application.h b/src/Gui/Application.h index 2802e5dbf..afb4c3c46 100644 --- a/src/Gui/Application.h +++ b/src/Gui/Application.h @@ -178,8 +178,6 @@ public: Gui::MacroManager *macroManager(void); /// Reference to the command manager Gui::CommandManager &commandManager(void); - /// Run a Python command - bool runPythonCode(const char* cmd, bool gui=false, bool pyexc=true); /// helper which create the commands void createStandardOperations(); //@} diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index f6262342e..08c0bd86b 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -25,6 +25,7 @@ #ifndef _PreComp_ # include # include +# include # include # include # include diff --git a/src/Gui/Command.h b/src/Gui/Command.h index 290355258..5a6daa810 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -33,6 +33,8 @@ #include class QWidget; +class QByteArray; + typedef struct _object PyObject; namespace App diff --git a/src/Gui/DlgProjectUtility.cpp b/src/Gui/DlgProjectUtility.cpp index aeb6902e6..94192c8b0 100644 --- a/src/Gui/DlgProjectUtility.cpp +++ b/src/Gui/DlgProjectUtility.cpp @@ -31,6 +31,7 @@ #include "DlgProjectUtility.h" #include "Application.h" +#include "Command.h" #include "ui_DlgProjectUtility.h" @@ -140,7 +141,7 @@ void DlgProjectUtility::on_extractButton_clicked() str << doctools << "\n"; str << "extractDocument(\"" << (const char*)source.toUtf8() << "\", \"" << (const char*)dest.toUtf8() << "\")"; - Application::Instance->runPythonCode(str.str().c_str()); + Gui::Command::runCommand(Gui::Command::App, str.str().c_str()); } void DlgProjectUtility::on_createButton_clicked() @@ -162,7 +163,7 @@ void DlgProjectUtility::on_createButton_clicked() str << doctools << "\n"; str << "createDocument(\"" << (const char*)source.toUtf8() << "\", \"" << (const char*)dest.toUtf8() << "\")"; - Application::Instance->runPythonCode(str.str().c_str()); + Gui::Command::runCommand(Gui::Command::App, str.str().c_str()); if (ui->checkLoadProject->isChecked()) Application::Instance->open((const char*)dest.toUtf8(),"FreeCAD"); diff --git a/src/Gui/DocumentRecovery.cpp b/src/Gui/DocumentRecovery.cpp index 04bca40d4..a033d8d90 100644 --- a/src/Gui/DocumentRecovery.cpp +++ b/src/Gui/DocumentRecovery.cpp @@ -57,6 +57,7 @@ #include #include +#include #include #include @@ -212,7 +213,7 @@ QString DocumentRecovery::createProjectFile(const QString& documentXml) str << doctools << "\n"; str << "createDocument(\"" << (const char*)source.toUtf8() << "\", \"" << (const char*)dest.toUtf8() << "\")"; - Application::Instance->runPythonCode(str.str().c_str()); + Gui::Command::runCommand(Gui::Command::App, str.str().c_str()); return dest; } diff --git a/src/Gui/Placement.cpp b/src/Gui/Placement.cpp index e4faec97b..b8441e113 100644 --- a/src/Gui/Placement.cpp +++ b/src/Gui/Placement.cpp @@ -30,6 +30,7 @@ #include "ui_Placement.h" #include #include +#include #include #include #include @@ -230,7 +231,7 @@ void Placement::applyPlacement(const QString& data, bool incremental) .arg(data); } - Application::Instance->runPythonCode((const char*)cmd.toLatin1()); + Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1()); } } diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 7210830b8..b02007342 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -46,6 +46,7 @@ #include #include "Tree.h" +#include "Command.h" #include "Document.h" #include "BitmapFactory.h" #include "ViewProviderDocumentObject.h" @@ -226,7 +227,7 @@ void TreeWidget::onCreateGroup() .arg(QString::fromLatin1(doc->getName())).arg(name); Gui::Document* gui = Gui::Application::Instance->getDocument(doc); gui->openCommand("Create group"); - Gui::Application::Instance->runPythonCode(cmd.toUtf8()); + Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8()); gui->commitCommand(); } else if (this->contextItem->type() == ObjectType) { @@ -241,7 +242,7 @@ void TreeWidget::onCreateGroup() .arg(name); Gui::Document* gui = Gui::Application::Instance->getDocument(doc); gui->openCommand("Create group"); - Gui::Application::Instance->runPythonCode(cmd.toUtf8()); + Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8()); gui->commitCommand(); } } diff --git a/src/Gui/ViewProviderDocumentObjectGroup.cpp b/src/Gui/ViewProviderDocumentObjectGroup.cpp index 05862cd90..b249169d5 100644 --- a/src/Gui/ViewProviderDocumentObjectGroup.cpp +++ b/src/Gui/ViewProviderDocumentObjectGroup.cpp @@ -208,7 +208,7 @@ void ViewProviderDocumentObjectGroup::drop(const std::vectorgetName())) .arg(QString::fromLatin1(par->getNameInDocument())) .arg(QString::fromLatin1(obj->getNameInDocument())); - Gui::Application::Instance->runPythonCode(cmd.toUtf8()); + Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8()); } // build Python command for execution @@ -219,7 +219,7 @@ void ViewProviderDocumentObjectGroup::drop(const std::vectorgetNameInDocument())) .arg(QString::fromLatin1(obj->getNameInDocument())); - Gui::Application::Instance->runPythonCode(cmd.toUtf8()); + Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8()); } gui->commitCommand(); diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 7aea4a904..3557f8a80 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -44,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -53,7 +55,7 @@ #include #include "PropertyItem.h" -#include +#include using namespace Gui::PropertyEditor; @@ -353,7 +355,19 @@ void PropertyItem::setPropertyValue(const QString& value) App::PropertyContainer* parent = (*it)->getContainer(); if (parent && !parent->isReadOnly(*it) && !(*it)->testStatus(App::Property::ReadOnly)) { QString cmd = QString::fromLatin1("%1 = %2").arg(pythonIdentifier(*it)).arg(value); - Gui::Application::Instance->runPythonCode((const char*)cmd.toUtf8()); + try { + Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8()); + } + catch (Base::PyException &e) { + e.ReportException(); + Base::Console().Error("Stack Trace: %s\n",e.getStackTrace().c_str()); + } + catch (Base::Exception &e) { + e.ReportException(); + } + catch (...) { + Base::Console().Error("Unknown C++ exception in PropertyItem::setPropertyValue thrown\n"); + } } } } diff --git a/src/Mod/Part/Gui/CrossSections.cpp b/src/Mod/Part/Gui/CrossSections.cpp index 7445ae279..c78af46e5 100644 --- a/src/Mod/Part/Gui/CrossSections.cpp +++ b/src/Mod/Part/Gui/CrossSections.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -232,29 +233,28 @@ void CrossSections::apply() section->purgeTouched(); } #else - Gui::Application* app = Gui::Application::Instance; Base::SequencerLauncher seq("Cross-sections...", obj.size() * (d.size() +1)); - app->runPythonCode("import Part\n"); - app->runPythonCode("from FreeCAD import Base\n"); + Gui::Command::runCommand(Gui::Command::App, "import Part\n"); + Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base\n"); for (std::vector::iterator it = obj.begin(); it != obj.end(); ++it) { App::Document* doc = (*it)->getDocument(); std::string s = (*it)->getNameInDocument(); s += "_cs"; - app->runPythonCode(QString::fromLatin1( + Gui::Command::runCommand(Gui::Command::App, QString::fromLatin1( "wires=list()\n" "shape=FreeCAD.getDocument(\"%1\").%2.Shape\n") .arg(QLatin1String(doc->getName())) .arg(QLatin1String((*it)->getNameInDocument())).toLatin1()); for (std::vector::iterator jt = d.begin(); jt != d.end(); ++jt) { - app->runPythonCode(QString::fromLatin1( + Gui::Command::runCommand(Gui::Command::App, QString::fromLatin1( "for i in shape.slice(Base.Vector(%1,%2,%3),%4):\n" " wires.append(i)\n" ).arg(a).arg(b).arg(c).arg(*jt).toLatin1()); seq.next(); } - app->runPythonCode(QString::fromLatin1( + Gui::Command::runCommand(Gui::Command::App, QString::fromLatin1( "comp=Part.Compound(wires)\n" "slice=FreeCAD.getDocument(\"%1\").addObject(\"Part::Feature\",\"%2\")\n" "slice.Shape=comp\n" diff --git a/src/Mod/Part/Gui/DlgFilletEdges.cpp b/src/Mod/Part/Gui/DlgFilletEdges.cpp index 8859169f8..0d4d8e2fb 100644 --- a/src/Mod/Part/Gui/DlgFilletEdges.cpp +++ b/src/Mod/Part/Gui/DlgFilletEdges.cpp @@ -679,7 +679,7 @@ void DlgFilletEdges::changeEvent(QEvent *e) int id = model->data(model->index(i, 0), Qt::UserRole).toInt(); model->setData(model->index(i, 0), QVariant(tr("Edge%1").arg(id))); } - } + } else { QWidget::changeEvent(e); } @@ -936,7 +936,7 @@ bool DlgFilletEdges::accept() "del __fillets__\n" "FreeCADGui.ActiveDocument.%2.Visibility = False\n") .arg(name).arg(shape); - Gui::Application::Instance->runPythonCode((const char*)code.toLatin1()); + Gui::Command::runCommand(Gui::Command::App, code.toLatin1()); activeDoc->commitTransaction(); activeDoc->recompute(); if (d->fillet) { diff --git a/src/Mod/Part/Gui/DlgRevolution.cpp b/src/Mod/Part/Gui/DlgRevolution.cpp index 8027801b2..bb203fd71 100644 --- a/src/Mod/Part/Gui/DlgRevolution.cpp +++ b/src/Mod/Part/Gui/DlgRevolution.cpp @@ -405,7 +405,7 @@ void DlgRevolution::accept() .arg(strAxisLink) //%12 .arg(symmetric) //13 ; - Gui::Application::Instance->runPythonCode((const char*)code.toLatin1()); + Gui::Command::runCommand(Gui::Command::App, code.toLatin1()); QByteArray to = name.toLatin1(); QByteArray from = shape.toLatin1(); Gui::Command::copyVisual(to, "ShapeColor", from); diff --git a/src/Mod/Part/Gui/Mirroring.cpp b/src/Mod/Part/Gui/Mirroring.cpp index ebd8189ae..469e12cb8 100644 --- a/src/Mod/Part/Gui/Mirroring.cpp +++ b/src/Mod/Part/Gui/Mirroring.cpp @@ -171,7 +171,7 @@ bool Mirroring::accept() .arg(this->document).arg(shape).arg(label) .arg(normx).arg(normy).arg(normz) .arg(basex).arg(basey).arg(basez); - Gui::Application::Instance->runPythonCode((const char*)code.toLatin1()); + Gui::Command::runCommand(Gui::Command::App, code.toLatin1()); QByteArray from = shape.toLatin1(); Gui::Command::copyVisual("ActiveObject", "ShapeColor", from); Gui::Command::copyVisual("ActiveObject", "LineColor", from); diff --git a/src/Mod/Part/Gui/TaskLoft.cpp b/src/Mod/Part/Gui/TaskLoft.cpp index 6d2c4cd13..24e072961 100644 --- a/src/Mod/Part/Gui/TaskLoft.cpp +++ b/src/Mod/Part/Gui/TaskLoft.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -66,8 +67,8 @@ public: LoftWidget::LoftWidget(QWidget* parent) : d(new Private()) { - Gui::Application::Instance->runPythonCode("from FreeCAD import Base"); - Gui::Application::Instance->runPythonCode("import Part"); + Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base"); + Gui::Command::runCommand(Gui::Command::App, "import Part"); d->ui.setupUi(this); d->ui.selector->setAvailableLabel(tr("Vertex/Edge/Wire/Face")); @@ -175,7 +176,7 @@ bool LoftWidget::accept() Gui::Document* doc = Gui::Application::Instance->getDocument(d->document.c_str()); if (!doc) throw Base::Exception("Document doesn't exist anymore"); doc->openCommand("Loft"); - Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); + Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1()); doc->getDocument()->recompute(); App::DocumentObject* obj = doc->getDocument()->getActiveObject(); if (obj && !obj->isValid()) { diff --git a/src/Mod/Part/Gui/TaskOffset.cpp b/src/Mod/Part/Gui/TaskOffset.cpp index 58dd22265..2114b586d 100644 --- a/src/Mod/Part/Gui/TaskOffset.cpp +++ b/src/Mod/Part/Gui/TaskOffset.cpp @@ -68,8 +68,8 @@ public: OffsetWidget::OffsetWidget(Part::Offset* offset, QWidget* parent) : d(new Private()) { - Gui::Application::Instance->runPythonCode("from FreeCAD import Base"); - Gui::Application::Instance->runPythonCode("import Part"); + Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base"); + Gui::Command::runCommand(Gui::Command::App, "import Part"); d->offset = offset; d->ui.setupUi(this); diff --git a/src/Mod/Part/Gui/TaskShapeBuilder.cpp b/src/Mod/Part/Gui/TaskShapeBuilder.cpp index 5ead53226..baa099d77 100644 --- a/src/Mod/Part/Gui/TaskShapeBuilder.cpp +++ b/src/Mod/Part/Gui/TaskShapeBuilder.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -85,29 +86,28 @@ namespace PartGui { } }; } - -class ShapeBuilderWidget::Private -{ -public: + +class ShapeBuilderWidget::Private +{ +public: Ui_TaskShapeBuilder ui; QButtonGroup bg; ShapeSelection* gate; Private() - { - } - ~Private() - { - } -}; + { + Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base"); + Gui::Command::runCommand(Gui::Command::App, "import Part"); + } + ~Private() + { + } +}; /* TRANSLATOR PartGui::ShapeBuilderWidget */ ShapeBuilderWidget::ShapeBuilderWidget(QWidget* parent) : d(new Private()) { - Gui::Application::Instance->runPythonCode("from FreeCAD import Base"); - Gui::Application::Instance->runPythonCode("import Part"); - d->ui.setupUi(this); d->ui.label->setText(QString()); d->bg.addButton(d->ui.radioButtonEdgeFromVertex, 0); @@ -157,10 +157,10 @@ void ShapeBuilderWidget::on_createButton_clicked() } doc->getDocument()->recompute(); Gui::Selection().clearSelection(); - } - catch (const Base::Exception& e) { - Base::Console().Error("%s\n", e.what()); - } + } + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + } } void ShapeBuilderWidget::createEdgeFromVertex() @@ -200,14 +200,14 @@ void ShapeBuilderWidget::createEdgeFromVertex() ).arg(elements[0]).arg(elements[1]); try { - Gui::Application::Instance->activeDocument()->openCommand("Edge"); - Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); - Gui::Application::Instance->activeDocument()->commitCommand(); - } - catch (const Base::Exception&) { - Gui::Application::Instance->activeDocument()->abortCommand(); - throw; - } + Gui::Application::Instance->activeDocument()->openCommand("Edge"); + Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1()); + Gui::Application::Instance->activeDocument()->commitCommand(); + } + catch (const Base::Exception&) { + Gui::Application::Instance->activeDocument()->abortCommand(); + throw; + } } void ShapeBuilderWidget::createFaceFromVertex() @@ -252,14 +252,14 @@ void ShapeBuilderWidget::createFaceFromVertex() } try { - Gui::Application::Instance->activeDocument()->openCommand("Face"); - Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); - Gui::Application::Instance->activeDocument()->commitCommand(); - } - catch (const Base::Exception&) { - Gui::Application::Instance->activeDocument()->abortCommand(); - throw; - } + Gui::Application::Instance->activeDocument()->openCommand("Face"); + Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1()); + Gui::Application::Instance->activeDocument()->commitCommand(); + } + catch (const Base::Exception&) { + Gui::Application::Instance->activeDocument()->abortCommand(); + throw; + } } void ShapeBuilderWidget::createFaceFromEdge() @@ -304,14 +304,14 @@ void ShapeBuilderWidget::createFaceFromEdge() } try { - Gui::Application::Instance->activeDocument()->openCommand("Face"); - Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); - Gui::Application::Instance->activeDocument()->commitCommand(); - } - catch (const Base::Exception&) { - Gui::Application::Instance->activeDocument()->abortCommand(); - throw; - } + Gui::Application::Instance->activeDocument()->openCommand("Face"); + Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1()); + Gui::Application::Instance->activeDocument()->commitCommand(); + } + catch (const Base::Exception&) { + Gui::Application::Instance->activeDocument()->abortCommand(); + throw; + } } void ShapeBuilderWidget::createShellFromFace() @@ -367,14 +367,14 @@ void ShapeBuilderWidget::createShellFromFace() } try { - Gui::Application::Instance->activeDocument()->openCommand("Shell"); - Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); - Gui::Application::Instance->activeDocument()->commitCommand(); - } - catch (const Base::Exception&) { - Gui::Application::Instance->activeDocument()->abortCommand(); - throw; - } + Gui::Application::Instance->activeDocument()->openCommand("Shell"); + Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1()); + Gui::Application::Instance->activeDocument()->commitCommand(); + } + catch (const Base::Exception&) { + Gui::Application::Instance->activeDocument()->abortCommand(); + throw; + } } void ShapeBuilderWidget::createSolidFromShell() @@ -419,14 +419,14 @@ void ShapeBuilderWidget::createSolidFromShell() } try { - Gui::Application::Instance->activeDocument()->openCommand("Solid"); - Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); - Gui::Application::Instance->activeDocument()->commitCommand(); - } - catch (const Base::Exception&) { - Gui::Application::Instance->activeDocument()->abortCommand(); - throw; - } + Gui::Application::Instance->activeDocument()->openCommand("Solid"); + Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1()); + Gui::Application::Instance->activeDocument()->commitCommand(); + } + catch (const Base::Exception&) { + Gui::Application::Instance->activeDocument()->abortCommand(); + throw; + } } void ShapeBuilderWidget::switchMode(int mode) diff --git a/src/Mod/Part/Gui/TaskSweep.cpp b/src/Mod/Part/Gui/TaskSweep.cpp index fe6713651..d05db6a00 100644 --- a/src/Mod/Part/Gui/TaskSweep.cpp +++ b/src/Mod/Part/Gui/TaskSweep.cpp @@ -43,6 +43,7 @@ #include #include +#include #include #include #include @@ -127,8 +128,8 @@ public: SweepWidget::SweepWidget(QWidget* parent) : d(new Private()) { - Gui::Application::Instance->runPythonCode("from FreeCAD import Base"); - Gui::Application::Instance->runPythonCode("import Part"); + Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base"); + Gui::Command::runCommand(Gui::Command::App, "import Part"); d->ui.setupUi(this); d->ui.selector->setAvailableLabel(tr("Vertex/Edge/Wire/Face")); @@ -321,7 +322,7 @@ bool SweepWidget::accept() Gui::Document* doc = Gui::Application::Instance->getDocument(d->document.c_str()); if (!doc) throw Base::Exception("Document doesn't exist anymore"); doc->openCommand("Sweep"); - Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); + Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1()); doc->getDocument()->recompute(); App::DocumentObject* obj = doc->getDocument()->getActiveObject(); if (obj && !obj->isValid()) { diff --git a/src/Mod/Part/Gui/TaskThickness.cpp b/src/Mod/Part/Gui/TaskThickness.cpp index c7c113815..f53d42501 100644 --- a/src/Mod/Part/Gui/TaskThickness.cpp +++ b/src/Mod/Part/Gui/TaskThickness.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include @@ -90,8 +91,8 @@ public: ThicknessWidget::ThicknessWidget(Part::Thickness* thickness, QWidget* parent) : d(new Private()) { - Gui::Application::Instance->runPythonCode("from FreeCAD import Base"); - Gui::Application::Instance->runPythonCode("import Part"); + Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base"); + Gui::Command::runCommand(Gui::Command::App, "import Part"); d->thickness = thickness; d->ui.setupUi(this);