From 86f4aac9f4af11873fbf0d8b06c99c6715e3b5c6 Mon Sep 17 00:00:00 2001 From: Xing Wang Date: Tue, 9 Apr 2024 10:34:00 +0200 Subject: [PATCH] hide kill button when the process is done (#648) * add process status information along with the kill button * hide kill button when the process is done, and replace it with "Workflow completed successfully!" --- src/aiidalab_qe/app/result/__init__.py | 27 +++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/aiidalab_qe/app/result/__init__.py b/src/aiidalab_qe/app/result/__init__.py index 125c5c738..7a3d2640a 100644 --- a/src/aiidalab_qe/app/result/__init__.py +++ b/src/aiidalab_qe/app/result/__init__.py @@ -13,6 +13,10 @@ # trigger registration of the viewer widget: from .workchain_viewer import WorkChainViewer # noqa: F401 +PROCESS_COMPLETED = "

Workflow completed successfully!

" +PROCESS_EXCEPTED = "

Workflow is excepted!

" +PROCESS_RUNNING = "

Workflow is running!

" + class ViewQeAppWorkChainStatusAndResultsStep(ipw.VBox, WizardAppWidgetStep): process = tl.Unicode(allow_none=True) @@ -50,8 +54,15 @@ def __init__(self, **kwargs): layout=ipw.Layout(width="120px", height="40px"), ) self.kill_button.on_click(self._on_click_kill_button) + self.process_info = ipw.HTML() - super().__init__([self.kill_button, self.process_status], **kwargs) + super().__init__( + [ + ipw.HBox(children=[self.kill_button, self.process_info]), + self.process_status, + ], + **kwargs, + ) self._update_kill_button_layout() @@ -75,21 +86,31 @@ def _update_state(self): ProcessState.WAITING, ): self.state = self.State.ACTIVE + self.process_info.value = PROCESS_RUNNING elif ( process_state in (ProcessState.EXCEPTED, ProcessState.KILLED) or process.is_failed ): self.state = self.State.FAIL + self.kill_button.layout.display = "none" + self.process_info.value = PROCESS_EXCEPTED elif process.is_finished_ok: self.state = self.State.SUCCESS + self.kill_button.layout.display = "none" + self.process_info.value = PROCESS_COMPLETED def _update_kill_button_layout(self): """Update the layout of the kill button.""" # If no process is selected, hide the button. - if self.process is None: + if self.process is None or self.process == "": self.kill_button.layout.display = "none" else: - self.kill_button.layout.display = "block" + process = orm.load_node(self.process) + # If the process is finished or excepted, hide the button. + if process.is_finished or process.is_excepted: + self.kill_button.layout.display = "none" + else: + self.kill_button.layout.display = "block" # If the step is not activated, no point to click the button, so disable it. # Only enable it if the process is on (RUNNING, CREATED, WAITING).