我在python脚本中有一个简单的窗口,如:
if cmds.window('test', exists = True): cmds.deleteUI('test')
self.window = cmds.window('test')
而不是删除窗口和重置控件内部每次执行,我想最大化窗口到它的原点(如果最小化)或调整到某个位置,所以我可见,很容易被注意到,是否有有办法吗?我知道如果存在我可以通过/取消,但我只想调整窗口大小 感谢。
答案 0 :(得分:0)
我不认为maya cmds是可能的,但你可以在没有Qt的情况下做到这一点。 以下是混合解决方案的示例:
from PyQt4 import QtGui
from sip import wrapinstance
import maya.OpenMayaUI as omui
def mayaToQT( name ):
# Maya -> QWidget
ptr = omui.MQtUtil.findControl( name )
if ptr is None: ptr = omui.MQtUtil.findLayout( name )
if ptr is None: ptr = omui.MQtUtil.findMenuItem( name )
if ptr is not None: return wrapinstance( long( ptr ), QtGui.QWidget )
# create a basic window
def createWin():
window = cmds.window( title="Long Name", iconName='Short Name', widthHeight=(200, 55) )
cmds.columnLayout( adjustableColumn=True )
cmds.button( label='Do Nothing' )
cmds.button( label='Close', command=('cmds.deleteUI(\"' + window + '\", window=True)') )
cmds.setParent( '..' )
cmds.showWindow( window )
return window
# First creation
win = createWin()
qtWin = mayaToQT(win)
if cmds.window(win, exists = True):
geom = qtWin.geometry()
cmds.deleteUI(win)
# Second Creation and put the window back where it was
win = createWin()
qtWin = mayaToQT(win)
qtWin.setGeometry(geom)
设置几何体可以在屏幕上的任意位置或任何你想要的地方完成
答案 1 :(得分:0)
您手头有几个选项,具体取决于您希望它的外观......这些都是默认的python / maya函数,适用于以前的版本,返回到Autodesk Maya 2012。
您可以将窗口停靠在特定的一侧,这有助于您在Maya中管理场景。最简单的方法是:
# Import your maya command package
import maya.cmds as cmds
try:
# Try to delete your window then the dock
cmds.deleteUI("yourWnd")
cmds.deleteUI("yourDock")
except:
pass
# Parent your window to this dock and then show the dock instead of the window
cmds.window("yourWnd")
cmds.columnLayout("col")
cmds.button("button1")
cmds.setParent("col")
cmds.dockControl("yourDock",
allowedArea = ["left","right"],
area = "left",
content = "yourWnd",
floating = False)
这会将您的用户界面置于Maya窗口中易于访问的位置。
如果您决定创建一个窗口,可以轻松添加一个按钮或放入窗口调整窗口大小...
import maya.cmds as cmds
import ctypes
# having imported the ctypes package, you can get viable os system info
user32 = ctypes.windll.user32
# Getting the screen size of your main window
screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
cmds.window("yourWnd")
cmds.columnLayout("col")
# A button that allows you to imitate maximizing your window on your mainscreen
cmds.button("maxPlease",
label = "Maximize",
command = """cmds.window("yourWnd",
edit=True,
topLeftCorner = [0,0],
widthHeight = [screensize[0],
screensize[1]])
""")
cmds.setParent("col")
cmds.showWindow("yourWnd")
这些只是基础知识,您可以混合使用其中的两个来实现自己的解决方案。我强烈推荐使用ctypes,因为它最有助于你调整大小以最大化你的窗口。