-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #356 from kreshuklab/headless_gui
Improved Headless + gui
- Loading branch information
Showing
10 changed files
with
314 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""This module contains the headless workflow for PlantSeg. | ||
To build a headless workflow, you can: | ||
- Register a new workflow manually using the plantseg API. | ||
- Run a workflow from the napari viewer and export it as a configuration file. | ||
The headless workflow configured can be run using the `run_headless_workflow` function. | ||
""" | ||
|
||
from plantseg.headless.headless import run_headles_workflow_from_config, run_headless_workflow | ||
|
||
__all__ = ["run_headles_workflow_from_config", "run_headless_workflow"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from enum import Enum | ||
|
||
from magicgui import magicgui | ||
from magicgui.experimental import guiclass | ||
from magicgui.widgets import Container | ||
|
||
# from plantseg.headless.headless import run_headless_workflow_from_path | ||
from plantseg.headless_gui.plantseg_classic import widget_plantseg_classic | ||
|
||
all_workflows = { | ||
"PlantsegClassic": widget_plantseg_classic, | ||
} | ||
|
||
|
||
@magicgui( | ||
auto_call=True, | ||
name={ | ||
'label': 'Mode', | ||
'tooltip': 'Select the workflow to run', | ||
'choices': list(all_workflows.keys()), | ||
}, | ||
) | ||
def workflow_selector(name: str = list(all_workflows.keys())[0]): | ||
for workflow in all_workflows.values(): | ||
workflow.hide() | ||
|
||
all_workflows[name].show() | ||
|
||
|
||
if __name__ == "__main__": | ||
gui_container = Container(widgets=[workflow_selector, *all_workflows.values()], labels=False) | ||
workflow_selector() | ||
gui_container.show(run=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from enum import Enum | ||
from pathlib import Path | ||
|
||
from magicgui import magicgui | ||
from magicgui.widgets import Container | ||
|
||
######################################################################################################################## | ||
# | ||
# Input Setup Widget | ||
# | ||
######################################################################################################################## | ||
|
||
|
||
class FilePickMode(Enum): | ||
File = 'File' | ||
Directory = 'Directory' | ||
|
||
@classmethod | ||
def to_choices(cls) -> list[str]: | ||
return [mode.value for mode in FilePickMode] | ||
|
||
|
||
@magicgui( | ||
call_button=False, | ||
file_pick_mode={ | ||
'label': 'Input Mode', | ||
'tooltip': 'Select the workflow to run', | ||
'choices': FilePickMode.to_choices(), | ||
}, | ||
file={ | ||
'label': 'File', | ||
'mode': 'r', | ||
'layout': 'vertical', | ||
'tooltip': 'Select the file to process one by one', | ||
}, | ||
directory={ | ||
'label': 'Directory', | ||
'mode': 'd', | ||
'tooltip': 'Process all files in the directory', | ||
}, | ||
) | ||
def widget_input_model( | ||
file_pick_mode: str = FilePickMode.File.value, | ||
file: Path = Path('.').absolute(), | ||
directory: Path = Path('.').absolute(), | ||
): | ||
pass | ||
|
||
|
||
@widget_input_model.file_pick_mode.changed.connect | ||
def _on_mode_change(file_pick_mode): | ||
if file_pick_mode == FilePickMode.File.value: | ||
widget_input_model.file.show() | ||
widget_input_model.directory.hide() | ||
else: | ||
widget_input_model.file.hide() | ||
widget_input_model.directory.show() | ||
|
||
|
||
widget_input_model.directory.hide() | ||
|
||
|
||
######################################################################################################################## | ||
# | ||
# PlantSeg Classic Workflow | ||
# | ||
######################################################################################################################## | ||
@magicgui( | ||
call_button="Run - PlantSeg Classic", | ||
) | ||
def widget_setup_workflow_config(): | ||
pass | ||
|
||
|
||
widget_plantseg_classic = Container(widgets=[widget_input_model, widget_setup_workflow_config], labels=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.