Skip to content

Commit

Permalink
Merge pull request #106 from jmwright/filenames
Browse files Browse the repository at this point in the history
Finished fixing dash support in filenames.
  • Loading branch information
jmwright committed Oct 21, 2017
2 parents a198182 + 0661191 commit 7607804
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gui/Command.py
Expand Up @@ -104,7 +104,7 @@ def Activated(self):

Shared.closeActiveCodeWindow()

class CadQueryExecuteExample:
class CadQueryOpenExample:
exFile = None

def __init__(self, exFile):
Expand Down
11 changes: 9 additions & 2 deletions Helpers.py
@@ -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
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion InitGui.py
Expand Up @@ -118,6 +118,6 @@ def ListExamples():
# 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())
12 changes: 11 additions & 1 deletion Shared.py
Expand Up @@ -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)

Expand All @@ -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]
Expand Down

0 comments on commit 7607804

Please sign in to comment.