Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/toad/widgets/comms_command_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ def bind_control(self):
self.paint()

def paint(self):
self.label = next((choice.name for choice in self.field.metadata(PreparedChoices).parameter.options
if choice.value == self.field.value), 'Choose / connect a provider…')
parameter = self.field.metadata(PreparedChoices).parameter
current = parameter.choice_value(self.field.value)
self.label = next((choice.name for choice in parameter.options
if choice.value == current), 'Choose / connect a provider…')

@on(Button.Pressed)
def on_button_pressed(self, event: Button.Pressed):
Expand All @@ -86,7 +88,7 @@ def on_button_pressed(self, event: Button.Pressed):
async def choose(self):
value = await self.app.push_screen_wait(CatalogChoiceDialog(self))
if value is not None and self.is_attached:
self.send(value)
self.send(self.field.metadata(PreparedChoices).parameter.editor_value(value))


class CatalogFieldSelection(ModelSelection):
Expand All @@ -96,11 +98,12 @@ def __init__(self, editor: CatalogField):

@property
def choices(self):
return self.editor.field.metadata(PreparedChoices).parameter.options
return tuple(choice for choice in self.editor.field.metadata(PreparedChoices).parameter.options
if choice.value is not None)

@property
def current(self):
return self.editor.field.value
return self.editor.field.metadata(PreparedChoices).parameter.choice_value(self.editor.field.value)

@property
def selection_active(self):
Expand Down
7 changes: 6 additions & 1 deletion tests/textual/test_application_actions_in_the_running_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Textual-facing: application actions (help, settings screen, command palette, sidebar buttons, tab close) run through Textual screens and keep the session, its draft and the saved settings."""
from agent_comms.nominal.field_codec import FieldCodec
from toad.forms.editors import ChoicesEditor
from toad.launch_binding import AgentAttached

Expand All @@ -15,7 +16,7 @@
from toad.preferences import SETTINGS
from toad.screens.keymap import KeymapScreen
from toad.screens.settings import SettingsScreen
from toad.widgets.comms_command_dialog import CatalogField
from toad.widgets.comms_command_dialog import CatalogField, CatalogFieldSelection
from toad.widgets.comms_sidebar import CommsSidebar, NewSessionButton
from toad.widgets.footer import ToadFooter
from toad.widgets.session_tabs import SessionTabClose
Expand Down Expand Up @@ -175,6 +176,10 @@ def call(self, request):
assert isinstance(dialog.form.values["thinking_level"].editor, ChoicesEditor)
released.set()
await ui.until(lambda: not CommandPreparation.running_on(dialog), why="the real catalogs to arrive")
selection = CatalogFieldSelection(dialog.form.values['model'].editor)
parameter = dialog.choices['model'].parameter
assert selection.current == FieldCodec.encode(parameter.value)
assert selection.choices == tuple(choice for choice in parameter.options if choice.value is not None)
button = dialog.query_one(ApplyCommandButton)
await ui.until(lambda: not button.disabled, why="the command values to be accepted")
editor = dialog.form.values["name"].editor
Expand Down
Loading