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:
parent
cc2063c7ad
commit
732918e5f2
|
@ -100,7 +100,39 @@ class CadQueryExecuteScript:
|
||||||
FreeCAD.Console.PrintMessage("\r\n" + msg + cqCodePane.file.path)
|
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."""
|
"""CadQuery's command to open a script file."""
|
||||||
previousPath = None
|
previousPath = None
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,8 @@ class CadQueryWorkbench (Workbench):
|
||||||
#logging.basicConfig(filename='/home/jwright/Documents/log.txt', level=logging.DEBUG)
|
#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
|
#We have our own CQ menu that's added when the user chooses our workbench
|
||||||
commands = ['CadQueryOpenScript', 'CadQuerySaveScript', 'CadQuerySaveAsScript', 'CadQueryExecuteScript',
|
commands = ['CadQueryNewScript', 'CadQueryOpenScript', 'CadQuerySaveScript', 'CadQuerySaveAsScript', 'CadQueryExecuteScript',
|
||||||
'CadQueryCloseScript']
|
'CadQueryCloseScript', 'Separator']
|
||||||
self.appendMenu('CadQuery', commands)
|
self.appendMenu('CadQuery', commands)
|
||||||
|
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
|
@ -141,6 +141,7 @@ class CadQueryWorkbench (Workbench):
|
||||||
# FreeCAD.Console.PrintMessage(widget.objectName())
|
# FreeCAD.Console.PrintMessage(widget.objectName())
|
||||||
# widget.setVisible(True)
|
# widget.setVisible(True)
|
||||||
|
|
||||||
|
FreeCADGui.addCommand('CadQueryNewScript', CadQueryNewScript())
|
||||||
FreeCADGui.addCommand('CadQueryOpenScript', CadQueryOpenScript())
|
FreeCADGui.addCommand('CadQueryOpenScript', CadQueryOpenScript())
|
||||||
FreeCADGui.addCommand('CadQuerySaveScript', CadQuerySaveScript())
|
FreeCADGui.addCommand('CadQuerySaveScript', CadQuerySaveScript())
|
||||||
FreeCADGui.addCommand('CadQuerySaveAsScript', CadQuerySaveAsScript())
|
FreeCADGui.addCommand('CadQuerySaveAsScript', CadQuerySaveAsScript())
|
||||||
|
|
5
CadQuery/Templates/script_template.py
Normal file
5
CadQuery/Templates/script_template.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# This is a CadQuery script template
|
||||||
|
# Add your script code below
|
||||||
|
|
||||||
|
# Length units
|
||||||
|
length_uom = 'mm'
|
Loading…
Reference in New Issue
Block a user