File size: 10,832 Bytes
b0eb8e1 8e4018d b0eb8e1 8e4018d b0eb8e1 8e4018d b0eb8e1 8e4018d b0eb8e1 8e4018d b0eb8e1 8e4018d b0eb8e1 8e4018d b0eb8e1 8e4018d b0eb8e1 8e4018d b0eb8e1 8e4018d b0eb8e1 8e4018d b0eb8e1 8e4018d b0eb8e1 8e4018d b0eb8e1 8e4018d b0eb8e1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
import streamlit as st
from datetime import datetime
from utils.config import load_config, save_config, reset_config, AppConfig
from utils.storage import get_storage_info, clear_storage, list_keys
from utils.error_handling import handle_ui_exceptions
from utils.logging import get_logger
logger = get_logger(__name__)
@handle_ui_exceptions
def create_settings_page():
"""Create the settings page"""
st.title("βοΈ Settings")
st.write("Configure your MONA dashboard preferences and system settings.")
# Create tabs for different settings categories
tab1, tab2, tab3, tab4 = st.tabs(["General", "Display", "Data", "System"])
with tab1:
create_general_settings()
with tab2:
create_display_settings()
with tab3:
create_data_settings()
with tab4:
create_system_settings()
@handle_ui_exceptions
def create_general_settings():
"""Create general settings section"""
st.header("π§ General Settings")
config = load_config()
# Application settings
with st.form("general_settings_form"):
st.subheader("Application Configuration")
app_name = st.text_input("Application Name", value=config.app_name)
version = st.text_input("Version", value=config.version, disabled=True)
debug_mode = st.checkbox("Debug Mode", value=config.debug_mode)
st.subheader("Performance Settings")
max_data_points = st.number_input(
"Maximum Data Points",
min_value=100,
max_value=10000,
value=config.max_data_points,
step=100
)
refresh_interval = st.number_input(
"Refresh Interval (seconds)",
min_value=1,
max_value=300,
value=config.refresh_interval,
step=1
)
if st.form_submit_button("Save General Settings"):
config.app_name = app_name
config.debug_mode = debug_mode
config.max_data_points = max_data_points
config.refresh_interval = refresh_interval
if save_config(config):
st.success("General settings saved successfully!")
st.rerun()
else:
st.error("Failed to save general settings.")
@handle_ui_exceptions
def create_display_settings():
"""Create display settings section"""
st.header("π¨ Display Settings")
config = load_config()
with st.form("display_settings_form"):
st.subheader("Theme & Appearance")
theme = st.selectbox(
"Theme",
options=["light", "dark"],
index=0 if config.theme == "light" else 1
)
default_chart_type = st.selectbox(
"Default Chart Type",
options=["line", "bar", "scatter", "area"],
index=["line", "bar", "scatter", "area"].index(config.default_chart_type)
)
st.subheader("Layout Settings")
sidebar_width = st.slider(
"Sidebar Width (px)",
min_value=200,
max_value=500,
value=config.sidebar_width,
step=10
)
chart_height = st.slider(
"Default Chart Height (px)",
min_value=300,
max_value=800,
value=config.chart_height,
step=50
)
table_page_size = st.number_input(
"Table Page Size",
min_value=10,
max_value=200,
value=config.table_page_size,
step=10
)
if st.form_submit_button("Save Display Settings"):
config.theme = theme
config.default_chart_type = default_chart_type
config.sidebar_width = sidebar_width
config.chart_height = chart_height
config.table_page_size = table_page_size
if save_config(config):
st.success("Display settings saved successfully!")
st.rerun()
else:
st.error("Failed to save display settings.")
@handle_ui_exceptions
def create_data_settings():
"""Create data settings section"""
st.header("π Data Settings")
config = load_config()
with st.form("data_settings_form"):
st.subheader("Data Processing")
data_cache_timeout = st.number_input(
"Data Cache Timeout (seconds)",
min_value=60,
max_value=3600,
value=config.data_cache_timeout,
step=60
)
max_file_size_mb = st.number_input(
"Maximum File Size (MB)",
min_value=1,
max_value=100,
value=config.max_file_size_mb,
step=1
)
st.subheader("Supported File Types")
current_types = config.supported_file_types or ['.csv', '.xlsx', '.json', '.parquet']
col1, col2 = st.columns(2)
with col1:
csv_support = st.checkbox("CSV Files (.csv)", value='.csv' in current_types)
xlsx_support = st.checkbox("Excel Files (.xlsx)", value='.xlsx' in current_types)
with col2:
json_support = st.checkbox("JSON Files (.json)", value='.json' in current_types)
parquet_support = st.checkbox("Parquet Files (.parquet)", value='.parquet' in current_types)
if st.form_submit_button("Save Data Settings"):
supported_types = []
if csv_support:
supported_types.append('.csv')
if xlsx_support:
supported_types.append('.xlsx')
if json_support:
supported_types.append('.json')
if parquet_support:
supported_types.append('.parquet')
config.data_cache_timeout = data_cache_timeout
config.max_file_size_mb = max_file_size_mb
config.supported_file_types = supported_types
if save_config(config):
st.success("Data settings saved successfully!")
st.rerun()
else:
st.error("Failed to save data settings.")
# Data management section
st.subheader("π Data Management")
col1, col2 = st.columns(2)
with col1:
st.write("**Memory Storage**")
memory_info = get_storage_info("memory")
st.write(f"Keys stored: {memory_info['total_keys']}")
if st.button("Clear Memory Storage", type="secondary"):
if clear_storage("memory"):
st.success("Memory storage cleared!")
st.rerun()
else:
st.error("Failed to clear memory storage.")
with col2:
st.write("**Session Storage**")
session_info = get_storage_info("session")
st.write(f"Keys stored: {session_info['total_keys']}")
if st.button("Clear Session Storage", type="secondary"):
if clear_storage("session"):
st.success("Session storage cleared!")
st.rerun()
else:
st.error("Failed to clear session storage.")
# Show stored data keys
with st.expander("View Stored Data Keys"):
memory_keys = list_keys("memory")
session_keys = list_keys("session")
col1, col2 = st.columns(2)
with col1:
st.write("**Memory Keys:**")
for key in memory_keys:
st.write(f"- {key}")
with col2:
st.write("**Session Keys:**")
for key in session_keys:
st.write(f"- {key}")
@handle_ui_exceptions
def create_system_settings():
"""Create system settings section"""
st.header("π§ System Settings")
# System information
st.subheader("π System Information")
col1, col2 = st.columns(2)
with col1:
st.write("**Application Info:**")
config = load_config()
st.write(f"- Name: {config.app_name}")
st.write(f"- Version: {config.version}")
st.write(f"- Debug Mode: {'Enabled' if config.debug_mode else 'Disabled'}")
with col2:
st.write("**Runtime Info:**")
st.write(f"- Current Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
st.write(f"- Streamlit Version: {st.__version__}")
st.write("- Python Version: 3.8+")
# Configuration management
st.subheader("βοΈ Configuration Management")
col1, col2, col3 = st.columns(3)
with col1:
if st.button("Export Configuration", type="secondary"):
config_dict = config.__dict__
st.download_button(
label="Download Config",
data=str(config_dict),
file_name=f"mona_config_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt",
mime="text/plain"
)
with col2:
if st.button("Reset to Defaults", type="secondary"):
if st.session_state.get('confirm_reset', False):
reset_config()
st.success("Configuration reset to defaults!")
st.session_state['confirm_reset'] = False
st.rerun()
else:
st.session_state['confirm_reset'] = True
st.warning("Click again to confirm reset.")
with col3:
if st.button("Reload Configuration", type="secondary"):
# Force reload by clearing the global config
from utils.config import _config
if '_config' in globals():
globals()['_config'] = None
st.success("Configuration reloaded!")
st.rerun()
# Advanced settings
with st.expander("π§ Advanced Settings"):
st.subheader("Developer Options")
if config.debug_mode:
st.write("**Debug Information:**")
st.json(config.__dict__)
if st.button("View Session State"):
st.write("**Session State:**")
st.json(dict(st.session_state))
else:
st.info("Enable Debug Mode in General Settings to access developer options.")
# System actions
st.subheader("π System Actions")
col1, col2 = st.columns(2)
with col1:
if st.button("Clear All Cache", type="secondary"):
st.cache_data.clear()
st.success("All cache cleared!")
with col2:
if st.button("Restart Application", type="primary"):
st.info("Application will restart...")
st.rerun() |