Skip to content
Open
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
43 changes: 42 additions & 1 deletion src/epicc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from epicc.model.base import BaseSimulationModel
from epicc.model.models import get_all_models
from epicc.ui.editor import render_model_editor
from epicc.ui.export import (
render_parameter_export_modal,
render_pdf_export_button,
Expand Down Expand Up @@ -40,12 +41,13 @@
model_registry: dict[str, BaseSimulationModel] = {m.human_name(): m for m in all_models}
model_registry.update(get_custom_models())

_EDITOR_MODE_KEY = "epicc_editor_mode"
_MODEL_SELECT_KEY = "model_selector"
pending_label = consume_pending_model_selection()
if pending_label is not None and pending_label in model_registry:
st.session_state[_MODEL_SELECT_KEY] = pending_label

hdr_title, hdr_right = st.columns([3, 3])
hdr_title, hdr_right, hdr_editor = st.columns([3, 3, 1])
hdr_title.title("EPICC Cost Calculator")

with hdr_right:
Expand All @@ -60,9 +62,33 @@
)
render_load_model_button(container=col_load)

in_editor = bool(st.session_state.get(_EDITOR_MODE_KEY))
btn_label = "Abort to Calculator" if in_editor else "Open Model Editor"
if hdr_editor.button(
btn_label,
use_container_width=True,
key="open_editor_btn",
):
if in_editor:
st.session_state.pop(_EDITOR_MODE_KEY, None)
else:
st.session_state[_EDITOR_MODE_KEY] = True
st.rerun()

st.divider()

if selected_label is None:
if in_editor:
def _close_editor() -> None:
st.session_state.pop(_EDITOR_MODE_KEY, None)

render_model_editor(
initial_doc=None,
source_label=None,
on_close=_close_editor,
)
st.stop()

st.markdown(
"""
## Welcome to EPICC
Expand Down Expand Up @@ -106,6 +132,21 @@

active_model = model_registry[selected_label]
assert selected_label is not None # Type narrowing for mypy

if st.session_state.get(_EDITOR_MODE_KEY):
model_def = active_model.get_model_definition()
initial_doc = model_def.model_dump(mode="json", by_alias=True)

def _close_editor() -> None:
st.session_state.pop(_EDITOR_MODE_KEY, None)

render_model_editor(
initial_doc=initial_doc,
source_label=selected_label,
on_close=_close_editor,
)
st.stop()

params = sync_active_model(selected_label)

param_col, result_col = st.columns([2, 3], gap="large")
Expand Down
Loading
Loading