diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cff2a0778..e5d30f0ad 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ ci: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-json - id: check-yaml @@ -13,7 +13,7 @@ repos: exclude: miscellaneous/structures - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.0 + rev: v0.6.9 hooks: - id: ruff-format exclude: ^docs/.* @@ -27,7 +27,7 @@ repos: args: [--preserve-quotes] - repo: https://github.com/sirosen/check-jsonschema - rev: 0.28.6 + rev: 0.29.3 hooks: - id: check-github-workflows diff --git a/aiidalab_widgets_base/wizard.py b/aiidalab_widgets_base/wizard.py index 074433769..0c633683d 100644 --- a/aiidalab_widgets_base/wizard.py +++ b/aiidalab_widgets_base/wizard.py @@ -88,7 +88,7 @@ class WizardAppWidget(ipw.VBox): selected_index = tl.Int(allow_none=True) - def __init__(self, steps, **kwargs): + def __init__(self, steps, show_header=True, **kwargs): # The number of steps must be greater than one # for this app's logic to make sense. if len(steps) < 2: @@ -142,11 +142,20 @@ def __init__(self, steps, **kwargs): ) self.next_button.on_click(self._on_click_next_button) - header = ipw.HBox( + self.header = ipw.HBox( children=[self.back_button, self.reset_button, self.next_button] ) + self.show_header = show_header - super().__init__(children=[header, self.accordion], **kwargs) + super().__init__(children=[self.header, self.accordion], **kwargs) + + @property + def show_header(self): + return self.header.layout.display != "none" + + @show_header.setter + def show_header(self, value): + self.header.layout.display = "flex" if value else "none" def _update_titles(self): for i, (title, widget) in enumerate(zip(self.titles, self.accordion.children)): diff --git a/notebooks/eln_import.ipynb b/notebooks/eln_import.ipynb index 51e566821..e3863c868 100644 --- a/notebooks/eln_import.ipynb +++ b/notebooks/eln_import.ipynb @@ -42,10 +42,15 @@ "metadata": {}, "outputs": [], "source": [ - "from aiidalab_widgets_base import AiidaNodeViewWidget, OpenAiidaNodeInAppWidget, ElnImportWidget\n", "import urllib.parse as urlparse\n", - "from aiidalab_widgets_base import viewer\n", - "from traitlets import dlink" + "\n", + "from traitlets import dlink\n", + "\n", + "from aiidalab_widgets_base import (\n", + " AiidaNodeViewWidget,\n", + " ElnImportWidget,\n", + " OpenAiidaNodeInAppWidget,\n", + ")" ] }, { @@ -55,9 +60,9 @@ "metadata": {}, "outputs": [], "source": [ - "url = urlparse.urlsplit(jupyter_notebook_url)\n", + "url = urlparse.urlsplit(jupyter_notebook_url) # noqa: F821\n", "parsed_url = urlparse.parse_qs(url.query)\n", - "params = {key:value[0] for key, value in parsed_url.items()}\n", + "params = {key: value[0] for key, value in parsed_url.items()}\n", "eln_widget = ElnImportWidget(**params)" ] }, @@ -71,8 +76,8 @@ "object_displayed = AiidaNodeViewWidget()\n", "open_in_app = OpenAiidaNodeInAppWidget()\n", "\n", - "_ = dlink((eln_widget, 'node'), (object_displayed, 'node'))\n", - "_ = dlink((eln_widget, 'node'), (open_in_app, 'node'))" + "_ = dlink((eln_widget, \"node\"), (object_displayed, \"node\"))\n", + "_ = dlink((eln_widget, \"node\"), (open_in_app, \"node\"))" ] }, { diff --git a/notebooks/process.ipynb b/notebooks/process.ipynb index 8584e6754..1dc8c6a53 100644 --- a/notebooks/process.ipynb +++ b/notebooks/process.ipynb @@ -37,13 +37,19 @@ "metadata": {}, "outputs": [], "source": [ - "import ipywidgets as ipw\n", - "from IPython.display import clear_output\n", - "from aiida.cmdline.utils.ascii_vis import format_call_graph\n", "import urllib.parse as urlparse\n", + "\n", "from aiida.orm import load_node\n", - "from aiidalab_widgets_base import ProcessFollowerWidget, ProgressBarWidget, ProcessReportWidget\n", - "from aiidalab_widgets_base import ProcessInputsWidget, ProcessOutputsWidget, ProcessCallStackWidget, RunningCalcJobOutputWidget" + "\n", + "from aiidalab_widgets_base import (\n", + " ProcessCallStackWidget,\n", + " ProcessFollowerWidget,\n", + " ProcessInputsWidget,\n", + " ProcessOutputsWidget,\n", + " ProcessReportWidget,\n", + " ProgressBarWidget,\n", + " RunningCalcJobOutputWidget,\n", + ")" ] }, { @@ -52,10 +58,10 @@ "metadata": {}, "outputs": [], "source": [ - "url = urlparse.urlsplit(jupyter_notebook_url)\n", + "url = urlparse.urlsplit(jupyter_notebook_url) # noqa: F821\n", "url_dict = urlparse.parse_qs(url.query)\n", - "if 'id' in url_dict:\n", - " pk = int(url_dict['id'][0])\n", + "if \"id\" in url_dict:\n", + " pk = int(url_dict[\"id\"][0])\n", " process = load_node(pk)\n", "else:\n", " process = None" @@ -101,8 +107,15 @@ "source": [ "follower = ProcessFollowerWidget(\n", " process,\n", - " followers=[ProgressBarWidget(), ProcessReportWidget(), ProcessCallStackWidget(), RunningCalcJobOutputWidget()], path_to_root=\"../../\", \n", - " update_interval=2)\n", + " followers=[\n", + " ProgressBarWidget(),\n", + " ProcessReportWidget(),\n", + " ProcessCallStackWidget(),\n", + " RunningCalcJobOutputWidget(),\n", + " ],\n", + " path_to_root=\"../../\",\n", + " update_interval=2,\n", + ")\n", "display(follower)\n", "follower.follow(detach=True)" ] diff --git a/notebooks/process_list.ipynb b/notebooks/process_list.ipynb index 6d2d8fc05..5765ad6ae 100644 --- a/notebooks/process_list.ipynb +++ b/notebooks/process_list.ipynb @@ -38,9 +38,10 @@ "outputs": [], "source": [ "import ipywidgets as ipw\n", - "from aiidalab_widgets_base import ProcessListWidget\n", + "from plumpy import ProcessState\n", "from traitlets import dlink\n", - "from plumpy import ProcessState" + "\n", + "from aiidalab_widgets_base import ProcessListWidget" ] }, { @@ -51,63 +52,68 @@ "source": [ "process_list = ProcessListWidget(path_to_root=\"../../\")\n", "\n", - "past_days_widget = ipw.IntText(value=7, description='Past days:')\n", - "dlink((past_days_widget, 'value'), (process_list, 'past_days'))\n", + "past_days_widget = ipw.IntText(value=7, description=\"Past days:\")\n", + "dlink((past_days_widget, \"value\"), (process_list, \"past_days\"))\n", "\n", "\n", "all_days_checkbox = ipw.Checkbox(description=\"All days\", value=False)\n", - "dlink((all_days_checkbox, 'value'), (past_days_widget, 'disabled'))\n", - "dlink((all_days_checkbox, 'value'), (process_list, 'past_days'), transform=lambda v: -1 if v else past_days_widget.value)\n", + "dlink((all_days_checkbox, \"value\"), (past_days_widget, \"disabled\"))\n", + "dlink(\n", + " (all_days_checkbox, \"value\"),\n", + " (process_list, \"past_days\"),\n", + " transform=lambda v: -1 if v else past_days_widget.value,\n", + ")\n", "\n", "incoming_node_widget = ipw.Text(\n", - " description='Incoming node:',\n", - " style={'description_width': 'initial'}\n", + " description=\"Incoming node:\", style={\"description_width\": \"initial\"}\n", ")\n", - "dlink((incoming_node_widget, 'value'), (process_list, 'incoming_node'))\n", + "dlink((incoming_node_widget, \"value\"), (process_list, \"incoming_node\"))\n", "\n", "\n", "outgoing_node_widget = ipw.Text(\n", - " description='Outgoing node:',\n", - " style={'description_width': 'initial'}\n", + " description=\"Outgoing node:\", style={\"description_width\": \"initial\"}\n", ")\n", - "dlink((outgoing_node_widget, 'value'), (process_list, 'outgoing_node'))\n", + "dlink((outgoing_node_widget, \"value\"), (process_list, \"outgoing_node\"))\n", "\n", "\n", "available_states = [state.value for state in ProcessState]\n", - "process_state_widget = ipw.SelectMultiple(options=available_states,\n", - " value=available_states,\n", - " description='Process State:',\n", - " style={'description_width': 'initial'},\n", - " disabled=False)\n", - "dlink((process_state_widget, 'value'), (process_list, 'process_states'))\n", + "process_state_widget = ipw.SelectMultiple(\n", + " options=available_states,\n", + " value=available_states,\n", + " description=\"Process State:\",\n", + " style={\"description_width\": \"initial\"},\n", + " disabled=False,\n", + ")\n", + "dlink((process_state_widget, \"value\"), (process_list, \"process_states\"))\n", "\n", "process_label_widget = ipw.Text(\n", - " description='Process label:',\n", - " style={'description_width': 'initial'}\n", + " description=\"Process label:\", style={\"description_width\": \"initial\"}\n", ")\n", - "dlink((process_label_widget, 'value'), (process_list, 'process_label'))\n", + "dlink((process_label_widget, \"value\"), (process_list, \"process_label\"))\n", "\n", "description_contains_widget = ipw.Text(\n", - " description='Description contains:',\n", - " style={'description_width': 'initial'}\n", + " description=\"Description contains:\", style={\"description_width\": \"initial\"}\n", ")\n", - "dlink((description_contains_widget, 'value'), (process_list, 'description_contains'))\n", + "dlink((description_contains_widget, \"value\"), (process_list, \"description_contains\"))\n", "\n", "display(\n", - " ipw.HBox([\n", - " ipw.VBox([past_days_widget, process_state_widget]),\n", - " ipw.VBox(\n", - " [\n", - " all_days_checkbox,\n", - " incoming_node_widget,\n", - " outgoing_node_widget,\n", - " process_label_widget,\n", - " description_contains_widget\n", - " ],\n", - " layout={'margin': '0px 0px 0px 40px'}\n", - " )\n", - " ]),\n", - " process_list)" + " ipw.HBox(\n", + " [\n", + " ipw.VBox([past_days_widget, process_state_widget]),\n", + " ipw.VBox(\n", + " [\n", + " all_days_checkbox,\n", + " incoming_node_widget,\n", + " outgoing_node_widget,\n", + " process_label_widget,\n", + " description_contains_widget,\n", + " ],\n", + " layout={\"margin\": \"0px 0px 0px 40px\"},\n", + " ),\n", + " ]\n", + " ),\n", + " process_list,\n", + ")" ] }, { diff --git a/notebooks/structures.ipynb b/notebooks/structures.ipynb index f5974aee6..7720474ee 100644 --- a/notebooks/structures.ipynb +++ b/notebooks/structures.ipynb @@ -57,10 +57,11 @@ " title=\"From Examples\",\n", " examples=[\n", " (\"Silicon oxide\", \"../miscellaneous/structures/SiO2.xyz\"),\n", - " (\"Silicon\", \"../miscellaneous/structures/Si.xyz\")\n", - " ]),\n", + " (\"Silicon\", \"../miscellaneous/structures/Si.xyz\"),\n", + " ],\n", + " ),\n", " ],\n", - " editors = [\n", + " editors=[\n", " awb.BasicStructureEditor(title=\"Basic Editor\"),\n", " awb.BasicCellEditor(title=\"Basic Cell Editor\"),\n", " ],\n", diff --git a/notebooks/viewers.ipynb b/notebooks/viewers.ipynb index 2d93bdb0b..2b1dc9826 100644 --- a/notebooks/viewers.ipynb +++ b/notebooks/viewers.ipynb @@ -7,7 +7,8 @@ "outputs": [], "source": [ "# Load the default AiiDA profile.\n", - "from aiida import orm, load_profile\n", + "from aiida import load_profile, orm\n", + "\n", "load_profile();" ] }, @@ -39,12 +40,14 @@ "source": [ "from aiidalab_widgets_base import viewer\n", "\n", - "p = orm.Dict(dict={\n", - " 'parameter 1' : 'some string',\n", - " 'parameter 2' : 2,\n", - " 'parameter 3' : 3.0,\n", - " 'parameter 4' : [1, 2, 3],\n", - "})\n", + "p = orm.Dict(\n", + " dict={\n", + " \"parameter 1\": \"some string\",\n", + " \"parameter 2\": 2,\n", + " \"parameter 3\": 3.0,\n", + " \"parameter 4\": [1, 2, 3],\n", + " }\n", + ")\n", "vwr = viewer(p.store(), downloadable=True)\n", "display(vwr)" ] @@ -67,14 +70,17 @@ "outputs": [], "source": [ "from aiida import orm\n", + "\n", "from aiidalab_widgets_base import AiidaNodeViewWidget\n", "\n", - "p = orm.Dict(dict={\n", - " 'parameter 1' : 'some string',\n", - " 'parameter 2' : 2,\n", - " 'parameter 3' : 3.0,\n", - " 'parameter 4' : [1, 2, 3],\n", - "})\n", + "p = orm.Dict(\n", + " dict={\n", + " \"parameter 1\": \"some string\",\n", + " \"parameter 2\": 2,\n", + " \"parameter 3\": 3.0,\n", + " \"parameter 4\": [1, 2, 3],\n", + " }\n", + ")\n", "wdgt = AiidaNodeViewWidget(node=p.store())\n", "display(wdgt)" ] @@ -96,10 +102,10 @@ "from aiida import plugins\n", "from ase.build import molecule\n", "\n", - "m = molecule('H2O')\n", + "m = molecule(\"H2O\")\n", "m.center(vacuum=2.0)\n", "\n", - "StructureData = plugins.DataFactory('core.structure')\n", + "StructureData = plugins.DataFactory(\"core.structure\")\n", "s = StructureData(ase=m)\n", "\n", "wdgt.node = s.store()" @@ -158,16 +164,19 @@ "metadata": {}, "outputs": [], "source": [ - "from aiidalab_widgets_base.viewers import DictViewer\n", "from aiida import plugins\n", "\n", - "Dict = plugins.DataFactory('core.dict')\n", - "p = Dict(dict={\n", - " 'Parameter' :'super long string '*4,\n", - " 'parameter 2' :'value 2',\n", - " 'parameter 3' : 1,\n", - " 'parameter 4' : 2,\n", - "})\n", + "from aiidalab_widgets_base.viewers import DictViewer\n", + "\n", + "Dict = plugins.DataFactory(\"core.dict\")\n", + "p = Dict(\n", + " dict={\n", + " \"Parameter\": \"super long string \" * 4,\n", + " \"parameter 2\": \"value 2\",\n", + " \"parameter 3\": 1,\n", + " \"parameter 4\": 2,\n", + " }\n", + ")\n", "vwr = DictViewer(p.store(), downloadable=True)\n", "display(vwr)" ] @@ -188,27 +197,27 @@ "metadata": {}, "outputs": [], "source": [ - "from ase.build import molecule, bulk\n", - "from aiidalab_widgets_base.viewers import StructureDataViewer\n", + "from ase.build import bulk, molecule\n", "\n", + "from aiidalab_widgets_base.viewers import StructureDataViewer\n", "\n", "# create bulk Pt\n", - "pt = bulk('Pt', cubic = True)\n", + "pt = bulk(\"Pt\", cubic=True)\n", "\n", "# Cif data.\n", - "CifData = plugins.DataFactory('core.cif')\n", + "CifData = plugins.DataFactory(\"core.cif\")\n", "s = CifData(ase=pt)\n", "vwr_cif = StructureDataViewer(s.store())\n", "display(vwr_cif)\n", "\n", "# Structure data.\n", - "m = molecule('H2O')\n", + "m = molecule(\"H2O\")\n", "m.center(vacuum=2.0)\n", "\n", - "StructureData = plugins.DataFactory('core.structure')\n", + "StructureData = plugins.DataFactory(\"core.structure\")\n", "s = StructureData(ase=m)\n", "vwr_structure = StructureDataViewer(s.store())\n", - "display(vwr_structure)\n" + "display(vwr_structure)" ] }, { @@ -229,42 +238,59 @@ "source": [ "import numpy as np\n", "from aiida import plugins\n", + "\n", "from aiidalab_widgets_base.viewers import BandsDataViewer\n", "\n", - "BandsData = plugins.DataFactory('core.array.bands')\n", + "BandsData = plugins.DataFactory(\"core.array.bands\")\n", "bs = BandsData()\n", - "kpoints = np.array([[0. , 0. , 0. ], # array shape is 12 * 3\n", - " [0.1 , 0. , 0.1 ],\n", - " [0.2 , 0. , 0.2 ],\n", - " [0.3 , 0. , 0.3 ],\n", - " [0.4 , 0. , 0.4 ],\n", - " [0.5 , 0. , 0.5 ],\n", - " [0.5 , 0. , 0.5 ],\n", - " [0.525 , 0.05 , 0.525 ],\n", - " [0.55 , 0.1 , 0.55 ],\n", - " [0.575 , 0.15 , 0.575 ],\n", - " [0.6 , 0.2 , 0.6 ],\n", - " [0.625 , 0.25 , 0.625 ]])\n", - "\n", - "bands = np.array([\n", - " [-5.64024889, 6.66929678, 6.66929678, 6.66929678, 8.91047649], # array shape is 12 * 5, where 12 is the size of the kpoints mesh\n", - " [-5.46976726, 5.76113772, 5.97844699, 5.97844699, 8.48186734], # and 5 is the number of states\n", - " [-4.93870761, 4.06179965, 4.97235487, 4.97235488, 7.68276008],\n", - " [-4.05318686, 2.21579935, 4.18048674, 4.18048675, 7.04145185],\n", - " [-2.83974972, 0.37738276, 3.69024464, 3.69024465, 6.75053465],\n", - " [-1.34041116, -1.34041115, 3.52500177, 3.52500178, 6.92381041],\n", - " [-1.34041116, -1.34041115, 3.52500177, 3.52500178, 6.92381041],\n", - " [-1.34599146, -1.31663872, 3.34867603, 3.54390139, 6.93928289],\n", - " [-1.36769345, -1.24523403, 2.94149041, 3.6004033 , 6.98809593],\n", - " [-1.42050683, -1.12604118, 2.48497007, 3.69389815, 7.07537154],\n", - " [-1.52788845, -0.95900776, 2.09104321, 3.82330632, 7.20537566],\n", - " [-1.71354964, -0.74425095, 1.82242466, 3.98697455, 7.37979746]])\n", + "kpoints = np.array(\n", + " [\n", + " [0.0, 0.0, 0.0], # array shape is 12 * 3\n", + " [0.1, 0.0, 0.1],\n", + " [0.2, 0.0, 0.2],\n", + " [0.3, 0.0, 0.3],\n", + " [0.4, 0.0, 0.4],\n", + " [0.5, 0.0, 0.5],\n", + " [0.5, 0.0, 0.5],\n", + " [0.525, 0.05, 0.525],\n", + " [0.55, 0.1, 0.55],\n", + " [0.575, 0.15, 0.575],\n", + " [0.6, 0.2, 0.6],\n", + " [0.625, 0.25, 0.625],\n", + " ]\n", + ")\n", + "\n", + "bands = np.array(\n", + " [\n", + " [\n", + " -5.64024889,\n", + " 6.66929678,\n", + " 6.66929678,\n", + " 6.66929678,\n", + " 8.91047649,\n", + " ], # array shape is 12 * 5, where 12 is the size of the kpoints mesh\n", + " [\n", + " -5.46976726,\n", + " 5.76113772,\n", + " 5.97844699,\n", + " 5.97844699,\n", + " 8.48186734,\n", + " ], # and 5 is the number of states\n", + " [-4.93870761, 4.06179965, 4.97235487, 4.97235488, 7.68276008],\n", + " [-4.05318686, 2.21579935, 4.18048674, 4.18048675, 7.04145185],\n", + " [-2.83974972, 0.37738276, 3.69024464, 3.69024465, 6.75053465],\n", + " [-1.34041116, -1.34041115, 3.52500177, 3.52500178, 6.92381041],\n", + " [-1.34041116, -1.34041115, 3.52500177, 3.52500178, 6.92381041],\n", + " [-1.34599146, -1.31663872, 3.34867603, 3.54390139, 6.93928289],\n", + " [-1.36769345, -1.24523403, 2.94149041, 3.6004033, 6.98809593],\n", + " [-1.42050683, -1.12604118, 2.48497007, 3.69389815, 7.07537154],\n", + " [-1.52788845, -0.95900776, 2.09104321, 3.82330632, 7.20537566],\n", + " [-1.71354964, -0.74425095, 1.82242466, 3.98697455, 7.37979746],\n", + " ]\n", + ")\n", "bs.set_kpoints(kpoints)\n", "bs.set_bands(bands)\n", - "labels = [(0, u'GAMMA'),\n", - " (5, u'X'),\n", - " (6, u'Z'),\n", - " (11, u'U')]\n", + "labels = [(0, \"GAMMA\"), (5, \"X\"), (6, \"Z\"), (11, \"U\")]\n", "bs.labels = labels\n", "\n", "\n", @@ -289,17 +315,17 @@ "outputs": [], "source": [ "import io\n", + "\n", "from aiida import plugins\n", - "from aiidalab_widgets_base.viewers import FolderDataViewer\n", "\n", - "FolderData = plugins.DataFactory('core.folder')\n", + "FolderData = plugins.DataFactory(\"core.folder\")\n", "fd = FolderData()\n", - "with io.StringIO('content of test1 file') as fobj:\n", - " fd.put_object_from_filelike(fobj, path='test1.txt')\n", - "with io.StringIO('content of test2 file') as fobj:\n", - " fd.put_object_from_filelike(fobj, path='test2.txt')\n", - "with io.StringIO(u'content of test_long file'*1000) as fobj:\n", - " fd.put_object_from_filelike(fobj, path='test_long.txt')\n", + "with io.StringIO(\"content of test1 file\") as fobj:\n", + " fd.put_object_from_filelike(fobj, path=\"test1.txt\")\n", + "with io.StringIO(\"content of test2 file\") as fobj:\n", + " fd.put_object_from_filelike(fobj, path=\"test2.txt\")\n", + "with io.StringIO(\"content of test_long file\" * 1000) as fobj:\n", + " fd.put_object_from_filelike(fobj, path=\"test_long.txt\")\n", "vwr = viewer(fd.store(), downloadable=True)\n", "display(vwr)" ] @@ -320,10 +346,14 @@ "metadata": {}, "outputs": [], "source": [ - "from aiida.workflows.arithmetic.add_multiply import add, add_multiply\n", "from aiida import engine, orm\n", + "from aiida.workflows.arithmetic.add_multiply import add, add_multiply\n", + "\n", "from aiidalab_widgets_base.viewers import ProcessNodeViewerWidget\n", - "result, workfunction = engine.run_get_node(add_multiply, orm.Int(3), orm.Int(4), orm.Int(5))\n", + "\n", + "result, workfunction = engine.run_get_node(\n", + " add_multiply, orm.Int(3), orm.Int(4), orm.Int(5)\n", + ")\n", "vwr_workfunction = ProcessNodeViewerWidget(workfunction)\n", "display(vwr_workfunction)\n", "\n", @@ -354,15 +384,17 @@ "metadata": {}, "outputs": [], "source": [ - "from aiidalab_widgets_base import register_viewer_widget\n", "import ipywidgets as ipw\n", - "from aiida.orm import Int\n", "\n", - "@register_viewer_widget('data.core.int.Int.')\n", + "from aiidalab_widgets_base import register_viewer_widget\n", + "\n", + "\n", + "@register_viewer_widget(\"data.core.int.Int.\")\n", "class IntViewerWidget(ipw.HTML):\n", " def __init__(self, node, **kwargs):\n", " super().__init__(**kwargs)\n", - " self.value = f'Int object: {node.value}'\n", + " self.value = f\"Int object: {node.value}\"\n", + "\n", "\n", "vwr = viewer(orm.Int(3).store())\n", "display(vwr)" diff --git a/notebooks/wizard_apps.ipynb b/notebooks/wizard_apps.ipynb index 1dcfc4606..c8a5fba9a 100644 --- a/notebooks/wizard_apps.ipynb +++ b/notebooks/wizard_apps.ipynb @@ -31,21 +31,25 @@ "source": [ "import enum\n", "import json\n", - "import time\n", "import threading\n", + "import time\n", "\n", - "import traitlets\n", "import ipywidgets as ipw\n", + "import traitlets\n", "\n", - "from aiidalab_widgets_base import WizardAppWidget\n", - "from aiidalab_widgets_base import WizardAppWidgetStep\n", - "\n", + "from aiidalab_widgets_base import WizardAppWidget, WizardAppWidgetStep\n", "\n", "OrderStatus = enum.Enum(\n", " \"OrderStatus\",\n", - " {\"init\": 0, \"in_preparation\": 40, \"in_transit\": 65, \"delivered\": 100, \"unavailable\": -1}\n", + " {\n", + " \"init\": 0,\n", + " \"in_preparation\": 40,\n", + " \"in_transit\": 65,\n", + " \"delivered\": 100,\n", + " \"unavailable\": -1,\n", + " },\n", ")\n", - " \n", + "\n", "\n", "class OrderTracker(traitlets.HasTraits):\n", " \"\"\"Helper class to keep track of our pizza order.\"\"\"\n", @@ -70,24 +74,25 @@ " self.status = OrderStatus.delivered\n", "\n", " threading.Thread(target=simulate_order).start()\n", - " \n", - " \n", + "\n", " @traitlets.default(\"status\")\n", " def _default_status(self):\n", " \"\"\"Initialize the initial (default) order status.\"\"\"\n", " return OrderStatus.init\n", - " \n", - " \n", + "\n", + "\n", "class OrderProgressWidget(ipw.HBox):\n", " \"\"\"Widget to nicely represent the order status.\"\"\"\n", - " \n", + "\n", " status = traitlets.Instance(OrderStatus)\n", "\n", " def __init__(self, **kwargs):\n", - " self._progress_bar = ipw.FloatProgress(style={\"description_width\": \"initial\"}, description=\"Delivery progress:\")\n", + " self._progress_bar = ipw.FloatProgress(\n", + " style={\"description_width\": \"initial\"}, description=\"Delivery progress:\"\n", + " )\n", " self._status_text = ipw.HTML()\n", " super().__init__([self._progress_bar, self._status_text], **kwargs)\n", - " \n", + "\n", " @traitlets.observe(\"status\")\n", " def _observe_status(self, change):\n", " with self.hold_trait_notifications():\n", @@ -99,7 +104,7 @@ " OrderStatus.delivered: \"Delivered! :)\",\n", " OrderStatus.unavailable: \"Your order is not available\",\n", " }.get(change[\"new\"], change[\"new\"].name)\n", - " \n", + "\n", " self._progress_bar.value = change[\"new\"].value\n", " self._progress_bar.bar_style = {\n", " OrderStatus.delivered: \"success\",\n", @@ -112,7 +117,6 @@ "\n", "\n", "class ConfigureOrderStep(ipw.HBox, WizardAppWidgetStep):\n", - "\n", " disabled = traitlets.Bool()\n", " configuration = traitlets.Dict(allow_none=True)\n", "\n", @@ -146,14 +150,17 @@ "\n", " def _confirm_configuration(self, button):\n", " \"Confirm the pizza configuration and expose as trait.\"\n", - " self.configuration = dict(style=self.style.value, toppings=self.toppings.value)\n", - " \n", + " self.configuration = {\n", + " \"style\": self.style.value,\n", + " \"toppings\": self.toppings.value,\n", + " }\n", + "\n", " def reset(self):\n", " with self.hold_trait_notifications():\n", " self.style.value = None\n", " self.toppings.value = []\n", " self.configuration = {}\n", - " \n", + "\n", " @traitlets.default(\"state\")\n", " def _default_state(self):\n", " return self.State.READY\n", @@ -183,7 +190,7 @@ " with self.hold_trait_notifications():\n", " self.disabled = change[\"new\"] == self.State.SUCCESS\n", " self.confirm_button.disabled = change[\"new\"] is not self.State.CONFIGURED\n", - " \n", + "\n", " @traitlets.observe(\"disabled\")\n", " def _observe_disabled(self, change):\n", " with self.hold_trait_notifications():\n", @@ -192,7 +199,6 @@ "\n", "\n", "class ReviewAndSubmitOrderStep(ipw.VBox, WizardAppWidgetStep):\n", - "\n", " # We use traitlets to connect the different steps.\n", " # Note that we can use dlinked transformations, they do not need to be of the same type.\n", " configuration = traitlets.Dict()\n", @@ -212,7 +218,7 @@ " self.observe(self._update_state, [\"configuration\", \"order\"])\n", "\n", " super().__init__([self.configuration_label, self.order_button], **kwargs)\n", - " \n", + "\n", " def reset(self):\n", " self.order = None\n", "\n", @@ -246,7 +252,6 @@ "\n", "\n", "class TrackOrderStep(ipw.VBox, WizardAppWidgetStep):\n", - "\n", " # We receive the order from the previous step and then display information about\n", " # its state in this widget.\n", " order = traitlets.Instance(OrderTracker, allow_none=True)\n", @@ -276,7 +281,6 @@ " else:\n", " self.state = self.State.INIT\n", "\n", - "\n", " def can_reset(self):\n", " \"Do not allow reset during active order processing.\"\n", " return self.state is not self.State.ACTIVE\n", @@ -284,7 +288,7 @@ " def _update_state(self, change=None):\n", " \"Update the step's state based on the order status configuration traits.\"\n", " new_status = change[\"new\"]\n", - " \n", + "\n", " if new_status in (OrderStatus.in_preparation, OrderStatus.in_transit):\n", " self.state = self.State.ACTIVE\n", " elif new_status is OrderStatus.delivered:\n",