Maya PySide Window - Remember position and size
<p>I am working in Pyside.  Every time I re-open the window it pops back to the middle of the screen.  How can I get either Maya or Windows to remember the position and size?</p>

<p>Here is some basic code I am working with:</p>

<pre><code>import traceback
from PySide import QtCore
from PySide import QtGui
from shiboken import wrapInstance
import maya.cmds as cmds
import maya.OpenMayaUI as omui
import pymel.core as pm
import maya.cmds as cmds

def maya_main_window():
     '''
     Return the Maya main window widget as a Python object
     '''
     main_window_ptr = omui.MQtUtil.mainWindow()
     return wrapInstance(long(main_window_ptr), QtGui.QWidget)

class TestTool(QtGui.QDialog):


 def __init__(self, parent=maya_main_window()):
      super(TestTool, self).__init__(parent)
      self.qtSignal = QtCore.Signal()
      #################################################################
 def create(self):
     '''
      Set up the UI prior to display
      '''
      self.setWindowTitle("Test")
      self.setWindowFlags(QtCore.Qt.Tool)
      #self.resize(400, 250) # re-size the window
     self.setGeometry(650, 200, 600, 300)
      self.setFixedHeight(580)
      self.setFixedWidth(300)

      QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))




if __name__ == "__main__":
     try:
          ui.deleteLater()
     except:
          pass
     ui = TestTool()
     try:
          ui.create()
          ui.show()
     except:
          ui.deleteLater()
          traceback.print_exc()
</code></pre>

<p>One option you can use is <code>QWidget.saveGeometry()</code> and <code>QWidget.restoreGeometry()</code>. With this you can save your window's position and size when your tool closes, then restore it back when it initializes. </p>

<p>Normally for stuff like this where it's saving a state of the tool, I'll store the data to an ini file somewhere with <code>QtCore.QSettings</code>. This way it will restore to the last state even if you close Maya, or have multiple sessions running.</p>

<p>Here's an example:</p>

<pre><code>import traceback
from PySide import QtCore
from PySide import QtGui
from shiboken import wrapInstance
import maya.cmds as cmds
import maya.OpenMayaUI as omui
import pymel.core as pm
import maya.cmds as cmds
import os

def maya_main_window():
    '''
    Return the Maya main window widget as a Python object
    '''
    main_window_ptr = omui.MQtUtil.mainWindow()
    return wrapInstance(long(main_window_ptr), QtGui.QWidget)

class TestTool(QtGui.QDialog):

    def __init__(self, parent=maya_main_window()):
        super(TestTool, self).__init__(parent)
        self.qtSignal = QtCore.Signal()

        # Using an env variable makes the path more generic, but use whatever you want
        self.settings_path = os.path.join(os.getenv('HOME'), "settingsFile.ini")

        #################################################################

    def create(self):
        '''
        Set up the UI prior to display
        '''
        self.setWindowTitle("Test")
        self.setWindowFlags(QtCore.Qt.Tool)
        self.resize(400, 250) # re-size the window
        self.setGeometry(650, 200, 600, 300)
        self.setFixedHeight(580)
        self.setFixedWidth(300)

        QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))

        # Restore window's previous geometry from file
        if os.path.exists(self.settings_path):
            settings_obj = QtCore.QSettings(self.settings_path, QtCore.QSettings.IniFormat)
            self.restoreGeometry(settings_obj.value("windowGeometry"))

    def closeEvent(self, event):
        # Save window's geometry
        settings_obj = QtCore.QSettings(self.settings_path, QtCore.QSettings.IniFormat)
        settings_obj.setValue("windowGeometry", self.saveGeometry())

if __name__ == "__main__":
    try:
        ui.deleteLater()
    except:
        pass

    ui = TestTool()

    try:
        ui.create()
        ui.show()
    except:
        ui.deleteLater()
        traceback.print_exc()
</code></pre>

<p>Since you're setting the size to be fixed, this will only effect position. Hope it helps!</p>

python window pyside maya