1414 ui , # noq
1515)
1616from nicegui import run as nicegui_run
17- from nicegui .events import ClickEventArguments
1817
19- from aignostics .platform import ItemOutput , ItemResult , ItemState , Run , RunState
18+ from aignostics .platform import ItemOutput , ItemResult , ItemState , RunState
2019from aignostics .third_party .showinfm .showinfm import show_in_file_manager
2120from aignostics .utils import GUILocalFilePicker , get_user_data_directory
2221
@@ -339,9 +338,9 @@ async def start_download() -> None:
339338
340339 # Activate the timer now that download is starting
341340 progress_timer .activate ()
342- download_button .disable ()
343- download_button .props (add = "loading" )
344341 try :
342+ download_button .disable ()
343+ download_button .props (add = "loading" )
345344 results_folder = await nicegui_run .cpu_bound (
346345 Service .application_run_download_static ,
347346 run_id = run .run_id ,
@@ -365,24 +364,19 @@ async def start_download() -> None:
365364 else :
366365 ui .notify ("Download completed." , type = "positive" )
367366 show_in_file_manager (str (results_folder ))
368- except Exception as e :
369- logger .exception (
370- "Download failed for run {} (qupath_project={}, marimo={}, folder={})" ,
371- run .run_id ,
372- current_qupath_project ,
373- current_marimo ,
374- current_folder ,
375- )
367+ except ValueError as e :
376368 ui .notify (f"Download failed: { e } " , type = "negative" , multi_line = True )
377- finally :
378369 progress_timer .deactivate ()
379370 progress_state ["queue" ] = None
380- download_button .props (remove = "loading" )
381- download_button .enable ()
382- download_item_status .set_visibility (False )
383- download_item_progress .set_visibility (False )
384- download_artifact_status .set_visibility (False )
385- download_artifact_progress .set_visibility (False )
371+ return
372+ progress_timer .deactivate ()
373+ progress_state ["queue" ] = None
374+ download_button .props (remove = "loading" )
375+ download_button .enable ()
376+ download_item_status .set_visibility (False )
377+ download_item_progress .set_visibility (False )
378+ download_artifact_status .set_visibility (False )
379+ download_artifact_progress .set_visibility (False )
386380
387381 ui .separator ()
388382 with ui .row (align_items = "end" ).classes ("w-full justify-end" ):
@@ -787,85 +781,29 @@ def render_item(item: ItemResult) -> None: # noqa: C901, PLR0912, PLR0915
787781 icon = mime_type_to_icon (mime_type ),
788782 group = "artifacts" ,
789783 ).classes ("w-full" ):
790- if artifact .output_artifact_id :
791- artifact_id = artifact .output_artifact_id
784+ if artifact .download_url :
785+ url = artifact .download_url
792786 title = artifact .name
793787 metadata = artifact .metadata
794-
795788 with ui .button_group ():
796789 if mime_type == "image/tiff" :
797- preview_button = ui .button (
790+ ui .button (
798791 "Preview" ,
799792 icon = mime_type_to_icon (mime_type ),
793+ on_click = lambda _ , url = url , title = title : tiff_dialog_open (title , url ),
800794 )
801-
802- async def _preview_tiff (
803- _ : ClickEventArguments ,
804- aid : str = artifact_id ,
805- t : str = title ,
806- _run : Run = run ,
807- _btn : ui .button = preview_button ,
808- ) -> None :
809- try :
810- _btn .props (add = "loading" )
811- url = await nicegui_run .io_bound (
812- _run .get_artifact_download_url , aid
813- )
814- tiff_dialog_open (t , url )
815- except Exception as e :
816- ui .notify (f"Failed to resolve preview URL: { e } " , type = "warning" )
817- finally :
818- _btn .props (remove = "loading" )
819-
820- preview_button .on_click (_preview_tiff )
821-
822795 if mime_type == "text/csv" :
823- preview_button = ui .button (
796+ ui .button (
824797 "Preview" ,
825798 icon = mime_type_to_icon (mime_type ),
799+ on_click = lambda _ , url = url , title = title : csv_dialog_open (title , url ),
800+ )
801+ if url :
802+ ui .button (
803+ text = "Download" ,
804+ icon = "cloud_download" ,
805+ on_click = lambda _ , url = url : webbrowser .open (url ),
826806 )
827-
828- async def _preview_csv (
829- _ : ClickEventArguments ,
830- aid : str = artifact_id ,
831- t : str = title ,
832- _run : Run = run ,
833- _btn : ui .button = preview_button ,
834- ) -> None :
835- try :
836- _btn .props (add = "loading" )
837- url = await nicegui_run .io_bound (
838- _run .get_artifact_download_url , aid
839- )
840- csv_dialog_open (t , url )
841- except Exception as e :
842- ui .notify (f"Failed to resolve preview URL: { e } " , type = "warning" )
843- finally :
844- _btn .props (remove = "loading" )
845-
846- preview_button .on_click (_preview_csv )
847-
848- artifact_dl_button = ui .button (
849- text = "Download" ,
850- icon = "cloud_download" ,
851- )
852-
853- async def _download_artifact (
854- _ : ClickEventArguments ,
855- aid : str = artifact_id ,
856- _run : Run = run ,
857- _btn : ui .button = artifact_dl_button ,
858- ) -> None :
859- try :
860- _btn .props (add = "loading" )
861- url = await nicegui_run .io_bound (_run .get_artifact_download_url , aid )
862- webbrowser .open (url )
863- except Exception as e :
864- ui .notify (f"Failed to resolve download URL: { e } " , type = "warning" )
865- finally :
866- _btn .props (remove = "loading" )
867-
868- artifact_dl_button .on_click (_download_artifact )
869807 if metadata :
870808 ui .button (
871809 text = "Schema" ,
0 commit comments