Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
"""
|
2 |
-
BuildSustain - Main Module
|
3 |
|
4 |
This is the main module for the BuildSustain application. It serves as the central
|
5 |
orchestrator for the application, handling navigation between different modules and managing
|
@@ -162,8 +162,9 @@ class BuildSustain:
|
|
162 |
if 'debug_mode' not in st.session_state:
|
163 |
st.session_state.debug_mode = False
|
164 |
|
165 |
-
|
166 |
-
|
|
|
167 |
|
168 |
def setup_layout(self):
|
169 |
"""
|
@@ -192,6 +193,9 @@ class BuildSustain:
|
|
192 |
"Materials Cost"
|
193 |
]
|
194 |
|
|
|
|
|
|
|
195 |
# Create the navigation radio buttons
|
196 |
selected_page = st.sidebar.radio(
|
197 |
"Go to",
|
@@ -202,10 +206,9 @@ class BuildSustain:
|
|
202 |
# Update the current page if changed
|
203 |
if selected_page != st.session_state.current_page:
|
204 |
st.session_state.current_page = selected_page
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
st.session_state.pop(key, None)
|
209 |
|
210 |
# Add application info to sidebar
|
211 |
st.sidebar.markdown("---")
|
@@ -231,10 +234,45 @@ class BuildSustain:
|
|
231 |
# Display the selected page content
|
232 |
self.display_page(st.session_state.current_page)
|
233 |
|
234 |
-
# Handle
|
235 |
-
|
236 |
-
|
237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
|
239 |
def display_page(self, page: str):
|
240 |
"""
|
|
|
1 |
"""
|
2 |
+
BuildSustain - Main Module (Fixed Version)
|
3 |
|
4 |
This is the main module for the BuildSustain application. It serves as the central
|
5 |
orchestrator for the application, handling navigation between different modules and managing
|
|
|
162 |
if 'debug_mode' not in st.session_state:
|
163 |
st.session_state.debug_mode = False
|
164 |
|
165 |
+
# Initialize module-specific rerun flags (for future modules that might need them)
|
166 |
+
if 'module_rerun_flags' not in st.session_state:
|
167 |
+
st.session_state.module_rerun_flags = {}
|
168 |
|
169 |
def setup_layout(self):
|
170 |
"""
|
|
|
193 |
"Materials Cost"
|
194 |
]
|
195 |
|
196 |
+
# Store previous page for comparison
|
197 |
+
previous_page = st.session_state.current_page
|
198 |
+
|
199 |
# Create the navigation radio buttons
|
200 |
selected_page = st.sidebar.radio(
|
201 |
"Go to",
|
|
|
206 |
# Update the current page if changed
|
207 |
if selected_page != st.session_state.current_page:
|
208 |
st.session_state.current_page = selected_page
|
209 |
+
|
210 |
+
# Clear module-specific states when leaving certain pages
|
211 |
+
self._handle_page_transition(previous_page, selected_page)
|
|
|
212 |
|
213 |
# Add application info to sidebar
|
214 |
st.sidebar.markdown("---")
|
|
|
234 |
# Display the selected page content
|
235 |
self.display_page(st.session_state.current_page)
|
236 |
|
237 |
+
# Handle module-specific reruns (only if needed by specific modules)
|
238 |
+
self._handle_module_reruns()
|
239 |
+
|
240 |
+
def _handle_page_transition(self, previous_page: str, new_page: str):
|
241 |
+
"""
|
242 |
+
Handle cleanup when transitioning between pages.
|
243 |
+
Only clear states that are specific to the page being left.
|
244 |
+
"""
|
245 |
+
# Clear materials library specific states when leaving that page
|
246 |
+
if previous_page == "Material Library":
|
247 |
+
# Only clear materials library editor states
|
248 |
+
keys_to_clear = [
|
249 |
+
"material_editor",
|
250 |
+
"fenestration_editor",
|
251 |
+
"material_saved",
|
252 |
+
"fenestration_saved"
|
253 |
+
]
|
254 |
+
for key in keys_to_clear:
|
255 |
+
if key in st.session_state:
|
256 |
+
st.session_state.pop(key, None)
|
257 |
+
|
258 |
+
# Add similar cleanup for other modules as needed
|
259 |
+
# This approach ensures each module's cleanup is isolated
|
260 |
+
|
261 |
+
# Clear any module-specific rerun flags when changing pages
|
262 |
+
st.session_state.module_rerun_flags = {}
|
263 |
+
|
264 |
+
def _handle_module_reruns(self):
|
265 |
+
"""
|
266 |
+
Handle module-specific rerun requests.
|
267 |
+
This allows modules to request reruns without interfering with each other.
|
268 |
+
"""
|
269 |
+
# Check for any module-specific rerun requests
|
270 |
+
for module_name, should_rerun in st.session_state.module_rerun_flags.items():
|
271 |
+
if should_rerun:
|
272 |
+
# Clear the flag and trigger rerun
|
273 |
+
st.session_state.module_rerun_flags[module_name] = False
|
274 |
+
st.rerun()
|
275 |
+
break # Only handle one rerun at a time
|
276 |
|
277 |
def display_page(self, page: str):
|
278 |
"""
|