]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add LaunchScript command
authorvsv <vsv@opencascade.com>
Wed, 22 Aug 2018 14:50:23 +0000 (17:50 +0300)
committervsv <vsv@opencascade.com>
Wed, 22 Aug 2018 14:50:37 +0000 (17:50 +0300)
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 0df4bea8dd826cefabd7bf35be876babd2cb3dbe..591487168c962499900eb8002b6d29729c9eaa1c 100755 (executable)
@@ -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 <PyConsole_Console.h>
+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
index 1d06627571ead63e6a9797f7af00a1b879205e03..84eb52ecee11ebf6d7d51826142ae8828a9e1c5b 100755 (executable)
@@ -393,6 +393,8 @@ signals:
 
   /// Open preferences dialog box
   void onPreferences();
+
+  void onFileExec();
 #endif
 
   /// Activates/deactivates the trihedron in the viewer AIS context