Spaces:
Sleeping
Sleeping
Update app/materials_library.py
Browse files- app/materials_library.py +40 -5
app/materials_library.py
CHANGED
@@ -355,13 +355,47 @@ def get_stable_button_key(prefix: str, name: str, action: str, unique_id: str =
|
|
355 |
|
356 |
def initialize_session_state():
|
357 |
"""Initialize all required session state variables."""
|
|
|
358 |
if "project_data" not in st.session_state:
|
359 |
-
st.session_state.project_data = {
|
360 |
-
|
361 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
}
|
363 |
-
|
364 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
if "material_editor" not in st.session_state:
|
366 |
reset_material_editor()
|
367 |
if "fenestration_editor" not in st.session_state:
|
@@ -374,6 +408,7 @@ def initialize_session_state():
|
|
374 |
st.session_state.fenestration_action = {"action": None, "id": None}
|
375 |
if "current_page" not in st.session_state:
|
376 |
st.session_state.current_page = "Material Library"
|
|
|
377 |
logger.debug("Session state initialized")
|
378 |
logger.debug(f"Project materials: {list(st.session_state.project_data['materials']['project'].keys())}")
|
379 |
logger.debug(f"Project fenestrations: {list(st.session_state.project_data['fenestrations']['project'].keys())}")
|
|
|
355 |
|
356 |
def initialize_session_state():
|
357 |
"""Initialize all required session state variables."""
|
358 |
+
# Ensure project_data exists
|
359 |
if "project_data" not in st.session_state:
|
360 |
+
st.session_state.project_data = {}
|
361 |
+
|
362 |
+
# Ensure materials structure is fully initialized
|
363 |
+
if "materials" not in st.session_state.project_data:
|
364 |
+
st.session_state.project_data["materials"] = {
|
365 |
+
"library": DEFAULT_MATERIALS.copy(),
|
366 |
+
"project": {},
|
367 |
+
"table": None
|
368 |
+
}
|
369 |
+
else:
|
370 |
+
# Ensure all required keys exist in materials
|
371 |
+
if "library" not in st.session_state.project_data["materials"]:
|
372 |
+
st.session_state.project_data["materials"]["library"] = DEFAULT_MATERIALS.copy()
|
373 |
+
if "project" not in st.session_state.project_data["materials"]:
|
374 |
+
st.session_state.project_data["materials"]["project"] = {}
|
375 |
+
if "table" not in st.session_state.project_data["materials"]:
|
376 |
+
st.session_state.project_data["materials"]["table"] = None
|
377 |
+
|
378 |
+
# Ensure fenestrations structure is fully initialized
|
379 |
+
if "fenestrations" not in st.session_state.project_data:
|
380 |
+
st.session_state.project_data["fenestrations"] = {
|
381 |
+
"library": DEFAULT_FENESTRATIONS.copy(),
|
382 |
+
"project": {},
|
383 |
+
"table": None
|
384 |
}
|
385 |
+
else:
|
386 |
+
# Ensure all required keys exist in fenestrations
|
387 |
+
if "library" not in st.session_state.project_data["fenestrations"]:
|
388 |
+
st.session_state.project_data["fenestrations"]["library"] = DEFAULT_FENESTRATIONS.copy()
|
389 |
+
if "project" not in st.session_state.project_data["fenestrations"]:
|
390 |
+
st.session_state.project_data["fenestrations"]["project"] = {}
|
391 |
+
if "table" not in st.session_state.project_data["fenestrations"]:
|
392 |
+
st.session_state.project_data["fenestrations"]["table"] = None
|
393 |
+
|
394 |
+
# Initialize tables if they are None
|
395 |
+
update_project_materials_table()
|
396 |
+
update_project_fenestrations_table()
|
397 |
+
|
398 |
+
# Initialize other session state variables
|
399 |
if "material_editor" not in st.session_state:
|
400 |
reset_material_editor()
|
401 |
if "fenestration_editor" not in st.session_state:
|
|
|
408 |
st.session_state.fenestration_action = {"action": None, "id": None}
|
409 |
if "current_page" not in st.session_state:
|
410 |
st.session_state.current_page = "Material Library"
|
411 |
+
|
412 |
logger.debug("Session state initialized")
|
413 |
logger.debug(f"Project materials: {list(st.session_state.project_data['materials']['project'].keys())}")
|
414 |
logger.debug(f"Project fenestrations: {list(st.session_state.project_data['fenestrations']['project'].keys())}")
|