Hey R.White.
Unfortunately I am not using Maya2018… But even so, I chanced upon some code that is able to detect maya gui closure and I incorporate it along with the code that Theodox has provided…
And while doing so, the inputs cannot be saved. Unsure of what went wrong (I have never used Maya api before…), could anyone kindly advise?
from maya import OpenMaya
from maya import OpenMayaUI
import maya.cmds as cmds
def makeTestWindow(win_closure=False):
default = cmds.optionVar(q='saved_value') or "default text"
w = cmds.window()
col = cmds.columnLayout()
textfld = cmds.textField(text = default)
def save_and_close(*_):
cmds.optionVar(sv = ('saved_value', cmds.textField(textfld, q=True, text=True)))
cmds.deleteUI(w)
if win_closure:
return save_and_close()
# The initial code has this button, but I commented it out as I do not want the button
# Having done that, it seems that it is unable to 'save' the inputs...
#btn = cmds.button('save and close', c= save_and_close)
cmds.showWindow(w)
def uiDeleteCallback( *args ):
"""
This is the function that will be called whenever the ui, passed to the MUiMessage.addUiDeletedCallback( window, uiDeleteCallback )
is deleted
"""
makeTestWindow(True)
cmds.confirmDialog(message = "The Window Was Closed!!!")
# make a test window
win = makeTestWindow(False)
# create the callback to run when the ui is deleted
uiCallBack = OpenMayaUI.MUiMessage.addUiDeletedCallback( win, uiDeleteCallback )