shimming-toolbox / fsleyes-plugin-shimming-toolbox

Fsleyes plugin for Shimming-Toolbox
GNU General Public License v3.0
0 stars 1 forks source link

Loading ST plugin causes `TypeError: list indices must be integers or slices, not NoneType` #23

Open joshuacwnewton opened 2 years ago

joshuacwnewton commented 2 years ago

While trying to debug #21, I followed the installation instructions here, then followed the "Running" instructions here. All I did was run shimming-toolbox then Settings -> Ortho View (1) -> Shimming Toolbox.

Nothing happens in the GUI, and in the terminal I see:

File "/home/joshua/shimming-toolbox/python/envs/pst_venv/lib/python3.7/site-packages/fsleyes/frame.py", line 787, in wrapper
    self.__onViewPanelMenuItem(vp, aname, sc, **kwargs)
  File "/home/joshua/shimming-toolbox/python/envs/pst_venv/lib/python3.7/site-packages/fsleyes/frame.py", line 937, in __onViewPanelMenuItem
    func()
  File "/home/joshua/shimming-toolbox/python/envs/pst_venv/lib/python3.7/site-packages/fsleyes/actions/base.py", line 347, in __call__
    result  = Action.__call__(self, *args, **kwargs)
  File "/home/joshua/shimming-toolbox/python/envs/pst_venv/lib/python3.7/site-packages/fsleyes/actions/base.py", line 200, in __call__
    return self.__func(*args, **kwargs)
  File "/home/joshua/shimming-toolbox/python/envs/pst_venv/lib/python3.7/site-packages/fsleyes/actions/togglecontrolpanel.py", line 84, in __togglePanel
    **self.__kwargs)
  File "/home/joshua/shimming-toolbox/python/envs/pst_venv/lib/python3.7/site-packages/fsleyes/views/viewpanel.py", line 521, in togglePanel
    **kwargs)
  File "/home/joshua/shimming-toolbox/python/envs/pst_venv/lib/python3.7/site-packages/fsleyes_plugin_shimming_toolbox/st_plugin.py", line 60, in __init__
    my_panel = TabPanel(self)
  File "/home/joshua/shimming-toolbox/python/envs/pst_venv/lib/python3.7/site-packages/fsleyes_plugin_shimming_toolbox/st_plugin.py", line 154, in __init__
    tab2 = FieldMapTab(nb)
  File "/home/joshua/shimming-toolbox/python/envs/pst_venv/lib/python3.7/site-packages/fsleyes_plugin_shimming_toolbox/st_plugin.py", line 1092, in __init__
    info_text="Algorithm for unwrapping"
  File "/home/joshua/shimming-toolbox/python/envs/pst_venv/lib/python3.7/site-packages/fsleyes_plugin_shimming_toolbox/st_plugin.py", line 362, in __init__
    self.on_choice(None)
  File "/home/joshua/shimming-toolbox/python/envs/pst_venv/lib/python3.7/site-packages/fsleyes_plugin_shimming_toolbox/st_plugin.py", line 400, in on_choice
    self.input_text_boxes = self.list_components[index].input_text_boxes
TypeError: list indices must be integers or slices, not NoneType

So, for some reason, index is None.

I did some print-statement debugging, and found that selection is returned as an empty string "".

https://github.com/shimming-toolbox/fsleyes-plugin-shimming-toolbox/blob/eadde8445cf4d61e14f9c5648b42b268585c0d01/fsleyes_plugin_shimming_toolbox/st_plugin.py#L389

So, self.find_index() fails to find anything, hence the crash:

https://github.com/shimming-toolbox/fsleyes-plugin-shimming-toolbox/blob/eadde8445cf4d61e14f9c5648b42b268585c0d01/fsleyes_plugin_shimming_toolbox/st_plugin.py#L399

I'm still not sure why selection is an empty string in the first place. I thought I would stop here and report to get insight from folks who have worked on st_plugin.py for longer.

joshuacwnewton commented 2 years ago

(Anyways, to continue debugging #21, I just quickly modified self.find_index to return 0 if the label can't be found. Once I did that, then the plugin loaded fine. But obviously I don't recommend that as a fix -- I just did that to demonstrate that this is the only issue I ran into.)

gaspardcereza commented 2 years ago

Hi @joshuacwnewton. I just encountered the same problem when trying to open the GUI in WSL2. I don't really understand what happens here especially since it works just fine on macOS... What OS are you using ?

gaspardcereza commented 2 years ago

It seems to me that this happens because the dropdown box is empty when we initialize the GUI so we get selection = "". and nothing is displayed. However, I don't get why it does not occur on macOS...

image
joshuacwnewton commented 2 years ago

What OS are you using ?

I encountered the issue on Ubuntu 20.04, so that would align with you encountering it in WSL2 (I presume with Ubuntu?)

gaspardcereza commented 2 years ago

Indeed I use a Ubuntu 20.04 distribution inside WSL2. Have you ever experienced something similar in the past (something that works on macOS but not on Ubuntu) ?