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

hide kill button when the process is done #648

Merged
merged 7 commits into from
Apr 9, 2024
27 changes: 24 additions & 3 deletions src/aiidalab_qe/app/result/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# trigger registration of the viewer widget:
from .workchain_viewer import WorkChainViewer # noqa: F401

PROCESS_COMPLETED = "<h4>Workflow completed successfully!</h4>"
PROCESS_EXCEPTED = "<h4>Workflow is excepted!</h4>"
PROCESS_RUNNING = "<h4>Workflow is running!</h4>"


class ViewQeAppWorkChainStatusAndResultsStep(ipw.VBox, WizardAppWidgetStep):
process = tl.Unicode(allow_none=True)
Expand Down Expand Up @@ -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()

Expand All @@ -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).
Expand Down
Loading