MotionBuilder Python Script19 - UI_List

We are

今天重新尝试构建了部分流程,看了一集海昏侯,挺好看

今天我们来看一下也是UI中非常常用的List

一、List

列表,以及下拉列表

我们来看一下UI效果

UI_效果

来直接看一下代码

# Copyright 2009 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Script description:
# Create a tool with 2 different kinds of list and shows how to register callbacks.
# 
# Topic: FBVBoxLayout, FBListStyle, FBList
#

from pyfbsdk import *
from pyfbsdk_additions import *

def ListCallback(control, event):
    print(control.Items[control.ItemIndex], "has been selected!")


def PopulateLayout(mainLyt):
    x = FBAddRegionParam(0,FBAttachType.kFBAttachLeft,"")
    y = FBAddRegionParam(0,FBAttachType.kFBAttachTop,"")
    w = FBAddRegionParam(200,FBAttachType.kFBAttachNone,"")
    h = FBAddRegionParam(0,FBAttachType.kFBAttachBottom,"")
    mainLyt.AddRegion("main","main", x,y,w,h)
    
    lyt = FBVBoxLayout()
    mainLyt.SetControl("main",lyt)
    
    
    # List creation
    global controls
    controls = [FBList(), FBList()]
    for l in controls:
        l.OnChange.Add(ListCallback)
        # fill the list with dummy data
        for i in range(10):
            name = "list element %d" % (i + 1)
            l.Items.append(name)
    
    
    #FBListStyle.kFBDropDownList
    #FBListStyle.kFBVerticalList
    controls[0].Style = FBListStyle.kFBDropDownList
    lyt.Add(controls[0], 25)
    controls[0].Selected(4, True)
    
    controls[1].Style = FBListStyle.kFBVerticalList
    lyt.Add(controls[1], 200)
    controls[1].Selected(7, True)
    controls[1].MultiSelect = True


def CreateTool():    
    # Tool creation will serve as the hub for all other controls
    t = FBCreateUniqueTool("List Example")    
    PopulateLayout(t)    
    ShowTool(t)


CreateTool()

大家仔细研究一下代码上方的几个函数,敲一敲,decomposition and refactor!

二、结语

有什么问题可以留言!

共勉!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 周末了,放个假休息休息,就再来更新一篇! 之前介绍的脚本以"脚本的感觉"来实现的,今天我们来介绍一下"系统级别"的...
    Houdinini阅读 4,247评论 0 0
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 11,723评论 0 17
  • “这个世界上每个人都爱着别人,爱自己的人怎就那么少。” 镜中的我 就那个模样 这么多年 我已习惯 偶尔听见 他人笑...
    吕三岁同学阅读 1,209评论 0 2
  • Linux学习初阶 使用ubuntu学习linux,安装方法与win安装的方法大同小异,看着图形化界面下一步就好了...
    宝塔山上的猫阅读 2,600评论 0 1
  • “生命就像写在水上的字,顺流而下,想回头寻找的时候总是失去了痕迹。”总是来不及跟过去挥手告别,郑重地说一声...
    独素离人怎挽阅读 2,985评论 0 0