用Pymel里的with来写UI

第一次看到一个同事用with写UI的时候,感觉好神奇,原来with还可以这样用啊,顿感自己好无知,今天在看Pymel的文档时,才返现原来那么好的范例就放在那里,自己没有发现啊,今天狠狠地补了一下这方面的知识。同时,如果对UI里的某一类control想做某方面的统一样式,如宽度、高度、边框等等,就可以定义个template,以后所有UI里的control都会自动统一到template,不用每次自定义了,更快捷方便。最后pymel的horizontalLayout和他的redistribute()为pymel自定义的部件和方法,也很好h.redistribute(3, 3, 2)。

 

from pymel.core import *

template = uiTemplate('ExampleTemplate', force=True)
template.define(button, width=100, height=30, align='right')
template.define(frameLayout, borderVisible=True, labelVisible=False)

if window('firstWithWindow', exists = 1): deleteUI('firstWithWindow', window = True)
with window('firstWithWindow', menuBar=True,menuBarVisible=True, title = 'WithWindow') as win:
    # start the template block
    with template:
        with columnLayout( rowSpacing=5, adj = 1 ):
            with frameLayout():
                with columnLayout(adj = 1):
                    button(label='One')
                    button(label='Two')
                    button(label='Three')
                    
            with frameLayout():
                with horizontalLayout() as h5:
                    button(label = 'Push Me!')
                    button(label = 'Pull Him!')
                    h5.redistribute(30, 30)
            with frameLayout():
                with optionMenu():
                    menuItem(label='Red')
                    menuItem(label='Green')
                    menuItem(label='Blue')

    # add a menu to an existing window
with win:
    with menu(label = 'File'):
        menuItem(label='One')
        menuItem(label='Two')
        with subMenuItem(label='Sub'):
            menuItem(label='A')
            menuItem(label='B')
        menuItem(label='Three')

 

 

 

 

pymel在meya里使用起来真是快键方便,而且代码量少,还有些其他功能,自己正在看文档,后面继续更新。

 

 

 

最后上传一张图:


 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值