Skip to content

Commit

Permalink
Studio: Create dataset ROI folder during export if it does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdolezal committed Jan 24, 2024
1 parent b9982f4 commit f5914e4
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions slideflow/studio/widgets/roi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import imgui
import numpy as np
import glfw
from os.path import join
import os
from os.path import join, exists, dirname
from shapely.geometry import Point
from shapely.geometry import Polygon
from tkinter.filedialog import askopenfilename
Expand Down Expand Up @@ -170,15 +171,18 @@ def _update_grid(self) -> None:
elif view.is_moving():
self.roi_grid = None

def get_roi_dest(self, slide: str) -> str:
def get_roi_dest(self, slide: str, create: bool = False) -> str:
"""Get the destination for a ROI file."""
viz = self.viz
if viz.P is None:
return None
dataset = viz.P.dataset()
source = dataset.get_slide_source(slide)
return (dataset.find_rois(slide)
or join(dataset.sources[source]['roi'], f'{slide}.csv'))
filename = (dataset.find_rois(slide)
or join(dataset.sources[source]['roi'], f'{slide}.csv'))
if dirname(filename) and not exists(dirname(filename)) and create:
os.makedirs(dirname(filename))
return filename

# --- Callbacks -----------------------------------------------------------

Expand Down Expand Up @@ -503,7 +507,8 @@ def draw_options(self):

# Save button.
if viz.sidebar.large_image_button('floppy', size=viz.font_size*3):
dest = viz.wsi.export_rois(self.get_roi_dest(viz.wsi.name))
roi_file = self.get_roi_dest(viz.wsi.name, create=True)
dest = viz.wsi.export_rois(roi_file)
viz.create_toast(f'ROIs saved to {dest}', icon='success')
self.reset_edit_state()
if imgui.is_item_hovered():
Expand Down

0 comments on commit f5914e4

Please sign in to comment.