From 3efd1a35ccf34bb1e66f797ce70e3f5dcaa757e1 Mon Sep 17 00:00:00 2001 From: Jochem Berends Date: Tue, 4 Jun 2024 13:56:41 +0200 Subject: [PATCH 1/3] Add multi attachment viewer widget support to Pykechain Updated Pykechain to include support for a new multi attachment viewer widget. This update includes changes to the widgets manager, the enums file, and the widget models file to accommodate the new widget type. Now, users can add and customize multi attachment viewer widgets in Pykechain with the provided methods. --- pykechain/enums.py | 5 ++ pykechain/models/widgets/widget_models.py | 5 ++ pykechain/models/widgets/widgets_manager.py | 64 ++++++++++++++++++++- 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/pykechain/enums.py b/pykechain/enums.py index ce19a86cc..5e7c92b78 100644 --- a/pykechain/enums.py +++ b/pykechain/enums.py @@ -227,6 +227,7 @@ class WidgetNames(Enum): :cvar SERVICEWIDGET: serviceWidget :cvar NOTEBOOKWIDGET: notebookWidget :cvar ATTACHMENTVIEWERWIDGET: attachmentViewerWidget + :cvar MULTIATTACHMENTVIEWERWIDGET: multiAttachmentViewerWidget :cvar TASKNAVIGATIONBARWIDGET: taskNavigationBarWidget :cvar JSONWIDGET: jsonWidget @@ -250,6 +251,7 @@ class WidgetNames(Enum): SERVICEWIDGET = "serviceWidget" NOTEBOOKWIDGET = "notebookWidget" ATTACHMENTVIEWERWIDGET = "attachmentViewerWidget" + MULTIATTACHMENTVIEWERWIDGET = "multiAttachmentViewerWidget" TASKNAVIGATIONBARWIDGET = "taskNavigationBarWidget" JSONWIDGET = "jsonWidget" METAPANELWIDGET = "metaPanelWidget" @@ -279,6 +281,7 @@ class WidgetTypes(Enum): :cvar SERVICE: Service widget :cvar NOTEBOOK: Notebook widget :cvar ATTACHMENTVIEWER: Attachmentviewer widget + :cvar MULTIATTACHMENTVIEWER: MultiAttachmentviewer widget :cvar TASKNAVIGATIONBAR: Tasknavigationbar widget :cvar JSON: Json widget :cvar METAPANEL: Metapanel widget @@ -304,6 +307,7 @@ class WidgetTypes(Enum): SERVICE = "SERVICE" NOTEBOOK = "NOTEBOOK" ATTACHMENTVIEWER = "ATTACHMENTVIEWER" + MULTIATTACHMENTVIEWER = "MULTIATTACHMENTVIEWER" TASKNAVIGATIONBAR = "TASKNAVIGATIONBAR" JSON = "JSON" METAPANEL = "METAPANEL" @@ -330,6 +334,7 @@ class WidgetTypes(Enum): WidgetNames.SERVICEWIDGET: WidgetTypes.SERVICE, WidgetNames.NOTEBOOKWIDGET: WidgetTypes.NOTEBOOK, WidgetNames.ATTACHMENTVIEWERWIDGET: WidgetTypes.ATTACHMENTVIEWER, + WidgetNames.MULTIATTACHMENTVIEWERWIDGET: WidgetTypes.MULTIATTACHMENTVIEWER, WidgetNames.TASKNAVIGATIONBARWIDGET: WidgetTypes.TASKNAVIGATIONBAR, WidgetNames.JSONWIDGET: WidgetTypes.JSON, WidgetNames.METAPANELWIDGET: WidgetTypes.METAPANEL, diff --git a/pykechain/models/widgets/widget_models.py b/pykechain/models/widgets/widget_models.py index 96db4a9b8..1a293761e 100644 --- a/pykechain/models/widgets/widget_models.py +++ b/pykechain/models/widgets/widget_models.py @@ -9,6 +9,7 @@ # SERVICE # NOTEBOOK # ATTACHMENTVIEWER +# MULTIATTACHMENTVIEWER # TASKNAVIGATIONBAR # JSON # METAPANEL @@ -62,6 +63,10 @@ class AttachmentviewerWidget(Widget): """Attachmentviewer Widget.""" +class MultiAttachmentviewerWidget(Widget): + """Multi Attachmentviewer Widget.""" + + class TasknavigationbarWidget(Widget): """Tasknavigationbar Widget.""" diff --git a/pykechain/models/widgets/widgets_manager.py b/pykechain/models/widgets/widgets_manager.py index b8c972abd..21eba2e6e 100644 --- a/pykechain/models/widgets/widgets_manager.py +++ b/pykechain/models/widgets/widgets_manager.py @@ -663,8 +663,17 @@ def add_attachmentviewer_widget( else: kwargs.update({"readable_models": [attachment_model_id]}) + widget_type = WidgetTypes.ATTACHMENTVIEWER + # we also use this function to make the MULTI ATTACHMENT VIEWER widget + # this can be provided in the kwargs as 'widget_type' argument + if ( + "widget_type" in kwargs + and kwargs.get("widget_type") == WidgetTypes.MULTIATTACHMENTVIEWER + ): + widget_type = kwargs.get("widget_type") + widget = self.create_widget( - widget_type=WidgetTypes.ATTACHMENTVIEWER, + widget_type=widget_type, meta=meta, title=title, parent=parent_widget, @@ -673,6 +682,59 @@ def add_attachmentviewer_widget( return widget + def add_mutliattachmentviewer_widget( + self, + attachment_property: Union[str, "AttachmentProperty"], + editable: Optional[bool] = False, + title: TITLE_TYPING = False, + parent_widget: Optional[Union[Widget, str]] = None, + alignment: Optional[Alignment] = None, + image_fit: Optional[Union[ImageFitValue, str]] = ImageFitValue.CONTAIN, + show_download_button: Optional[bool] = True, + show_full_screen_button: Optional[bool] = True, + **kwargs, + ) -> Widget: + """ + Add a KE-chain Multi Attachment widget widget manager. + + The widget will be saved to KE-chain. + + :param attachment_property: KE-chain Attachment property to display + :type attachment_property: AttachmentProperty + :param editable: Whether the attachment can be added, edited or deleted (default: False) + :type editable: bool + :param title: A custom title for the script widget + * False (default): Property name + * String value: Custom title + * None: No title + :type title: bool or basestring or None + :param alignment: horizontal alignment of the previewed attachment (Alignment enum class) + :type alignment: Alignment + :param image_fit: (O) enumeration to address the image_fit (defaults to 'contain', otherwise 'cover') + :type image_fit: basestring or None + :param show_download_button: (O) whether a user can download the attached figure (defaults to True) + :type show_download_button: bool + :param show_full_screen_button: (O) whether the figure can be expanded to fit the full screen (defaults to True) + :type show_full_screen_button: bool + :param kwargs: additional keyword arguments to pass + :return: newly created widget + :rtype: Widget + :raises IllegalArgumentError: when incorrect arguments are provided + :raises APIError: When the widget could not be created. + """ + return self.add_attachmentviewer_widget( + attachment_property, + editable, + title, + parent_widget, + alignment, + image_fit, + show_download_button, + show_full_screen_button, + widget_type=WidgetTypes.MULTIATTACHMENTVIEWER, + **kwargs, + ) + def add_tasknavigationbar_widget( self, activities: Union[Iterable[Dict]], From 8c703fef22c85af0d4170e85d11261c53861bfe7 Mon Sep 17 00:00:00 2001 From: jberends Date: Mon, 17 Jun 2024 13:44:25 +0200 Subject: [PATCH 2/3] Update pykechain/models/widgets/widgets_manager.py --- pykechain/models/widgets/widgets_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pykechain/models/widgets/widgets_manager.py b/pykechain/models/widgets/widgets_manager.py index 21eba2e6e..ec268c342 100644 --- a/pykechain/models/widgets/widgets_manager.py +++ b/pykechain/models/widgets/widgets_manager.py @@ -682,7 +682,7 @@ def add_attachmentviewer_widget( return widget - def add_mutliattachmentviewer_widget( + def add_multiattachmentviewer_widget( self, attachment_property: Union[str, "AttachmentProperty"], editable: Optional[bool] = False, From e32cfafe0dd8d6e8acaad025d53bd68710a7196e Mon Sep 17 00:00:00 2001 From: Jochem Berends Date: Tue, 2 Jul 2024 11:24:18 +0200 Subject: [PATCH 3/3] Add multiattachment viewer widget and update dependent versions In this commit, a multiattachment viewer widget has been added to the codebase. This update is made to align with the KE-chain-2 backend. Additionally, dependent versions for development have been updated. --- CHANGELOG.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 25cebf193..bd894135e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ Change Log ========== +v4.12.0 (UNRELEASED) +-------------------- +* :star: Added the multiattachment viewer widget to the codebase in alignment with KE-chain-2 backend. (#1434) +* :+1: dependent versions for development + v4.11.0 (27MAY24) ----------------- * :+1: Added the `ShowScopeMembersOnly` representation on the `UserReferenceProperty`. (#1418)