duongthienz commited on
Commit
3f88b7e
·
verified ·
1 Parent(s): c18c8f8

Update ui.py

Browse files
Files changed (1) hide show
  1. ui.py +26 -24
ui.py CHANGED
@@ -145,7 +145,7 @@ def render_data_table(tableDF, speakerNames, raw_to_display, currFile):
145
  # ---------------------------------------------------------------------------
146
 
147
  def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
148
- """Render a table: Speaker (with inline ✎ rename + history dropdown) | Audio Sample | ↺ button."""
149
  file_samples = st.session_state.speakerClips.get(currFile, {})
150
  has_waveform = currFile in st.session_state.speakerWaveforms
151
  has_samples = bool(file_samples)
@@ -174,7 +174,6 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
174
 
175
  # --- Speaker cell ---
176
  if is_editing:
177
- select_key = f"inline_rename_select_{currFile}_{sp}"
178
  input_key = f"inline_rename_input_{currFile}_{sp}"
179
  confirm_key = f"inline_rename_confirm_{currFile}_{sp}"
180
  cancel_key = f"inline_rename_cancel_{currFile}_{sp}"
@@ -182,30 +181,31 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
182
  history = st.session_state.inline_rename_history
183
  current_val = display_name if display_name != sp else ""
184
 
 
 
 
 
185
  with row_cols[0]:
 
 
 
 
 
 
 
 
186
  if history:
187
- # Selectbox with index=None shows placeholder and lets user
188
- # type to filter — single combined widget, no separate input.
189
- options = history
190
- default_idx = history.index(current_val) if current_val in history else None
191
- chosen = st.selectbox(
192
- "Rename",
193
- options=options,
194
- index=default_idx,
195
- key=select_key,
196
- label_visibility="collapsed",
197
- placeholder="Type or select a name…",
198
- )
199
- new_name = chosen or ""
200
- else:
201
- # No history yet — plain text input
202
- new_name = st.text_input(
203
- "Rename",
204
- value=current_val,
205
- key=input_key,
206
- label_visibility="collapsed",
207
- placeholder=f"Rename {sp}…",
208
- )
209
 
210
  btn_col1, btn_col2 = st.columns(2)
211
  if btn_col1.button("✓", key=confirm_key, help="Confirm rename"):
@@ -215,9 +215,11 @@ def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
215
  if confirmed not in st.session_state.inline_rename_history:
216
  st.session_state.inline_rename_history.append(confirmed)
217
  st.session_state.inline_rename_active[edit_key] = False
 
218
  st.rerun()
219
  if btn_col2.button("✕", key=cancel_key, help="Cancel"):
220
  st.session_state.inline_rename_active[edit_key] = False
 
221
  st.rerun()
222
  else:
223
  with row_cols[0]:
 
145
  # ---------------------------------------------------------------------------
146
 
147
  def render_speaker_samples_tab(speakerNames, raw_to_display, currFile):
148
+ """Render a table: Speaker (with inline ✎ rename + history fill) | Audio Sample | ↺ button."""
149
  file_samples = st.session_state.speakerClips.get(currFile, {})
150
  has_waveform = currFile in st.session_state.speakerWaveforms
151
  has_samples = bool(file_samples)
 
174
 
175
  # --- Speaker cell ---
176
  if is_editing:
 
177
  input_key = f"inline_rename_input_{currFile}_{sp}"
178
  confirm_key = f"inline_rename_confirm_{currFile}_{sp}"
179
  cancel_key = f"inline_rename_cancel_{currFile}_{sp}"
 
181
  history = st.session_state.inline_rename_history
182
  current_val = display_name if display_name != sp else ""
183
 
184
+ # Seed initial value when first opening the input
185
+ if input_key not in st.session_state:
186
+ st.session_state[input_key] = current_val
187
+
188
  with row_cols[0]:
189
+ new_name = st.text_input(
190
+ "Rename",
191
+ key=input_key,
192
+ label_visibility="collapsed",
193
+ placeholder=f"Rename {sp}…",
194
+ )
195
+
196
+ # History pills — clicking one writes into the input key and reruns
197
  if history:
198
+ st.caption("Quick fill:")
199
+ pill_cols = st.columns(min(len(history), 4))
200
+ for hi, past_name in enumerate(history):
201
+ col_idx = hi % 4
202
+ if pill_cols[col_idx].button(
203
+ past_name,
204
+ key=f"inline_fill_{currFile}_{sp}_{hi}",
205
+ use_container_width=True,
206
+ ):
207
+ st.session_state[input_key] = past_name
208
+ st.rerun()
 
 
 
 
 
 
 
 
 
 
 
209
 
210
  btn_col1, btn_col2 = st.columns(2)
211
  if btn_col1.button("✓", key=confirm_key, help="Confirm rename"):
 
215
  if confirmed not in st.session_state.inline_rename_history:
216
  st.session_state.inline_rename_history.append(confirmed)
217
  st.session_state.inline_rename_active[edit_key] = False
218
+ st.session_state.pop(input_key, None)
219
  st.rerun()
220
  if btn_col2.button("✕", key=cancel_key, help="Cancel"):
221
  st.session_state.inline_rename_active[edit_key] = False
222
+ st.session_state.pop(input_key, None)
223
  st.rerun()
224
  else:
225
  with row_cols[0]: