From 003ba758a140a67fea5b036c06d2a6a59e74ba79 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 22 Aug 2018 17:50:23 +0300 Subject: [PATCH] Add LaunchScript command --- src/XGUI/XGUI_Workshop.cpp | 22 ++++++++++++++++++++++ src/XGUI/XGUI_Workshop.h | 2 ++ 2 files changed, 24 insertions(+) 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 -- 2.39.2