Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt LoadClassifierContainer to allow other file extensions #36

Closed
fdsteffen opened this issue Sep 3, 2023 · 0 comments · Fixed by #37
Closed

Adapt LoadClassifierContainer to allow other file extensions #36

fdsteffen opened this issue Sep 3, 2023 · 0 comments · Fixed by #37

Comments

@fdsteffen
Copy link
Contributor

When reloading a classifier magicgui's FileEdit widget currently filters for files with the extension *.clf.

# LoadClassifierContainer class from classifier_widget.py
def __init__(self, viewer: napari.viewer.Viewer):
    self._viewer = viewer
    self._clf_destination = FileEdit(mode="r", filter="*.clf")
    self._load_button = PushButton(label="Load Classifier")

Classifiers saved with another file extension (e.g. standard python .pkl files) can currently not be loaded again. Unfortunately, the FileEdit widget itself does not allow to deactivate the filter and choose another filetype. A possible workaround may be to include a filter RadioButtons widget to set the filter to all files *.

I could think of something along these lines:

def __init__(self, viewer: napari.viewer.Viewer):
    self._viewer = viewer
    self._clf_destination = FileEdit(mode="r", filter=None)
    self._filter = RadioButtons(
        value="*.clf",
        choices=["*.clf", "*.pkl", "*"],
        orientation="horizontal",
        label="Filter",
    )
    self._load_button = PushButton(label="Load Classifier")
    self._run_container = None
    super().__init__(
        widgets=[self._clf_destination, self._filter, self._load_button]
    )
    self._load_button.clicked.connect(self.load)
    self._filter.changed.connect(self.set_filter)

def set_filter(self):
    self._clf_destination.filter = self._filter.value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant