Here's a simple example of the strategy you'd want to use. This uses buttons, not icontextbuttons, but the idea is the same. The structure is the part you'd want to copy; the whole thing is wrapped in a columnLayout for expandability, the filter is a RowLayout with a text field and a button, then all of the buttons are in a second columnLayout that can expand and contract as you show-hide the buttons.
import maya.cmds as cmds
# some dummy commands. Not the use of "_", which is
# a lazy way to ignore the argument which Maya will
# add to all callback functions
def apple_command(_):
cmds.polyCube()
def orange_command(_):
cmds.polySphere()
def banana_command(_):
cmds.polyPlane()
window = cmds.window(title = "filter")
root = cmds.columnLayout()
# filter button and text field
header = cmds.rowLayout(nc=2)
filter_field = cmds.textField()
filter_button = cmds.button(label = 'filter')
cmds.setParent("..")
# hideable butttons
button_list = cmds.columnLayout()
# create a bunch of buttons, storing the name in a dictionary for easier filtering
# this is a dictionary with the label of the button and the commands you want to
# attach to the buttons
button_names = {
'apples': apple_command,
'oranges': orange_command,
'bananas': banana_comand,
'mangoes': apple_command,
'coconuts': orange_command,
'durians': banana_command
}
button_widgets = {}
for button_name, button_command in button_names.items():
button_widgets[button_name] = cmds.button(label = button_name, width = 160, c= button_command)
# in a real application you'd also make the buttons do something....
# this makes the filter button apply the filter
# defining it down here lets it 'remember' the name of the filter
# field and the contents of the button dictionary
def apply_filter(*_):
# get the current text in the filter field
filter_text = cmds.textField(filter_field, q=True, text=True)
# loop over the dictionary, setting the visiblity of the button
# based on the key and the filter
for key, value in button_widgets.items():
viz = True
if len(filter_text):
viz = filter_text.lower() in key.lower()
cmds.button(value, edit=True, visible = viz)
# now hook it too the button
cmds.button(filter_button, e=True, c= apply_filter)
cmds.showWindow(window)
Basically what you do is to collect the filter-able names while you're creating buttons into a dictionary that maps them to the actual GUI widgets. Then you can loop over the whole thing, setting the visibility according to the filter. In a columnLayout
they will automatically close up the gaps when you change their visibility.
You could use this trick on sets of controls by creating layouts and show/hiding them the same way instead of managing individual controls.