I downloaded the latest build (4.13.0-2021-05-04) and now my .slicerrc.py is not working. This is because I’m trying to reach a button of SegmentEditorWidget:
So it looks like the class SegmentEditorWidget implemented in Python is no longer a QWidget, but instead contain qSlicerSegmentationsModuleWidget as a member editor. What’s behind this change? It is strange that getModuleWidget() is not returning a (Q)widget (but it did so before).
Is there an API documentation of the Python interface to Slicer? It is not easy to understand how the classes are intended to work.
BTW, do the Python-implemented classes dropping the prefixes vtk/mrml/q etc. as the C++ classes have?
The SegmentEditorWidget class has had the editor member since the first commit, so in that sense nothing changed. The reason for this difference is this commit in slicer.util, which for scripted module widgets returns the actual Python class instead of the C++ wrapper. The reason it worked for you is most probably that the Qt widgets in the editor module transitively had this C++ class as parent, however the Python widget class is not a QWidget.
I don’t think there is a complete Python API doc. You can use the C++ Doxygen in conjunction with the source code itself. And since Python works via interpreter, you can try everything first in Slicer’s Python interactor, and you can see what is available using the auto-complete function, and get documentation for the functions using help(className.functionName).
Thank you! I’ve been using the C++ API (and source code) alot while learning Python scripting. Luckily I have a lot of C++ knowledge (but no Python, so I have actually learnt Python through Slicer ).
It looks like the Python wrapping of C++ use the same naming and therefore prefixes vtk/mrml/q/etc). But are the Python-only classes like SegmentEditorWidget using no prefixes, so this is a way to differate between C++ and Python-only classes?
I would say yes. As far as I know all C++ classes start with vtk or q, while all of the Python classes start with capital letter and generally without such prefix.