Skip to content

Commit 7607804

Browse files
authored
Merge pull request #106 from jmwright/filenames
Finished fixing dash support in filenames.
2 parents a198182 + 0661191 commit 7607804

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

Gui/Command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def Activated(self):
104104

105105
Shared.closeActiveCodeWindow()
106106

107-
class CadQueryExecuteExample:
107+
class CadQueryOpenExample:
108108
exFile = None
109109

110110
def __init__(self, exFile):

Helpers.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# (c) 2014-2016 Jeremy Wright Apache 2.0 License
2+
import sys
23

34
def show(cqObject, rgba=(204, 204, 204, 0.0)):
45
import FreeCAD
@@ -24,14 +25,20 @@ def show(cqObject, rgba=(204, 204, 204, 0.0)):
2425
docname = os.path.splitext(os.path.basename(cqCodePane.file.path))[0]
2526

2627
# Make sure we replace any troublesome characters
27-
for ch in ['&', '#', '.', '-', '$', '%', ',', ' ']:
28+
for ch in ['&', '#', '.', '$', '%', ',', ' ']:
2829
if ch in docname:
2930
docname = docname.replace(ch, "")
3031

32+
# Translate dashes so that they can be safetly used since theyare common
33+
if '-' in docname:
34+
docname = docname.replace('-', "__")
35+
3136
# If the matching 3D view has been closed, we need to open a new one
3237
try:
3338
FreeCAD.getDocument(docname)
34-
except:
39+
except NameError:
40+
# FreeCAD.Console.PrintError("Could not find the model document or invalid characters were used in the filename.\r\n")
41+
3542
FreeCAD.newDocument(docname)
3643

3744
ad = FreeCAD.activeDocument()

InitGui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@ def ListExamples():
118118
# Step through and add an Examples submenu item for each example
119119
dirs = CadQueryWorkbench.ListExamples()
120120
for curFile in dirs:
121-
FreeCADGui.addCommand(curFile, CadQueryExecuteExample(curFile))
121+
FreeCADGui.addCommand(curFile, CadQueryOpenExample(curFile))
122122

123123
FreeCADGui.addWorkbench(CadQueryWorkbench())

Shared.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def clearActiveDocument():
1414
return
1515
winName = currentWin.windowTitle().split(" ")[0].split('.')[0]
1616

17+
# Translate dashes so that they can be safetly used since theyare common
18+
if '-' in winName:
19+
winName= winName.replace('-', "__")
20+
1721
try:
1822
doc = FreeCAD.getDocument(winName)
1923

@@ -35,11 +39,17 @@ def getActiveCodePane():
3539
# If our current subwindow doesn't contain a script, we need to find the one that does
3640
mdiWin = mdi.currentSubWindow()
3741
if mdiWin == None: return None # We need to warn the caller that there is no code pane
42+
43+
windowTitle = mdiWin.windowTitle()
44+
3845
if mdiWin == 0 or ".py" not in mdiWin.windowTitle():
46+
if '__' in mdiWin.windowTitle():
47+
windowTitle = mdiWin.windowTitle().replace("__", '-')
48+
3949
subList = mdi.subWindowList()
4050

4151
for sub in subList:
42-
if sub.windowTitle() == mdiWin.windowTitle().split(" ")[0] + ".py":
52+
if sub.windowTitle() == windowTitle.split(" ")[0] + ".py":
4353
mdiWin = sub
4454

4555
winName = mdiWin.windowTitle().split('.')[0]

0 commit comments

Comments
 (0)