diff --git a/Gui/Command.py b/Gui/Command.py index 8e68f27..ef586c5 100644 --- a/Gui/Command.py +++ b/Gui/Command.py @@ -104,7 +104,7 @@ def Activated(self): Shared.closeActiveCodeWindow() -class CadQueryExecuteExample: +class CadQueryOpenExample: exFile = None def __init__(self, exFile): diff --git a/Helpers.py b/Helpers.py index f396035..2388680 100644 --- a/Helpers.py +++ b/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 @@ -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() diff --git a/InitGui.py b/InitGui.py index 5f8468e..fe829fe 100644 --- a/InitGui.py +++ b/InitGui.py @@ -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()) diff --git a/Shared.py b/Shared.py index 96fb214..00ce651 100644 --- a/Shared.py +++ b/Shared.py @@ -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]