I’m writing a Python Scripted Module and I want to create a custom data loading functionality.
What I want to achieve is to drag a folder into the scene and for Slicer to load the content automatically, according to some logic that I would specify. The folder has some predefined structure of subfolders and files, which is always the same.
I want to do this to save time, so I don’t have to select descriptions in the ‘Add data into scene’ dialog and then click load.
I tried to use a custom file reader and writer, as shown here, but this didn’t help me. As far as I understood, those two classes only allow you to write custom code to load/save a specific file type - but I want to automatically load files that are dropped into the scene, without opening the dialog.
The holding of ‘shift’ while selecting the description as described here, doesn’t help me as I have three file types to load - volumes, segmentations and displacement fields.
I am also very interested in a custom load function. I tried running your code by saving it as a .py file and creating a module from it so I could import it, but I didn’t succeed. How can I use your code?
@koeglfryderyk Adding a dropwidget is a neat idea if you want to directly load and select a file in a particular widget. I’m just wondering what was the issue with the Add Data dialog. Was the problem that you had to confirm loading in the add data window (single mouse click or hitting Enter key)? Or the problem was that you had to change what description was selected by default?
In recent Slicer versions, you can make sure that always the correct description is selected by adding a custom file reader that provides high confidence value.
I think it’s about hanging protocols and simplification of data organized in a standard way.
Btw I’ll need to override drag&drop very soon on the main window in one of the applications as well, in this particular case because the app loads a huge stack of TIFFs and the default loader does not support progress reporting, which is a must (may be 200+GB).