Clicking New Script opens a template file with some skeleton comments/code showing best practices. Needs to have it fixed so that Save-As always comes up if the user tries to save over the template.

This commit is contained in:
Jeremy Wright 2014-12-13 23:59:54 -05:00
parent cc2063c7ad
commit 732918e5f2
3 changed files with 41 additions and 3 deletions

View File

@ -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

View File

@ -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())

View File

@ -0,0 +1,5 @@
# This is a CadQuery script template
# Add your script code below
# Length units
length_uom = 'mm'