Finished fixing dash support in filenames.

This commit is contained in:
Jeremy Mack Wright 2017-10-21 07:31:40 -04:00
parent a198182e15
commit 0661191ff8
4 changed files with 22 additions and 5 deletions

View File

@ -104,7 +104,7 @@ class CadQueryCloseScript:
Shared.closeActiveCodeWindow()
class CadQueryExecuteExample:
class CadQueryOpenExample:
exFile = None
def __init__(self, exFile):

View File

@ -1,4 +1,5 @@
# (c) 2014-2016 Jeremy Wright Apache 2.0 License
import sys
def show(cqObject, rgba=(204, 204, 204, 0.0)):
import FreeCAD
@ -24,14 +25,20 @@ def show(cqObject, rgba=(204, 204, 204, 0.0)):
docname = os.path.splitext(os.path.basename(cqCodePane.file.path))[0]
# Make sure we replace any troublesome characters
for ch in ['&', '#', '.', '-', '$', '%', ',', ' ']:
for ch in ['&', '#', '.', '$', '%', ',', ' ']:
if ch in docname:
docname = docname.replace(ch, "")
# Translate dashes so that they can be safetly used since theyare common
if '-' in docname:
docname = docname.replace('-', "__")
# If the matching 3D view has been closed, we need to open a new one
try:
FreeCAD.getDocument(docname)
except:
except NameError:
# FreeCAD.Console.PrintError("Could not find the model document or invalid characters were used in the filename.\r\n")
FreeCAD.newDocument(docname)
ad = FreeCAD.activeDocument()

View File

@ -118,6 +118,6 @@ FreeCADGui.addCommand('CadQueryClearOutput', CadQueryClearOutput())
# Step through and add an Examples submenu item for each example
dirs = CadQueryWorkbench.ListExamples()
for curFile in dirs:
FreeCADGui.addCommand(curFile, CadQueryExecuteExample(curFile))
FreeCADGui.addCommand(curFile, CadQueryOpenExample(curFile))
FreeCADGui.addWorkbench(CadQueryWorkbench())

View File

@ -14,6 +14,10 @@ def clearActiveDocument():
return
winName = currentWin.windowTitle().split(" ")[0].split('.')[0]
# Translate dashes so that they can be safetly used since theyare common
if '-' in winName:
winName= winName.replace('-', "__")
try:
doc = FreeCAD.getDocument(winName)
@ -35,11 +39,17 @@ def getActiveCodePane():
# If our current subwindow doesn't contain a script, we need to find the one that does
mdiWin = mdi.currentSubWindow()
if mdiWin == None: return None # We need to warn the caller that there is no code pane
windowTitle = mdiWin.windowTitle()
if mdiWin == 0 or ".py" not in mdiWin.windowTitle():
if '__' in mdiWin.windowTitle():
windowTitle = mdiWin.windowTitle().replace("__", '-')
subList = mdi.subWindowList()
for sub in subList:
if sub.windowTitle() == mdiWin.windowTitle().split(" ")[0] + ".py":
if sub.windowTitle() == windowTitle.split(" ")[0] + ".py":
mdiWin = sub
winName = mdiWin.windowTitle().split('.')[0]