Skip to content

Commit 7249a8f

Browse files
committed
settings: await remove_children/mount to fix duplicate widget ID errors
Textual is inherently `async`, so removal of elements requires awaiting on the result. Without this, it is a race to add back widgets with duplicate IDs back into the widget tree. Await on removal to avoid the race. Co-authored-by: GitHub Copilot (claude-opus-4.6)
1 parent 99a2bbb commit 7249a8f

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

meeting_notes/settings.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -604,14 +604,14 @@ def render_editor_section(self) -> list:
604604

605605
return widgets
606606

607-
def on_button_pressed(self, event: Button.Pressed) -> None:
607+
async def on_button_pressed(self, event: Button.Pressed) -> None:
608608
"""Handle button presses."""
609609
button_id = event.button.id
610610

611611
# Section navigation
612612
if button_id and button_id.startswith("section-"):
613613
section = button_id.split("-")[1]
614-
self.switch_section(section)
614+
await self.switch_section(section)
615615

616616
# Provider selection
617617
elif button_id and button_id.startswith("provider-"):
@@ -626,20 +626,20 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
626626
self.config["ai_model"] = "balanced"
627627
elif event.button.provider_id == "local":
628628
self.config["ai_model"] = self.config.get("ollama_model", "llama3.2:3b")
629-
self.refresh_content()
629+
await self.refresh_content()
630630

631631
# AI model selection (for cloud providers)
632632
elif button_id and button_id.startswith("aimodel-"):
633633
if hasattr(event.button, 'model_id'):
634634
self.config["ai_model"] = event.button.model_id
635-
self.refresh_content()
635+
await self.refresh_content()
636636

637637
# Ollama model selection (for local provider)
638638
elif button_id and button_id.startswith("model-"):
639639
if hasattr(event.button, 'model_name'):
640640
self.config["ollama_model"] = event.button.model_name
641641
self.config["ai_model"] = event.button.model_name # Sync ai_model
642-
self.refresh_content()
642+
await self.refresh_content()
643643

644644
# Install model
645645
elif button_id == "install-model-button":
@@ -651,7 +651,7 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
651651
elif button_id == "cancel-button":
652652
self.action_cancel()
653653

654-
def switch_section(self, section: str) -> None:
654+
async def switch_section(self, section: str) -> None:
655655
"""Switch to a different settings section."""
656656
self.current_section = section
657657

@@ -662,12 +662,12 @@ def switch_section(self, section: str) -> None:
662662
else:
663663
item.remove_class("-active")
664664

665-
self.refresh_content()
665+
await self.refresh_content()
666666

667-
def refresh_content(self) -> None:
667+
async def refresh_content(self) -> None:
668668
"""Refresh the content area based on current section."""
669669
content = self.query_one("#settings-content", ScrollableContainer)
670-
content.remove_children()
670+
await content.remove_children()
671671

672672
# Render appropriate section
673673
if self.current_section == "ai":
@@ -683,7 +683,7 @@ def refresh_content(self) -> None:
683683

684684
# Mount all widgets (buttons are now in fixed footer, not here)
685685
for widget in widgets:
686-
content.mount(widget)
686+
await content.mount(widget)
687687

688688
def action_install_model(self) -> None:
689689
"""Open the install model dialog."""
@@ -699,12 +699,12 @@ def handle_install_model(self, model_name: Optional[str]) -> None:
699699
# Show installing screen
700700
self.app.push_screen(InstallingModelScreen(model_name), self.handle_installation_complete)
701701

702-
def handle_installation_complete(self, success: bool) -> None:
702+
async def handle_installation_complete(self, success: bool) -> None:
703703
"""Handle completion of model installation."""
704704
if success:
705705
self.app.notify("✓ Model installed successfully!", severity="information")
706706
# Refresh the content to show new model
707-
self.refresh_content()
707+
await self.refresh_content()
708708
else:
709709
self.app.notify("✗ Model installation failed", severity="error")
710710

0 commit comments

Comments
 (0)