首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PyMEL嵌入布局

PyMEL嵌入布局
EN

Stack Overflow用户
提问于 2021-04-27 04:02:49
回答 1查看 110关注 0票数 0

在一个表单中嵌入多个PyMEL布局的最佳方法是什么?

例如,对于表单的每一行,我希望指定:

  • row为label+textField对
  • 第二行使用2列布局,第二行对具有自己的注释标签
  • 第三行的菜单项使用1列布局,如果用户

调整窗口的大小,则第三行为1列布局

  • 添加一个全宽度执行按钮。

蒂娅!

代码语言:javascript
复制
import pymel.core as pm

def test(*args):
    print('model name: {}'.format(modelTField.getText()))
    print('model geom: {}'.format(modelMenu.getValue())) 

if pm.window("testUI", ex=1): pm.deleteUI("testUI")
window = pm.window("testUI", t="Test v0.1", w=500, h=200)
mainLayout = pm.verticalLayout() 

# two column layout
col2Layout = pm.horizontalLayout(ratios=[1, 2], spacing=10)
pm.text(label='Model name')

global modelTField
modelTField = pm.textField()

col2Layout.redistribute()

# single column layout
col1Layout = pm.horizontalLayout()

global modelMenu
modelMenuName = "modelMenu"
modelMenuLabel = "Model mesh"
modelMenuAnnotation = "Select which geo corresponds to the model shape"
modelMenu = pm.optionMenu(modelMenuName, l=modelMenuLabel, h=20, ann=modelMenuAnnotation)
pm.menuItem(l="FooShape")
pm.menuItem(l="BarShape") 

# execute
buttonLabel = "[DOIT]"
button = pm.button(l=buttonLabel, c=test)

col2Layout.redistribute()

# display window
pm.showWindow(window)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-29 09:00:11

由于pm.horizontalLayout()pm.verticalLayout自动地重新分发内容,所以不需要自己调用重分发。但是,要使这些函数正常工作,您需要一个类似于这样的with语句:

代码语言:javascript
复制
import pymel.core as pm

def test(*args):
    print('model name: {}'.format(modelTField.getText()))
    print('model geom: {}'.format(modelMenu.getValue())) 

if pm.window("testUI", ex=1): pm.deleteUI("testUI")
window = pm.window("testUI", t="Test v0.1", w=500, h=200)

with pm.verticalLayout() as mainLayout:
    with pm.horizontalLayout(ratios=[1, 2], spacing=10) as col2Layout:
        pm.text(label='Model name'
        global modelTField
        modelTField = pm.textField()

    with pm.horizontalLayout() as col1Layout:        
        global modelMenu
        modelMenuName = "modelMenu"
        modelMenuLabel = "Model mesh"
        modelMenuAnnotation = "Select which geo corresponds to the model shape"
        modelMenu = pm.optionMenu(modelMenuName, l=modelMenuLabel, h=20, ann=modelMenuAnnotation)
        pm.menuItem(l="FooShape")
        pm.menuItem(l="BarShape") 
    
        # execute
        buttonLabel = "[DOIT]"
        button = pm.button(l=buttonLabel, c=test)

# display window
pm.showWindow(window)

要使用python创建UI,如果将所有内容都包含在类中,特别是如果使用PyMel,则会有很大帮助。这样你就能做到:

代码语言:javascript
复制
class MyWindow(pm.ui.Window):
    def __init(self):
        self.title = "TestUI"
    def buttonCallback(self, *args):
        do something....

如果您有回调,这是非常有用的,因为您需要的所有东西都可以从类中访问,而且您根本不需要全局变量。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67276831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档