diff --git a/CadQuery/Gui/Command.py b/CadQuery/Gui/Command.py index ad6861e..e5181b1 100644 --- a/CadQuery/Gui/Command.py +++ b/CadQuery/Gui/Command.py @@ -75,18 +75,7 @@ class CadQueryCloseScript: if filename is not None: ExportCQ.save(filename) - # Close the matching 3D view if it's open - if cqCodePane.file.path is not None: - docname = os.path.splitext(os.path.basename(cqCodePane.file.path))[0] - - try: - FreeCAD.closeDocument(docname) - except: - # Assume that the document has already been closed - pass - - # Clear our script and whatever was rendered by it out - cqCodePane.file.close() + Shared.closeActiveCodeWindow() class CadQueryExecuteExample: exFile = None @@ -214,9 +203,6 @@ class CadQueryOpenScript: # Make sure the user didn't click cancel if filename[0]: - # We need to close any file that's already open in the editor window - CadQueryCloseScript().Activated() - self.previousPath = filename[0] # Append this script's directory to sys.path diff --git a/CadQuery/Shared.py b/CadQuery/Shared.py index c2d4065..24b5ca9 100644 --- a/CadQuery/Shared.py +++ b/CadQuery/Shared.py @@ -45,9 +45,7 @@ def getActiveCodePane(): return cqCodePane -def getActiveCodeWindow(): - """Gets the currently active code window (that holds the pane), even if the associated 3D view window has focus""" - +def closeActiveCodeWindow(): mw = FreeCADGui.getMainWindow() mdi = mw.findChild(QtGui.QMdiArea) @@ -59,11 +57,11 @@ def getActiveCodeWindow(): subList = mdi.subWindowList() for sub in subList: - if sub.windowTitle() == mdiWin.windowTitle() + ".py": - mdiWin = sub - - return mdiWin + if sub.windowTitle() == mdiWin.windowTitle().split(" ")[0] + ".py": + sub.close() + return + mdiWin.close() def setActiveWindowTitle(title): """Sets the title of the currently active MDI window, as long as it is a scripting window"""