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!
二、结语
有什么问题可以留言!
共勉!