From 9c894268b819311fa07e24d125749d6a42a51dea Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Thu, 18 Dec 2014 13:42:07 -0500 Subject: [PATCH] Added a Settings file to hold configuration options in preparation for adding better support for external editors. --- CadQuery/Gui/Command.py | 10 ++++++++-- CadQuery/Settings.py | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 CadQuery/Settings.py diff --git a/CadQuery/Gui/Command.py b/CadQuery/Gui/Command.py index 7ce7a81..f8cf3b1 100644 --- a/CadQuery/Gui/Command.py +++ b/CadQuery/Gui/Command.py @@ -6,6 +6,7 @@ import FreeCAD, FreeCADGui from PySide import QtGui import ExportCQ, ImportCQ import module_locator +import Settings #Distinguish python built-in open function from the one declared here if open.__module__ == '__builtin__': @@ -213,8 +214,9 @@ class CadQuerySaveScript: cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane") #If the code pane doesn't have a filename, we need to present the save as dialog - if len(cqCodePane.file.path) == 0 or os.path.basename(cqCodePane.file.path) == 'script_template.py': - FreeCAD.Console.PrintMessage("\r\nYou cannot save a blank file or save over a template file.") + if len(cqCodePane.file.path) == 0 or os.path.basename(cqCodePane.file.path) == 'script_template.py' \ + or os.path.split(cqCodePane.file.path)[-2].endswith('Examples'): + FreeCAD.Console.PrintError("\r\nYou cannot save over a blank file, example file or template file.") CadQuerySaveAsScript().Activated() @@ -223,6 +225,10 @@ class CadQuerySaveScript: #Rely on our export library to help us save the file ExportCQ.save() + #Execute the script if the user has asked for it + if Settings.execute_on_save: + CadQueryExecuteScript().Activated() + class CadQuerySaveAsScript: """CadQuery's command to save-as a script file""" previousPath = None diff --git a/CadQuery/Settings.py b/CadQuery/Settings.py new file mode 100644 index 0000000..e7571ce --- /dev/null +++ b/CadQuery/Settings.py @@ -0,0 +1,2 @@ +execute_on_save = False # Automatically execute a script every time you save +use_external_editor = False # Automatically reloads and executes a file when an external change is made \ No newline at end of file