Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support-the-multi-attachmentviewer #1434

Merged
merged 5 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 5 additions & 0 deletions pykechain/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -250,6 +251,7 @@ class WidgetNames(Enum):
SERVICEWIDGET = "serviceWidget"
NOTEBOOKWIDGET = "notebookWidget"
ATTACHMENTVIEWERWIDGET = "attachmentViewerWidget"
MULTIATTACHMENTVIEWERWIDGET = "multiAttachmentViewerWidget"
TASKNAVIGATIONBARWIDGET = "taskNavigationBarWidget"
JSONWIDGET = "jsonWidget"
METAPANELWIDGET = "metaPanelWidget"
Expand Down Expand Up @@ -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
Expand All @@ -304,6 +307,7 @@ class WidgetTypes(Enum):
SERVICE = "SERVICE"
NOTEBOOK = "NOTEBOOK"
ATTACHMENTVIEWER = "ATTACHMENTVIEWER"
MULTIATTACHMENTVIEWER = "MULTIATTACHMENTVIEWER"
TASKNAVIGATIONBAR = "TASKNAVIGATIONBAR"
JSON = "JSON"
METAPANEL = "METAPANEL"
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions pykechain/models/widgets/widget_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# SERVICE
# NOTEBOOK
# ATTACHMENTVIEWER
# MULTIATTACHMENTVIEWER
# TASKNAVIGATIONBAR
# JSON
# METAPANEL
Expand Down Expand Up @@ -62,6 +63,10 @@ class AttachmentviewerWidget(Widget):
"""Attachmentviewer Widget."""


class MultiAttachmentviewerWidget(Widget):
"""Multi Attachmentviewer Widget."""


class TasknavigationbarWidget(Widget):
"""Tasknavigationbar Widget."""

Expand Down
64 changes: 63 additions & 1 deletion pykechain/models/widgets/widgets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -673,6 +682,59 @@ def add_attachmentviewer_widget(

return widget

def add_multiattachmentviewer_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]],
Expand Down
Loading