Find the last window created in Maya?
<p>I was wondering if there is any way to find the name of the last window created in Maya, knowing that I can't add any information to the window itself before that... I checked in both the <code>cmds</code> and API but couldn't find anything. Maybe in PyQt but I don't know much about it.</p>

<p>I'm looking for any solution. Thanks</p>

<p>you can work with something like a close callback, save the needed information and restore it again </p>

<pre><code>def restoreLayout(self):
    """
    Restore the layout of each widget
    """
    settings=self.settings
    try:
        self.restoreGeometry(settings.value("geometry").toByteArray())
        self.restoreState(settings.value("windowState").toByteArray())
        size=settings.value('fontSize').toFloat()[0]
        self.setFontSize(size)
    except:
        pass

def saveLayout(self):
    """
    Save the layout of each widget
    Save the main window id to your data base
    """
    settings=self.settings
    settings.setValue("geometry", self.saveGeometry())
    settings.setValue("windowState", self.saveState())
    settings.setValue("fontSize", app.font().pointSize())

def closeEvent(self, event):
    QtGui.QMainWindow.closeEvent(self, event)
    self.saveLayout()
</code></pre>

<p>a simple case/idea to save tha main win_id and a child button_id:</p>

<pre><code>from functools import partial
import json
def close_ui(*args):
    win_id = args[0]
    if cmds.window(win_id, exists=True):
       cmds.deleteUI(win_id, window=True)
       with open('dataBase/ui/uidata.json', 'w') as outfile:
            json.dump(args, outfile)
win = {}
win["main_win"] = cmds.window()
cmds.columnLayout()
cmds.text( label='closing it' )
win["btn"] = cmds.button( label='Close')
cmds.button(win["btn"],e=True, command=partial(close_ui, win["main_win"], win["btn"]))
cmds.showWindow(win["main_win"])
</code></pre>

python maya