Allow to run script in global environment

This commit is contained in:
wmayer 2012-06-29 13:57:22 +02:00
parent 013b5f0dce
commit 487a041c89
4 changed files with 110 additions and 88 deletions

View File

@ -1,45 +1,62 @@
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Gui::Dialog::DlgSettingsMacro</class>
<widget class="QWidget" name="Gui::Dialog::DlgSettingsMacro" >
<property name="geometry" >
<widget class="QWidget" name="Gui::Dialog::DlgSettingsMacro">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>384</width>
<height>388</height>
<width>391</width>
<height>407</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>Macro</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="QGroupBox" name="GroupBox6" >
<property name="title" >
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>General macro settings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="Gui::PrefCheckBox" name="PrefCheckBox_LocalEnv">
<property name="text">
<string>Run macros in local environment</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>LocalEnvironment</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Macro</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="GroupBox6">
<property name="title">
<string>Macro recording settings</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<layout class="QGridLayout">
<property name="margin">
<number>9</number>
</property>
<property name="spacing" >
<property name="spacing">
<number>6</number>
</property>
<item row="3" column="0" >
<item row="3" column="0">
<spacer>
<property name="orientation" >
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
@ -47,56 +64,56 @@
</property>
</spacer>
</item>
<item row="2" column="0" >
<widget class="QGroupBox" name="groupBox4" >
<property name="title" >
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox4">
<property name="title">
<string>Logging Commands</string>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>11</number>
</property>
<property name="spacing" >
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>11</number>
</property>
<item>
<widget class="Gui::PrefCheckBox" name="PConsoleCheckBox" >
<property name="text" >
<widget class="Gui::PrefCheckBox" name="PConsoleCheckBox">
<property name="text">
<string>Show script commands in python console</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0" >
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>ScriptToPyConsole</cstring>
</property>
<property name="prefPath" stdset="0" >
<property name="prefPath" stdset="0">
<cstring>Macro</cstring>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="FileLogCheckBox" >
<property name="text" >
<widget class="Gui::PrefCheckBox" name="FileLogCheckBox">
<property name="text">
<string>Log all commands issued by menus to file:</string>
</property>
<property name="prefEntry" stdset="0" >
<property name="prefEntry" stdset="0">
<cstring>ScriptToFile</cstring>
</property>
<property name="prefPath" stdset="0" >
<property name="prefPath" stdset="0">
<cstring>Macro</cstring>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefFileChooser" name="MacroPath_2" >
<property name="fileName" >
<widget class="Gui::PrefFileChooser" name="MacroPath_2">
<property name="fileName">
<string>FullScript.FCScript</string>
</property>
<property name="prefEntry" stdset="0" >
<property name="prefEntry" stdset="0">
<cstring>ScriptFile</cstring>
</property>
<property name="prefPath" stdset="0" >
<property name="prefPath" stdset="0">
<cstring>Macro</cstring>
</property>
</widget>
@ -104,46 +121,46 @@
</layout>
</widget>
</item>
<item row="1" column="0" >
<widget class="QGroupBox" name="GroupBox7" >
<property name="title" >
<item row="1" column="0">
<widget class="QGroupBox" name="GroupBox7">
<property name="title">
<string>Gui commands</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<layout class="QGridLayout">
<property name="margin">
<number>11</number>
</property>
<property name="spacing" >
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="Gui::PrefCheckBox" name="PrefCheckBox_RecordGui" >
<property name="text" >
<item row="0" column="0">
<widget class="Gui::PrefCheckBox" name="PrefCheckBox_RecordGui">
<property name="text">
<string>Recording GUI commands</string>
</property>
<property name="checked" >
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0" >
<property name="prefEntry" stdset="0">
<cstring>RecordGui</cstring>
</property>
<property name="prefPath" stdset="0" >
<property name="prefPath" stdset="0">
<cstring>Macro</cstring>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="Gui::PrefCheckBox" name="PrefCheckBox_GuiAsComment" >
<property name="text" >
<item row="1" column="0">
<widget class="Gui::PrefCheckBox" name="PrefCheckBox_GuiAsComment">
<property name="text">
<string>Record as comment</string>
</property>
<property name="checked" >
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0" >
<property name="prefEntry" stdset="0">
<cstring>GuiAsComment</cstring>
</property>
<property name="prefPath" stdset="0" >
<property name="prefPath" stdset="0">
<cstring>Macro</cstring>
</property>
</widget>
@ -151,27 +168,27 @@
</layout>
</widget>
</item>
<item row="0" column="0" >
<widget class="QGroupBox" name="GroupBox8" >
<property name="title" >
<item row="0" column="0">
<widget class="QGroupBox" name="GroupBox8">
<property name="title">
<string>Macro path</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<layout class="QGridLayout">
<property name="margin">
<number>11</number>
</property>
<property name="spacing" >
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="Gui::PrefFileChooser" name="MacroPath" >
<property name="mode" >
<item row="0" column="0">
<widget class="Gui::PrefFileChooser" name="MacroPath">
<property name="mode">
<enum>Gui::FileChooser::Directory</enum>
</property>
<property name="prefEntry" stdset="0" >
<property name="prefEntry" stdset="0">
<cstring>MacroPath</cstring>
</property>
<property name="prefPath" stdset="0" >
<property name="prefPath" stdset="0">
<cstring>Macro</cstring>
</property>
</widget>
@ -184,21 +201,22 @@
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11" />
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
<container>0</container>
<pixmap></pixmap>
<class>Gui::FileChooser</class>
<extends>QWidget</extends>
<header>Gui/FileDialog.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefFileChooser</class>
<extends>Gui::FileChooser</extends>
<header>Gui/PrefWidgets.h</header>
<container>0</container>
<pixmap></pixmap>
</customwidget>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources/>
@ -209,11 +227,11 @@
<receiver>PrefCheckBox_GuiAsComment</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>

View File

@ -54,6 +54,7 @@ DlgSettingsMacroImp::~DlgSettingsMacroImp()
void DlgSettingsMacroImp::saveSettings()
{
PrefCheckBox_LocalEnv->onSave();
MacroPath->onSave();
PrefCheckBox_RecordGui->onSave();
PrefCheckBox_GuiAsComment->onSave();
@ -64,6 +65,7 @@ void DlgSettingsMacroImp::saveSettings()
void DlgSettingsMacroImp::loadSettings()
{
PrefCheckBox_LocalEnv->onRestore();
MacroPath->onRestore();
PrefCheckBox_RecordGui->onRestore();
PrefCheckBox_GuiAsComment->onRestore();

View File

@ -71,6 +71,7 @@ void MacroManager::OnChange(Base::Subject<const char*> &rCaller, const char * sR
this->recordGui = this->params->GetBool("RecordGui", true);
this->guiAsComment = this->params->GetBool("GuiAsComment", true);
this->scriptToPyConsole = this->params->GetBool("ScriptToPyConsole", true);
this->localEnv = this->params->GetBool("LocalEnvironment", true);
}
void MacroManager::open(MacroType eType,const char *sName)
@ -228,7 +229,7 @@ void MacroManager::run(MacroType eType,const char *sName)
PythonRedirector std_out("stdout",pyout);
PythonRedirector std_err("stderr",pyerr);
//The given path name is expected to be Utf-8
Base::Interpreter().runFile(sName, true);
Base::Interpreter().runFile(sName, this->localEnv);
}
catch (const Base::SystemExitException&) {
Base::PyGILStateLocker lock;

View File

@ -98,6 +98,7 @@ protected:
bool recordGui;
bool guiAsComment;
bool scriptToPyConsole;
bool localEnv;
PythonConsole* pyConsole; // link to the python console
PythonDebugger* pyDebugger;
Base::Reference<ParameterGrp> params; // link to the Macro parameter group