Browsing folders with magicgui

Hi,

I am new to both Napari and Imagesc, so I am not sure this is the right place to ask this. I am writing a plugin with magicgui, and I want to select a folder using a FileEdit widget. It works fine if I set up the code to open a file using the option {‘mode’: ‘r’}, but I get an error if use the option {‘mode’: ‘d’} to open a folder. More precisely, using this code:

import pathlib
from magicgui import magicgui


@magicgui(fn={'mode': 'd'}, call_button='Run')
def widget(fn =  pathlib.Path.home()):
    print(fn)


widget.show(run=True)

I get the following error:

Traceback (most recent call last):
File “/home/aurelien/anaconda3/envs/napari-env/lib/python3.8/site-packages/magicgui/widgets/_bases/value_widget.py”, line 44, in
lambda *x: self.changed(value=x[0] if x else None)
File “/home/aurelien/anaconda3/envs/napari-env/lib/python3.8/site-packages/magicgui/events.py”, line 603, in call
self._invoke_callback(cb, event)
File “/home/aurelien/anaconda3/envs/napari-env/lib/python3.8/site-packages/magicgui/events.py”, line 621, in _invoke_callback
_handle_exception(
File “/home/aurelien/anaconda3/envs/napari-env/lib/python3.8/site-packages/magicgui/events.py”, line 619, in _invoke_callback
cb(event)
File “/home/aurelien/anaconda3/envs/napari-env/lib/python3.8/site-packages/magicgui/widgets/_concrete.py”, line 423, in _on_choose_clicked
result = self._show_file_dialog(
File “/home/aurelien/anaconda3/envs/napari-env/lib/python3.8/site-packages/magicgui/backends/_qtpy/widgets.py”, line 549, in show_file_dialog
result = show_dialog(*args)
TypeError: getExistingDirectory(parent: QWidget = None, caption: str = ‘’, directory: str = ‘’, options: Union[QFileDialog.Options, QFileDialog.Option] = QFileDialog.ShowDirsOnly): argument 4 has unexpected type ‘NoneType’

Does anyone know how I could fix this?

Edit: I am running napari 0.4.5 on Ubuntu 18.04

Hi @abarbotin and welcome to imagesc. This is a perfectly fine place to ask this question, and note that you can also report bugs on the respective package’s github page. (note also that this is a magicgui issue, not a napari issue, and you could report it here)

This particular issue was fixed in Fix FileEdit with directory mode by tlambert03 · Pull Request #158 · napari/magicgui · GitHub and has been released in magicgui 0.2.7. please try updating magicgui with pip install -U magicgui

Great, that solved it thanks! I will use github next time.