Show a list of string in a python reader

I have a python reader reading an HDF5 and I have added a property to allow to select which group of the HDF5 the user wants to read. However, since it may be complicated to know the correct path of the group, I have added a view which shows all the possible groups

I would like to know if there is a way to disable the checkboxes on the list. And even better, when selecting an element of the list, copying directly that string to the RootPath string.

Relevant code is here

    @smproperty.dataarrayselection(name="Groups")
    def GetGroupNames(self):
        from vtkmodules.vtkCommonCore import vtkDataArraySelection
        arrayselection = vtkDataArraySelection()
        for name in self.group_names:
            arrayselection.AddArray(name)
        return arrayselection

You probably want to use an array list domain or a string list for your root path property

Can you explain how? I am totally new to this

You can find an example here:

https://gitlab.kitware.com/paraview/paraview/blob/master/Examples/Plugins/PythonAlgorithm/PythonAlgorithmExamples.py

    # "StringInfo" and "String" demonstrate how one can add a selection widget
    # that lets user choose a string from the list of strings.
    @smproperty.stringvector(name="StringInfo", information_only="1")
    def GetStrings(self):
        return ["one", "two", "three"]

    @smproperty.stringvector(name="String", number_of_elements="1")
    @smdomain.xml(\
        """<StringListDomain name="list">
                <RequiredProperties>
                    <Property name="StringInfo" function="StringInfo"/>
                </RequiredProperties>
            </StringListDomain>
        """)
    def SetString(self, value):
        print("Setting ", value)

So if I understand correctly, the property String uses the property StringInfo, which calls the function StringInfo, to get the strings that are shown in the list?

How are the different names related?
There are at least 5:
first stringvector property name (StringInfo)
GetStrings function. Does the name of this function have any constraints?

second stringvector property name (String)
name and function in the required properties in the StringListDomain
SetString function

I guess the python function can be called as we wish, and the decorators are the ones that must match, right?

I have just tried the snippet you provided, as it is, and paraview is crashing.

/usr/include/c++/12.2.1/bits/stl_vector.h:1123: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.

Yes.

I guess the python function can be called as we wish, and the decorators are the ones that must match, right?

Yes

I have just tried the snippet you provided, as it is, and paraview is crashing.

The example itself is working.

Fails even to load in my paraview application

Failed to call `paraview.detail.pythonalgorithm.load_plugin`.
Traceback (most recent call last):
  File "/opt/paraview/lib/python3.10/site-packages/paraview/detail/pythonalgorithm.py", line 509, in load_plugin
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/jjcasmar/Downloads/PythonAlgorithmExamples.py", line 16, in <module>
    class PythonSuperquadricSource(VTKPythonAlgorithmBase):
  File "/home/jjcasmar/Downloads/PythonAlgorithmExamples.py", line 57, in PythonSuperquadricSource
    def SetThetaResolution(self, x):
  File "/opt/paraview/lib/python3.10/site-packages/paraview/detail/pythonalgorithm.py", line 76, in decorator
    updated_attrs = update_func(original_func, attrs)
  File "/opt/paraview/lib/python3.10/site-packages/paraview/detail/pythonalgorithm.py", line 144, in _update_vectorproperty_defaults
    assert attrs["number_of_elements"] == _count(attrs["default_values"])
AssertionError
(   9.646s) [paraview        ]  vtkPVPluginLoader.cxx:532    ERR| vtkPVPluginLoader (0x56122d209ba0): /home/jjcasmar/Downloads/PythonAlgorithmExamples.py: /home/jjcasmar/Downloads/PythonAlgorithmExamples.py: invalid ELF header

Are there any version requirements?

How do you install ParaView ? Which version are you using ?

I was testing in Paraview 5.10, which comes from Archlinux repos, but I have also tested in 5.11, directly downloaded from the web, and the example you linked to gitlab fails to load also there. I have had to remove everything in the Source algorithm but the String and StringInfo stuff we are talking about to make it work.

Indeed, it seems broken. That is unexpected, could you open an issue ? https://gitlab.kitware.com/paraview/paraview/-/issues