From: vsv Date: Wed, 22 Aug 2018 14:50:23 +0000 (+0300) Subject: Add LaunchScript command X-Git-Tag: SHAPER_V9_1_0RC1~35 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=003ba758a140a67fea5b036c06d2a6a59e74ba79;p=modules%2Fshaper.git Add LaunchScript command --- diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 0df4bea8d..591487168 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -477,6 +477,10 @@ void XGUI_Workshop::initMenu() QIcon(":pictures/open.png"), QKeySequence::Open); aCommand->connectTo(this, SLOT(onOpen())); + aCommand = aGroup->addFeature("EXEC_CMD", tr("Launch Script"), tr("Launch Python script file"), + QIcon(":pictures/assembly.png"), QKeySequence()); + aCommand->connectTo(this, SLOT(onFileExec())); + aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"), QIcon(":pictures/preferences.png"), QKeySequence::Preferences); aCommand->connectTo(this, SLOT(onPreferences())); @@ -2787,3 +2791,21 @@ void XGUI_Workshop::moveOutFolder(bool isBefore) updateCommandStatus(); } + +#ifndef HAVE_SALOME +#include +void XGUI_Workshop::onFileExec() +{ + QString aScript = QFileDialog::getOpenFileName(myMainWindow, tr("Open script"), + QString(), "Python script (*.py)"); + + if (!aScript.isNull()) { + PyConsole_Console* aConsole = myMainWindow->pythonConsole(); + aConsole->execAndWait(QString("f = open('%1', 'rb')").arg(aScript)); + QString aExecStr = + QString("exec(compile(f.read(), '%1', 'exec'))").arg(aScript); + aConsole->execAndWait(aExecStr); + aConsole->execAndWait("f.close()"); + } +} +#endif diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 1d0662757..84eb52ece 100755 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -393,6 +393,8 @@ signals: /// Open preferences dialog box void onPreferences(); + + void onFileExec(); #endif /// Activates/deactivates the trihedron in the viewer AIS context