I would like to develop a small builder component. However, I do not want to alter the psychopy installation itself (e.g. adding stuff to /experiment/component/…), but would like to use the plugin system.
How do I register a component via the plugin system?
And a second question: Once a component is loaded, is it possible to alter the GUI elements in the builder? E.g component is added and its
component.__init__ is executed that determines the GUI parameters. Is there a way to update those?
Hi, perhaps this guide Creating Plugins for PsychoPy® — PsychoPy v2023.2.0 can help with some of your questions.
I di already read that page, but it does not explain how to create a component. I simply don’t know where to mark the entry point for a component, as they are discovered and registered at runtime based on file location.
Components exist in psychopy/experiment/components, each in their own folder. They’re all subclasses of
BaseComponent, so you could also find them that way.
The GUI elements in Builder are constructed from the Param objects defined in the Component’s init function, have a look at the existing components to see how this lines up.
That documentation needs updating, to be fair. It tells you how to use a
setup.py file whereas the modern python way is to use a
pyproject.toml file to determine the settings of a project, including its entrypoints.
Take a look at an existing plugin, like the Emotiv one. There are 3 things to note about how this is set up:
- your project may have classes that are needed at run-time, like stimulus/hardware classes. In the Emotiv plugin these classes are in psychopy_emotiv/emotiv.py but they are also imported in the init file so you can do things like
from psychopy_emotiv import cortex in a script
- the Emotiv plugin also contains components, like EmotiveRecord: https://github.com/psychopy/psychopy-emotiv/tree/main/psychopy_emotiv/emotiv_record and those are created in a folder with icon/theme subfolders and usually just an init file that contains the actual Component
- for the Component to be found by the application you need to specify its entrypoint. As above that can be done in a setup.py but we now usually do it in pyproject.toml. See the bottom 3 lines of https://github.com/psychopy/psychopy-emotiv/blob/main/pyproject.toml where a pair of components are set up that will appear in psychop.experiment.components as needed by the app