简体   繁体   中英

Position a layout to the bottom of main layout python Autodesk Maya

I'am creating a user interface that allows the user each time he clicks on '+' button it adds a new layout with text fields in it, knowing that I have to put that apply button at the bottom of my main layout, but the problem that I have is that the added layout hide my apply button

this is my code:

import maya.cmds as cmds
from functools import partial
import pymel.core as pm

selectedEmotion = ""
def createUI(*args):
    windowID = 'myWindowID'
    if cmds.window(windowID, exists=True):
        cmds.deleteUI(windowID)
    cmds.window(windowID, title="User Interface", sizeable=True)
    cmds.scrollLayout(horizontalScrollBarThickness=10,verticalScrollBarThickness=10, parent=windowID)
    myLayout=cmds.rowColumnLayout(width=600, nr=3)
    layout1=cmds.rowColumnLayout(width=600, height=40, cs=[(1,5),(2,5),(3,5)],
    rowSpacing=[(1,30), (2,30), (3,30)], nc=3, cal=[(1, "center"),(2, "center"), (3,"center")], cw=[(1,60),(2,280),(3,50)], parent=myLayout)
    cmds.text(label="Browse: ", p=layout1)
    filenameField=cmds.textField(p=layout1, width=200)
    cmds.iconTextButton(style='iconOnly',align='center',command=partial(browseFile, filenameField), image1='fileOpen.xpm', height=30)
    layout2=cmds.rowColumnLayout(width=600, nc=2, cw=[(1,100),(2,100)], height=40, cs=[(1,40),(2,60)], parent=myLayout)
    layoutF=cmds.rowColumnLayout(width=600, nc=1, parent=myLayout)
    cmds.button(label="+", width=100, parent=layout2, command=partial(addRow,layoutF))
    cmds.button(label="-", width=100, parent=layout2, command=partial(addRow,layoutF))
    layout3=cmds.rowLayout(width=400,height=30, parent=myLayout)
    global globalFile
    cmds.button(label="Apply", width=130, parent=layout3, align='right')
    cmds.setParent('..')
    cmds.showWindow()
def addRow(pLayout, *args):
    layout2=cmds.rowLayout(parent=pLayout, width=390, nc=9, 
        cal=[(1, "center"),(2, "center"), (3,"center"), (4, "center"), (5,"center"),(6, "center"), (7,"center"), (8, "center")], 
        cw=[(1,25),(2,50),(3,25), (4,50), (5,50),(6,70),(7,50),(8,50)])
    cmds.text(label="From : ", p=layout2)
    fromField = cmds.textField(width=50)
    cmds.textField(fromField, edit=True, parent=layout2)
    cmds.text(label="To : ", p=layout2)
    toField = cmds.textField(width=50)
    cmds.textField(toField, edit=True, parent=layout2)
    cmds.text(label="Emotion : ", p=layout2)
    emotionList = cmds.optionMenu("objects", parent=layout2 )
    cmds.menuItem( label='Neutre', parent = "objects" )
    cmds.menuItem( label='Happy', parent = "objects" )
    cmds.menuItem( label='Sad', parent = "objects" )
    cmds.text(label="Position : ", p=layout2)
    positionField = cmds.textField(width=50)

createUI()  

在此输入图像描述

I figure it out.

This is my code for anyone who need help:

import maya.cmds as cmds
from functools import partial
import pymel.core as pm

selectedEmotion = ""
def createUI(*args):
    windowID = 'myWindowID'
    if cmds.window(windowID, exists=True):
        cmds.deleteUI(windowID)
    cmds.window(windowID, title="User Interface", sizeable=True)
    cmds.scrollLayout(horizontalScrollBarThickness=10,verticalScrollBarThickness=10, parent=windowID)
    myLayout=cmds.rowColumnLayout(width=600,ral=(4,"right"),columnAttach=(1,"both",0), nr=4,adj=True, rowAttach=(4, "bottom", 0))
    layout1=cmds.rowColumnLayout(width=600, height=40, cs=[(1,5),(2,5),(3,5)],
    rowSpacing=[(1,30), (2,30), (3,30)], nc=3, cal=[(1, "center"),(2, "center"), (3,"center")], cw=[(1,60),(2,280),(3,50)], parent=myLayout)
    cmds.text(label="Browse : ", p=layout1)
    filenameField=cmds.textField(p=layout1, width=200)
    cmds.iconTextButton(style='iconOnly',align='center',command=partial(browseFile, filenameField), image1='fileOpen.xpm', height=30)
    layout2=cmds.rowColumnLayout(width=600, nc=2, cw=[(1,100),(2,100)], height=40, cs=[(1,40),(2,60)], parent=myLayout)
    layoutF=cmds.rowColumnLayout(width=600, nc=1, parent=myLayout)
    global countClick
    countClick =0
    cmds.button(label="+", width=100, parent=layout2, command=partial(addRow,layoutF))
    cmds.button(label="-", width=100, parent=layout2, command=printCount)
    layout3=cmds.rowLayout(width=400,height=30, rowAttach=(1, "bottom", 0), parent=myLayout)
    cmds.button(label="Apply", width=130, parent=layout3, align='right')
    cmds.setParent('..')
    cmds.showWindow()
def addRow(pLayout, *args):
    global countClick
    countClick=countClick+1
    layout2=cmds.rowLayout(parent=pLayout, width=390, nc=9, 
        cal=[(1, "center"),(2, "center"), (3,"center"), (4, "center"), (5,"center"),(6, "center"), (7,"center"), (8, "center")], 
        cw=[(1,25),(2,50),(3,25), (4,50), (5,50),(6,70),(7,50),(8,50)])
    cmds.text(label="From : ", p=layout2)
    fromField = cmds.textField(width=50)
    cmds.textField(fromField, edit=True, parent=layout2)
    cmds.text(label="To : ", p=layout2)
    toField = cmds.textField(width=50)
    cmds.textField(toField, edit=True, parent=layout2)
    cmds.text(label="Emotion : ", p=layout2)
    emotionList = cmds.optionMenu("objects", parent=layout2 )
    cmds.menuItem( label='Neutre', parent = "objects" )
    cmds.menuItem( label='Happy', parent = "objects" )
    cmds.menuItem( label='Sad', parent = "objects" )
    cmds.text(label="Position : ", p=layout2)
    positionField = cmds.textField(width=50)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM