Community
Does anyone know how to remove an entry from an FBList? Either by index or selection?
Here's how I did it:
from pyfbsdk import * from pyfbsdk_additions import * def PopulateListUI(): myList.Items.removeAll() # add items to the list for number in range(0, 5): name = ('name%s') % number myList.Items.append(name) def RemoveSelectedBtnEvent(control, event): if myList.Items.__len__() > 0: selectedItem = myList.Items[myList.ItemIndex] print ('Deleting %s') % selectedItem myList.Items.remove(selectedItem) # select the first item in the list myList.Selected(0, True) def OnToolDestroy(control,event): FBSystem().Scene.OnChange.Remove(SceneChanged) def PopulateLayoutUI(mainLayout): x = FBAddRegionParam(0,FBAttachType.kFBAttachLeft, "") y = FBAddRegionParam(0,FBAttachType.kFBAttachTop, "") w = FBAddRegionParam(0,FBAttachType.kFBAttachRight, "") h = FBAddRegionParam(25,FBAttachType.kFBAttachBottom, "") mainLayout.AddRegion("main", "main", x, y, w, h) vLayout = FBVBoxLayout() mainLayout.SetControl("main", vLayout) myLabel = FBLabel() myLabel.Caption = "My Label" vLayout.Add(myLabel, 10) global myList myList = FBList() vLayout.Add(myList, 20) PopulateListUI() removeSelectedIndexBtn = FBButton() removeSelectedIndexBtn.OnClick.Add(RemoveSelectedBtnEvent) removeSelectedIndexBtn.Caption = 'Remove Last Index' vLayout.Add(removeSelectedIndexBtn, 30) # register when this tool is destroyed tool.OnUnbind.Add(OnToolDestroy) def CreateTool(): global tool tool = FBCreateUniqueTool("List Removal") tool.StartSizeX = 275 tool.StartSizeY = 110 PopulateLayoutUI(tool) ShowTool(tool) CreateTool()
Ah, thanks Greg!
I ended up doing it round about:
The remove function is much faster! I couldn't get the syntax correct 😞
~Danilo
Hey, I noticed an error with the code I posted in regards to the SceneChanged part when I was posting it to my blog. Sorry about that.
Instead of reposting the big block of code again, those interested can go to my blog post here.
Can't find what you're looking for? Ask the community or share your knowledge.