diff --git a/CadQuery/Gui/Command.py b/CadQuery/Gui/Command.py index 139092d..ce3b751 100644 --- a/CadQuery/Gui/Command.py +++ b/CadQuery/Gui/Command.py @@ -100,7 +100,39 @@ class CadQueryExecuteScript: FreeCAD.Console.PrintMessage("\r\n" + msg + cqCodePane.file.path) -class CadQueryOpenScript(): +class CadQueryNewScript: + """CadQuery's command to start a new script file.""" + def GetResources(self): + return {"MenuText": "New Script", + "Accel": "Alt+N", + "ToolTip": "Starts a new CadQuery script", + "Pixmap": ":/icons/document-new.svg"} + + def IsActive(self): + return True + + def Activated(self): + import os, module_locator + + module_base_path = module_locator.module_path() + templ_dir_path = os.path.join(module_base_path, 'Templates') + + #We've created a library that FreeCAD can use as well to open CQ files + ImportCQ.open(os.path.join(templ_dir_path, 'script_template.py')) + + #Getting the main window will allow us to find the children we need to work with + mw = FreeCADGui.getMainWindow() + + #We need this so we can load the file into it + cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane") + + #Set the file name to be blank so that we can't save over the template + cqCodePane.file.path = '' + + FreeCAD.Console.PrintMessage("New Clicked\r\n") + + +class CadQueryOpenScript: """CadQuery's command to open a script file.""" previousPath = None diff --git a/CadQuery/InitGui.py b/CadQuery/InitGui.py index 5597600..93f8bfb 100644 --- a/CadQuery/InitGui.py +++ b/CadQuery/InitGui.py @@ -27,8 +27,8 @@ class CadQueryWorkbench (Workbench): #logging.basicConfig(filename='/home/jwright/Documents/log.txt', level=logging.DEBUG) #We have our own CQ menu that's added when the user chooses our workbench - commands = ['CadQueryOpenScript', 'CadQuerySaveScript', 'CadQuerySaveAsScript', 'CadQueryExecuteScript', - 'CadQueryCloseScript'] + commands = ['CadQueryNewScript', 'CadQueryOpenScript', 'CadQuerySaveScript', 'CadQuerySaveAsScript', 'CadQueryExecuteScript', + 'CadQueryCloseScript', 'Separator'] self.appendMenu('CadQuery', commands) def Activated(self): @@ -141,6 +141,7 @@ class CadQueryWorkbench (Workbench): # FreeCAD.Console.PrintMessage(widget.objectName()) # widget.setVisible(True) +FreeCADGui.addCommand('CadQueryNewScript', CadQueryNewScript()) FreeCADGui.addCommand('CadQueryOpenScript', CadQueryOpenScript()) FreeCADGui.addCommand('CadQuerySaveScript', CadQuerySaveScript()) FreeCADGui.addCommand('CadQuerySaveAsScript', CadQuerySaveAsScript()) diff --git a/CadQuery/Templates/script_template.py b/CadQuery/Templates/script_template.py new file mode 100644 index 0000000..88dac12 --- /dev/null +++ b/CadQuery/Templates/script_template.py @@ -0,0 +1,5 @@ +# This is a CadQuery script template +# Add your script code below + +# Length units +length_uom = 'mm'