Got save as working, still need to handle tabs gracefully.

This commit is contained in:
Jeremy Mack Wright 2016-10-04 17:07:51 -04:00
parent cb1221da2c
commit 2c18886dd5
2 changed files with 65 additions and 3 deletions

View File

@ -302,7 +302,7 @@ class CadQuerySaveAsScript:
def Activated(self):
#So we can open the save-as dialog
mw = FreeCADGui.getMainWindow()
cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane")
cqCodePane = Shared.getActiveCodePane()
#Try to keep track of the previous path used to open as a convenience to the user
if self.previousPath is None:
@ -323,6 +323,9 @@ class CadQuerySaveAsScript:
#Assume that there was no 3D view to close
pass
# Change the name of our script window's tab
Shared.setActiveWindowTitle(os.path.basename(filename[0]))
#Save the file before closing the original and the re-rendering the new one
ExportCQ.save(filename[0])
CadQueryExecuteScript().Activated()

View File

@ -23,10 +23,69 @@ def clearActiveDocument():
def getActiveCodePane():
"""Gets the currently active code pane, even if its 3D view is selected."""
# TODO: Make sure that the code pane is selected, even if the associated 3D view currently has focus
# Grab our code editor so we can interact with it
mw = FreeCADGui.getMainWindow()
mdi = mw.findChild(QtGui.QMdiArea)
winName = mdi.currentSubWindow().windowTitle().split('.')[0]
# If our current subwindow doesn't contain a script, we need to find the one that does
mdiWin = mdi.currentSubWindow()
if mdiWin == 0 or ".py" not in mdiWin.windowTitle():
subList = mdi.subWindowList()
for sub in subList:
print(sub.windowTitle())
if sub.windowTitle() == mdiWin.windowTitle().split(" ")[0] + ".py":
mdiWin = sub
winName = mdiWin.windowTitle().split('.')[0]
cqCodePane = mw.findChild(QtGui.QPlainTextEdit, "cqCodePane_" + winName)
return cqCodePane
return cqCodePane
def getActiveCodeWindow():
"""Gets the currently active code window (that holds the pane), even if the associated 3D view window has focus"""
mw = FreeCADGui.getMainWindow()
mdi = mw.findChild(QtGui.QMdiArea)
# We cannot trust the current subwindow to be a script window, it may be the associated 3D view
mdiWin = mdi.currentSubWindow()
# We have a 3D view selected so we need to find the corresponding script window
if mdiWin == 0 or ".py" not in mdiWin.windowTitle():
subList = mdi.subWindowList()
for sub in subList:
if sub.windowTitle() == mdiWin.windowTitle() + ".py":
mdiWin = sub
return mdiWin
def setActiveWindowTitle(title):
"""Sets the title of the currently active MDI window, as long as it is a scripting window"""
mw = FreeCADGui.getMainWindow()
mdi = mw.findChild(QtGui.QMdiArea)
# We cannot trust the current subwindow to be a script window, it may be the associated 3D view
mdiWin = mdi.currentSubWindow()
if mdiWin == 0 or ".py" not in mdiWin.windowTitle():
subList = mdi.subWindowList()
for sub in subList:
if sub.windowTitle() == mdiWin.windowTitle() + ".py":
mdiWin = sub
# Change the window title if there is something there to change
if (mdiWin != 0):
mdiWin.setWindowTitle(title)
cqCodePane = mdiWin.findChild(QtGui.QPlainTextEdit)
cqCodePane.setObjectName("cqCodePane_" + title.split('.')[0])