Search code examples
pythonuser-interfacewindowmaya

Maya Python windowPref command doesn't change window width, but says it does


I'm trying to set the width of a non-main Maya window (hypergraph, etc.).

But the command doesn't actually move it. It returns that it does...which is really weird. Anyone know what's up?

openWindows = cmds.lsUI(windows=True)

for i, window in enumerate(openWindows):
    if window != "MayaWindow":

        widthQueryPre = cmds.windowPref(window, q=True, w=True)

        cmds.windowPref(window, e=True, w=200) # Why doesn't this change the window's width?

        widthQueryPost = cmds.windowPref(window, q=True, w=True)

        print i, window, widthQueryPre, widthQueryPost

Solution

  • According to Maya 2014 documentation (the version I'm using):

    Create or modify preferred window attributes. The size and position of a window is retained during and between application sessions. A default window preference is created when a window is closed. Window preferences must be named and, consequently, only affect the window with a matching name.

    This means that the value you are changing using the windowPref command is not the actual size of the windows but it's default size. However this command is also called when you close a sub-window. And will override your previous calls to windowPref. You have to call windowPref once your sub-window is closed. Then next time you'll open the sub-window it will be 200px width.

    To sum up: This command does not resize your current sub-window but sets it's default size.

    If you want to resize a current window, use the window command.

    for win in cmds.lsUI(type="window"): #Lists all windows (including Pyside/PyQT ones)
        if win != "MayaWindow" and cmds.window(win, query=True, exists=True): #cmds.window(win, query=True, exists=True) checks if the windows really exists (do it, this can be useful)
            cmds.window( win, edit=True, widthHeight=(900, 777) ) #the actual command to resie the windows