Maya Python windowPref 命令不会更改 window 宽度,但表示会更改

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

我正在尝试设置非主 Maya window(超图等)的宽度。

但命令实际上并没有移动它。它 returns 确实如此……这真的很奇怪。有人知道怎么回事吗?

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

根据Maya 2014 documentation(我使用的版本):

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.

这意味着您使用 windowPref 命令更改的值不是 windows 的实际大小,而是默认大小。但是,当您关闭子 window 时,也会调用此命令。并将覆盖您之前对 windowPref 的调用。 一旦您的 sub-window 关闭,您必须致电 windowPref。那么下次你打开 sub-window 时,它将是 200px 宽度。

总结:此命令不会调整当前子window的大小,但设置其默认大小

如果要调整当前 window 的大小,请使用 window 命令。

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