Skip to content

Implement logging widget (mostly for devs) #1133

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

Merged
merged 2 commits into from
Feb 5, 2025
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
39 changes: 36 additions & 3 deletions src/aiidalab_qe/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from pathlib import Path

import ipywidgets as ipw
from IPython.display import display

from aiidalab_qe.app.static import styles
Expand All @@ -20,12 +21,17 @@

class QeApp:
def __init__(
self, process=None, qe_auto_setup=True, bug_report_url=DEFAULT_BUG_REPORT_URL
self,
process=None,
qe_auto_setup=True,
bug_report_url=DEFAULT_BUG_REPORT_URL,
show_log=False,
):
"""Initialize the AiiDAlab QE application with the necessary setup."""

self.process = process
self.qe_auto_setup = qe_auto_setup
self.log_widget = None

self._load_styles()

Expand All @@ -34,10 +40,34 @@ def __init__(
self.view = AppWrapperView()
display(self.view)

if show_log:
self.log_widget = ipw.Output(
layout=ipw.Layout(
border="solid 1px lightgray",
margin="2px",
padding="5px",
),
)
reset_button = ipw.Button(
description="Clear log",
button_style="primary",
icon="trash",
layout=ipw.Layout(width="fit-content"),
)
reset_button.on_click(lambda _: self.log_widget.clear_output())
display(
ipw.VBox(
children=[
reset_button,
self.log_widget,
],
)
)

# Set up bug report handling (if a URL is provided)
if bug_report_url:
install_create_github_issue_exception_handler(
self.view.output,
self.log_widget if show_log else self.view.output,
url=bug_report_url,
labels=("bug", "automated-report"),
)
Expand All @@ -52,7 +82,10 @@ def _load_styles(self):

def load(self):
"""Initialize the WizardApp and integrate the app into the main view."""
self.app = WizardApp(qe_auto_setup=self.qe_auto_setup)
self.app = WizardApp(
qe_auto_setup=self.qe_auto_setup,
log_widget=self.log_widget,
)
self.view.main.children = [self.app]
# load a previous calculation if it is provided
if self.process:
Expand Down
2 changes: 2 additions & 0 deletions src/aiidalab_qe/app/result/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ViewQeAppWorkChainStatusAndResultsStep(QeDependentWizardStep[ResultsStepMo
)

def __init__(self, model: ResultsStepModel, **kwargs):
self.log_widget = kwargs.pop("log_widget", None)
super().__init__(model=model, **kwargs)
self.observe(
self._on_previous_step_state_change,
Expand Down Expand Up @@ -130,6 +131,7 @@ def _post_render(self):
self._update_status,
self._update_state,
],
log_widget=self.log_widget,
)
ipw.dlink(
(self._model, "process_uuid"),
Expand Down
8 changes: 6 additions & 2 deletions src/aiidalab_qe/app/wizard_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ class WizardApp(ipw.VBox):
# The PK or UUID of the work chain node.
process = tl.Union([tl.Unicode(), tl.Int()], allow_none=True)

def __init__(self, qe_auto_setup=True):
def __init__(self, qe_auto_setup=True, **kwargs):
# Initialize the models
self.structure_model = StructureStepModel()
self.configure_model = ConfigurationStepModel()
self.submit_model = SubmissionStepModel()
self.results_model = ResultsStepModel()

log_widget = kwargs.pop("log_widget", None)

# Create the application steps
self.structure_step = StructureSelectionStep(
model=self.structure_model,
Expand All @@ -46,6 +48,7 @@ def __init__(self, qe_auto_setup=True):
)
self.results_step = ViewQeAppWorkChainStatusAndResultsStep(
model=self.results_model,
log_widget=log_widget,
)

# Wizard step observations
Expand Down Expand Up @@ -102,7 +105,8 @@ def __init__(self, qe_auto_setup=True):
self._process_loading_message,
self._wizard_app_widget,
InAppGuide(identifier="post-guide"),
]
],
**kwargs,
)

self._wizard_app_widget.selected_index = None
Expand Down
2 changes: 1 addition & 1 deletion src/aiidalab_qe/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"AddingTagsEditor",
"LazyLoadedOptimade",
"LazyLoadedStructureBrowser",
"PeriodicityEditor",
"QeAppWorkChainSelector",
"WorkChainSelector",
"PeriodicityEditor",
]
Loading