I'm trying to compile a UIlist, but I don't understand how to avoid inserting some sockets. In this example, to simplify things, I want that if a Socket is named "Empty" it doesn't get put in the UIlist, so what I get right now is that in the UIList, I get some "empty" item.
I would like to avoid these empty items in the list. How can I do?
class Node_UL_node_interface_sockets(bpy.types.UIList):
filter_string: StringProperty(name="filter_string",
default="",
description="Filter string for name")
def draw_item(self, context, layout, _data, item, icon, _active_data, _active_propname, _index):
socket = item
# if socket.name == "Empty":
# # I need not to display any "Empty" name lines
# return
color = socket.draw_color(context)
if self.layout_type in {'DEFAULT', 'COMPACT'}:
row = layout.row(align=True)
row.template_node_socket(color=color)
row.prop(socket, "name", text="", emboss=False, icon_value=icon)
elif self.layout_type == 'GRID':
layout.alignment = 'CENTER'
layout.template_node_socket(color=color)
def filter_items(self, context, data, propname):
# This function is really difficult for me to understand, it seems very confusing to me and I can't manage it
items = getattr(data, propname)
if not len(items):
return [], []
filtered = [self.bitflag_filter_item] * len(items)
for i, item in enumerate(items):
if not item.name == 'Empty':
if self.filter_string in item.name:
filtered[i] &= ~self.bitflag_filter_item
else:
filtered = [self.bitflag_filter_item] * len(items)
return filtered, []
def draw_filter(self, context, layout):
# In addition, I want to keep a search by name.
row = layout.row(align=True)
row.prop(self, "filter_string", text="Filter", icon="VIEWZOOM")
As in the example above, I tried to do this, but I really don't understand how to handle this filter_items() function
I would also like to keep a search by name, that's why I put the draw_filter function (self, context, layout), it seems to be very convenient, because it replaces the default one.
But the problem remains the understanding of the filter_items(), in addition I do not understand why if I return an empty list [], the UIList, will show all the items equally, Maybe because the list must be filled with what should not be shown, I suppose yes, but it's really frustrating, I have no idea how to continue this.
filter_itemsto filter on what you want to filter on. Decide whether you want to allow the filter to be editable and if you don't remove the editing operators and their panel entries. – Marty Fouts Jan 29 '22 at 20:20