Tyycha commited on
Commit
b167476
·
1 Parent(s): ea58224

fix: db switcher — vertical radio, no default selection

Browse files
Files changed (1) hide show
  1. streamlit_app.py +15 -45
streamlit_app.py CHANGED
@@ -78,40 +78,14 @@ st.markdown("""
78
  .status-ok { color: #3fb950; font-size: 13px; font-weight: 600; }
79
  .status-err { color: #f85149; font-size: 13px; font-weight: 600; }
80
 
81
- /* ── DB-переключатель: стилизуем radio как сегментированные кнопки ── */
82
- div[data-testid="stRadio"] > label { display: none; }
83
  div[data-testid="stRadio"] > div {
84
- display: flex;
85
- gap: 0;
86
- border: 1px solid #30363d;
87
- border-radius: 8px;
88
- overflow: hidden;
89
- background: #0d1117;
90
  }
91
  div[data-testid="stRadio"] > div > label {
92
- flex: 1;
93
- display: flex !important;
94
- align-items: center;
95
- justify-content: center;
96
- padding: 8px 4px;
97
- font-size: 12px;
98
- font-weight: 500;
99
- color: #7d8590;
100
- cursor: pointer;
101
- border-right: 1px solid #30363d;
102
- transition: background 0.15s, color 0.15s;
103
- text-align: center;
104
- }
105
- div[data-testid="stRadio"] > div > label:last-child { border-right: none; }
106
- div[data-testid="stRadio"] > div > label:has(input:checked) {
107
- background: #21262d;
108
- color: #e6edf3;
109
- }
110
- div[data-testid="stRadio"] > div > label:hover:not(:has(input:checked)) {
111
- background: #161b22;
112
- color: #c9d1d9;
113
  }
114
- div[data-testid="stRadio"] > div > label > div:first-child { display: none; }
115
 
116
  /* ── Кнопка словаря ── */
117
  .vocab-status {
@@ -224,7 +198,7 @@ def _init_state():
224
  "vocabulary": None,
225
  "db_connection_string": "",
226
  "vocab_yaml": _default_vocab_yaml(),
227
- "db_mode": "Демо-база",
228
  }
229
  for k, v in defaults.items():
230
  if k not in st.session_state:
@@ -341,14 +315,18 @@ with st.sidebar:
341
  # ── База данных ──
342
  st.markdown('<p class="sb-label">База данных</p>', unsafe_allow_html=True)
343
 
 
 
344
  db_mode = st.radio(
345
- "db_mode",
346
- ["Демо-база", "Загрузить файл", "Строка подключения"],
347
- horizontal=True,
348
- index=["Демо-база", "Загрузить файл", "Строка подключения"].index(
349
- st.session_state.db_mode
350
- ),
351
  )
 
 
 
 
352
  st.session_state.db_mode = db_mode
353
 
354
  cs = ""
@@ -435,14 +413,6 @@ with st.sidebar:
435
  vocab_dialog()
436
 
437
 
438
- # ──────────────────────────────────────────────
439
- # Автоподключение демо-базы при первом запуске
440
- # ──────────────────────────────────────────────
441
- if (
442
- st.session_state.db_mode == "Демо-база"
443
- and st.session_state.db_connector is None
444
- ):
445
- _auto_connect_demo()
446
 
447
 
448
  # ──────────────────────────────────────────────
 
78
  .status-ok { color: #3fb950; font-size: 13px; font-weight: 600; }
79
  .status-err { color: #f85149; font-size: 13px; font-weight: 600; }
80
 
81
+ /* ── DB-переключатель ── */
 
82
  div[data-testid="stRadio"] > div {
83
+ gap: 4px;
 
 
 
 
 
84
  }
85
  div[data-testid="stRadio"] > div > label {
86
+ font-size: 14px;
87
+ padding: 4px 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  }
 
89
 
90
  /* ── Кнопка словаря ── */
91
  .vocab-status {
 
198
  "vocabulary": None,
199
  "db_connection_string": "",
200
  "vocab_yaml": _default_vocab_yaml(),
201
+ "db_mode": None,
202
  }
203
  for k, v in defaults.items():
204
  if k not in st.session_state:
 
315
  # ── База данных ──
316
  st.markdown('<p class="sb-label">База данных</p>', unsafe_allow_html=True)
317
 
318
+ _modes = ["Демо-база", "Загрузить файл", "Строка подключения"]
319
+ _prev = st.session_state.db_mode
320
  db_mode = st.radio(
321
+ "Источник данных",
322
+ _modes,
323
+ index=_modes.index(_prev) if _prev in _modes else None,
324
+ label_visibility="collapsed",
 
 
325
  )
326
+ if db_mode != _prev:
327
+ # При смене режима сбрасываем подключение
328
+ st.session_state.db_connector = None
329
+ st.session_state.db_executor = None
330
  st.session_state.db_mode = db_mode
331
 
332
  cs = ""
 
413
  vocab_dialog()
414
 
415
 
 
 
 
 
 
 
 
 
416
 
417
 
418
  # ──────────────────────────────────────────────