emvecchi commited on
Commit
5f81ae2
·
verified ·
1 Parent(s): 3a4ea9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py CHANGED
@@ -445,6 +445,42 @@ def _is_default_value(f: Field, val):
445
  """Check if current value equals the default for this widget type."""
446
  return val == INPUT_FIELD_DEFAULT_VALUES.get(f.type)
447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
  def validate_current_page(fields: List[Field], index: int) -> bool:
449
  """
450
  Walk the field tree and verify mandatory inputs are filled.
@@ -586,6 +622,7 @@ def show_field(f: Field, index: int, data_collected):
586
  st.checkbox(f.title, key=f.name, value=False)
587
 
588
  case 'rupture_markers':
 
589
  render_rupture_markers_widget(index, rupture_choices)
590
 
591
  return
 
445
  """Check if current value equals the default for this widget type."""
446
  return val == INPUT_FIELD_DEFAULT_VALUES.get(f.type)
447
 
448
+ def prime_rupture_markers_from_saved(index: int, data_collected: dict | None):
449
+ """
450
+ Copy saved JSON values (rupture_marker_1, *_line_a, *_line_b) into
451
+ st.session_state keys used by the widget (…_{index}), and set the count.
452
+ Runs once per index to avoid clobbering user edits on reruns.
453
+ """
454
+ if not data_collected:
455
+ return
456
+
457
+ primed_flag = f"rupture_primed_{index}"
458
+ if st.session_state.get(primed_flag):
459
+ return # already restored for this page
460
+
461
+ slots = []
462
+ for i in range(1, MAX_RUPTURE_MARKERS + 1):
463
+ m = data_collected.get(f"rupture_marker_{i}")
464
+ a = data_collected.get(f"rupture_marker_{i}_line_a")
465
+ b = data_collected.get(f"rupture_marker_{i}_line_b")
466
+ if any(v is not None for v in (m, a, b)):
467
+ # widget's selectbox uses "" for "no selection"
468
+ slots.append(((m or ""), a, b))
469
+
470
+ if not slots:
471
+ return
472
+
473
+ # set widget count (at least 1, capped to MAX)
474
+ count_key = f"rupture_count_{index}"
475
+ st.session_state[count_key] = min(MAX_RUPTURE_MARKERS, max(1, len(slots)))
476
+
477
+ for i, (m, a, b) in enumerate(slots, start=1):
478
+ st.session_state[f"rupture_marker_{i}_{index}"] = m if m in rupture_choices else (m or "")
479
+ st.session_state[f"rupture_marker_{i}_line_a_{index}"] = a
480
+ st.session_state[f"rupture_marker_{i}_line_b_{index}"] = b
481
+
482
+ st.session_state[primed_flag] = True
483
+
484
  def validate_current_page(fields: List[Field], index: int) -> bool:
485
  """
486
  Walk the field tree and verify mandatory inputs are filled.
 
622
  st.checkbox(f.title, key=f.name, value=False)
623
 
624
  case 'rupture_markers':
625
+ prime_rupture_markers_from_saved(index, data_collected)
626
  render_rupture_markers_widget(index, rupture_choices)
627
 
628
  return