Reputation: 121
I have a simple window in python script like :
if cmds.window('test', exists = True): cmds.deleteUI('test')
self.window = cmds.window('test')
instead of delete window and reset controls inside for every time executed, I want to maximize window to it's origin (if minimized) or resize to some position so i'ts visible and easily noticed, is there any way to do it ? i know i can pass/ cancel if exist, but i just want to resize window
thanks.
Upvotes: 1
Views: 1424
Reputation: 2512
I don't think it is possible with maya cmds but you can do it without Qt. Here is an example do to an hybrid solution :
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)
Set Geometry can be done with an arbitrary position on the screen or anything you zqnt
Upvotes: 0
Reputation: 397
you have a few options at hand, depending on how you want it to look... These are all default python / maya functions, and works in previous versions, back to Autodesk Maya 2012.
You can dock your window to a particular side, which would help you manage your scene in Maya. The easiest way to do this is:
# 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)
This will put your UI in an easily accessible location in your Maya Window.
If you've decided to create a window, you could easily add a button or into your window that resizes your window...
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")
And these are just basics, you can mix and match the two of these to work your own solution. I highly recommend using ctypes, as it will most definitely help you with resizing to maximize your window.
Upvotes: 0