Controlling the order that widgets appear in the GUI for a Python algorithm plugin

I have created a plugin using the Python algorithm. It has five different UI widgets created by using @smproperty and @smdomain decorators with three of the widgets set as boolean checkboxes, one widget set as a double vector slider and the last widget set as a string vector with a dropdown menu. I want to have my widgets ordered within the filter’s ParaView GUI so that one of my boolean checkbox widgets is above the string vector widget followed by the double vector widget. Unfortunately, I have not figured out how to order any of my widgets in the GUI and the string vector widget is always at the top and the double vector widget is placed between the boolean checkbox widgets. Is there a way to code the widgets that can control the order they appear in the GUI?

Hi @lpalmstrom. I know this question has been hanging out here for a while. That’s mainly because I didn’t know the answer and wanted to figure out why properties were ordered the way they are

Unfortunately, there isn’t a good way to specify an ordering on the properties. As it turns out, the properties are ordered alphabetically by the name of the command attribute, which is rather arbitrary. I’ve created an issue to add a smarter way to order properties in future versions of ParaView.

I’ve spoken too soon. There is a hack you can try now.

First, identify which of your properties shows up on the bottom of the UI. We’ll modify the definition of that property by manually specifying the XML that the Python algorithm magically generates behind the scenes for you. Let’s say that is one of the boolean checkbox widgets, which uses the @smproperty.intvector decorator. Let’s name it “MyCheckbox”. We’re going to turn

@smproperty.intvector(name="MyCheckbox")

into the equivalent XML for the property. Then we’re going to add XML to group your widgets in order.

Replace the above decorator with

    @smproperty.xml("""
    <IntVectorProperty name="MyCheckbox"
            number_of_elements="1"
            command="SetMyCheckbox">
        </IntVectorProperty>

        <PropertyGroup label="Ordered Widgets">
            <Property name="MyCheckbox" />
            <Property name="StringProp" />
            <Property name="DoubleProp" />
        </PropertyGroup>""")

The PropertyGroup lets you manually order the properties. I’ve made up two others here, StringProp and DoubleProp - use the names of your properties here instead.

Why do you have to do this for the property that shows up at the bottom you might ask? Well, PropertyGroups must appear in the generated XML after the properties they reference are defined in the XML, and we figure that out by looking for the bottom property in the UI which corresponds to the last property definition in the XML, then we declare our PropertyGroup after that. Phwew, told you it was a hack. But, it works for now.

Having a way to specify the order or just ordering by definition in the Python file would greatly simplify this.

1 Like