From 383435565a63b00c8d10f238d8a77409d0d7822e Mon Sep 17 00:00:00 2001 From: GoldenAnpu Date: Tue, 13 Aug 2024 18:22:01 +0200 Subject: [PATCH] Refactor workflow.py for improved readability and maintainability --- src/workflow.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/workflow.py b/src/workflow.py index 73d20b6..31cdd4d 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -1,26 +1,29 @@ # This module contains the functions that are used to configure the input and output of the workflow for the current app. -import supervisely as sly from typing import Union +import supervisely as sly + + def workflow_input(api: sly.Api, project_id: int): api.app.workflow.add_input_project(project_id) sly.logger.debug(f"Workflow: Input project - {project_id}") + def workflow_output(api: sly.Api, file: Union[int, sly.api.file_api.FileInfo]): try: if isinstance(file, int): file = api.file.get_info_by_id(file) - meta = {"customRelationSettings": { - "icon": { - "icon": "zmdi-archive", - "color": "#33c94c", - "backgroundColor": "#d9f7e4" - }, - "title": f"

{file.name}

", - "mainLink": {"url": f"/files/{file.id}/true/?teamId={file.team_id}", "title": "Download"} - }} + relation_settings = sly.app.WorkflowSettings( + title=file.name, + icon="archive", + color="#33c94c", + background_color="#d9f7e4", + url=f"/files/{file.id}/true/?teamId={file.team_id}", + url_title="Download", + ) + meta = sly.app.WorkflowMeta.create_as_dict(relation_settings=relation_settings) api.app.workflow.add_output_file(file, meta=meta) sly.logger.debug(f"Workflow: Output file - {file}") except Exception as e: - sly.logger.debug(f"Failed to add output to the workflow: {repr(e)}") \ No newline at end of file + sly.logger.debug(f"Failed to add output to the workflow: {repr(e)}")