PythonMaya-GUI-Windows(窗口)

colorEditor 颜色编辑器窗口

#    Example 1.
#
cmds.colorEditor()
if cmds.colorEditor(query=True, result=True):
    values = cmds.colorEditor(query=True, rgb=True)
    print 'RGB = ' + str(values)
    values = cmds.colorEditor(query=True, hsv=True)
    print 'HSV = ' + str(values)
    alpha = cmds.colorEditor(query=True, alpha=True)
    print 'Alpha = ' + str(alpha)
else:
    print 'Editor was dismissed'

#    Example 2.
#
result = cmds.colorEditor()
buffer = result.split()
if '1' == buffer[3]:
    values = cmds.colorEditor(query=True, rgb=True)
    print 'RGB = ' + str(values)
    alpha = cmds.colorEditor(query=True, alpha=True)
    print 'Alpha = ' + str(alpha)
else:
    print 'Editor was dismissed'
image.png

image.png

confirmDialog 确认对话框

# 创建一个空单按钮对话框。
#
cmds.confirmDialog()

# 创建一个基本的“是”/“否”对话框。
#
cmds.confirmDialog(
    title='Confirm',
    message='Are you sure?',
    button=['Yes','No'],
    defaultButton='Yes', cancelButton='No', dismissString='No'
)
image.png

image.png

defaultNavigation 默认导航

# Create a poly plane
cmds.polyPlane(w=10, h=10, sx=10, sy=10, n='pPlane1')

# 这将打开Create Render Node窗口,您可以从中选择要连接到现有lambert1.color属性的节点
cmds.defaultNavigation(createNew=True, destination='lambert1.color')

# 选择Checker节点,您会发现“checker1.outColor”连接到“lambert1.color”。

# 打破你刚刚建立的“checker1.outColor”和“lambert1.color”之间的联系
cmds.disconnectAttr('checker1.outColor', 'lambert1.color')

# 将“checker1”连接到“lambert1”.此处仅指定节点,但该命令将进行最佳猜测。
# 所以“checker1.outColor”和“lambert1.color”是相连的
cmds.defaultNavigation(connectToExisting=True, source='checker1', destination='lambert1')

minimizeApp 最小化程序

cmds.minimizeApp()

progressWindow 进度条

# 在脚本对话框中使用进度条,而不是直接在脚本编辑器中。

amount = 0

cmds.progressWindow(    title='Doing Nothing',
                    progress=amount,
                    status='Sleeping: 0%',
                    isInterruptable=True )
while True :
    # 检查对话框是否已取消
    if cmds.progressWindow( query=True, isCancelled=True ) :
        break

    # 检查是否已达到最终条件
    if cmds.progressWindow( query=True, progress=True ) >= 100 :
        break

    amount += 5

    cmds.progressWindow( edit=True, progress=amount, status=('Sleeping: ' + `amount` + '%' ) )

    cmds.pause( seconds=1 )

cmds.progressWindow(endProgress=1)
image.png

promptDialog

result = cmds.promptDialog(
        title='Rename Object',
        message='Enter Name:',
        button=['OK', 'Cancel'],
        defaultButton='OK',
        cancelButton='Cancel',
        dismissString='Cancel')

if result == 'OK':
    text = cmds.promptDialog(query=True, text=True)
image.png

scriptEditorInfo

直接操作和查询“命令窗口”窗口的内容。

showSelectionInTitle

此命令使指定为参数的窗口的标题链接到当前文件和选择。
当选择更改时,窗口标题将更改为显示当前文件名和最后选定对象的名称。

window = cmds.window(widthHeight=(400, 100))
cmds.paneLayout()
cmds.scrollField(wordWrap=True, text='The title of this window will reflect the current object selection.')
cmds.showWindow(window)

cmds.showSelectionInTitle(window)
cmds.sphere()

toggleWindowVisibility 切换窗口的可见性

切换窗口的可见性。如果未指定窗口,则使用当前窗口(最近创建的)。另请参见window命令的vis / visible标志。

window1 = cmds.window( retain=True )
cmds.columnLayout()
cmds.checkBox()
cmds.checkBox()
cmds.checkBox()
cmds.button( label='Close', command='cmds.window( window1, edit=True, visible=False )' )

#    Create another window with a button that will toggle the visibility
#    of the first window.
#
window2 = cmds.window()
cmds.columnLayout()
cmds.button( label='Toggle Window Visibility', command=('cmds.toggleWindowVisibility(\"' + window1 +'\")' ) )

cmds.showWindow( window1 )
cmds.showWindow( window2 )
image.png

window

# 开个新窗口
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 )

# 调整主窗口的大小
gMainWindow = maya.mel.eval('$tmpVar=$gMainWindow') # 这是在Python中获取MEL全局变量值的变通方法
cmds.window( gMainWindow, edit=True, widthHeight=(900, 777) )

# 添加主窗口菜单栏右侧的菜单
cmds.setParent ( "" )
menuName = "menuTest"
cmds.optionMenu( menuName, label='test menu')
cmds.menuItem( label='item 1', parent = menuName )
cmds.menuItem( label='item 2', parent = menuName )
cmds.menuItem( label='item 3', parent = menuName )

cmds.window ("MayaWindow", edit=True, menuBarCornerWidget = (menuName, "topRight") )

你可能感兴趣的:(PythonMaya-GUI-Windows(窗口))