Skip to content

trading_agent.terminal.widgets.desk_picker

A dialog listing the desks, for switching the chat to another one.

It returns the chosen desk's name, or None when the user presses Escape.

Typical usage example:

app.push_screen(DeskPicker(desks, 'general'), on_chosen)

DeskPicker

DeskPicker(desks, current)

Bases: ModalScreen[str | None]

The desk list.

Creates the dialog.

Parameters:

Name Type Description Default
desks list[dict[str, Any]]

The desk summaries from GET /api/desks.

required
current str

The desk the chat shows now.

required
Source code in src/trading_agent/terminal/widgets/desk_picker.py
def __init__(self, desks: list[dict[str, Any]], current: str):
    """Creates the dialog.

    Args:
        desks (list[dict[str, Any]]): The desk summaries from GET /api/desks.
        current (str): The desk the chat shows now.
    """
    super().__init__(classes='picker-screen')
    self._desks = desks
    self._current = current

compose

compose()

Builds the dialog.

Yields:

Type Description
Widget

The title and the list.

Source code in src/trading_agent/terminal/widgets/desk_picker.py
def compose(self):
    """Builds the dialog.

    Yields:
        Widget: The title and the list.
    """
    with containers.Vertical(classes='picker'):
        yield widgets.Static('[b]Switch desk[/b]', classes='picker-title')
        options = []
        for desk in self._desks:
            options.append(option_list.Option(self._label(desk)))
        yield widgets.OptionList(*options, id='desk-options')
        yield widgets.Static(
            '[dim]↑↓ to move · enter to choose · esc to close[/dim]',
            classes='picker-hint',
        )

on_mount

on_mount()

Highlights the current desk.

Source code in src/trading_agent/terminal/widgets/desk_picker.py
def on_mount(self) -> None:
    """Highlights the current desk."""
    options = self.query_one('#desk-options', widgets.OptionList)
    for index, desk in enumerate(self._desks):
        if desk['name'] == self._current:
            options.highlighted = index
    options.focus()

on_option_list_option_selected

on_option_list_option_selected(event)

Returns the chosen desk.

Parameters:

Name Type Description Default
event OptionSelected

The choice.

required
Source code in src/trading_agent/terminal/widgets/desk_picker.py
def on_option_list_option_selected(
    self, event: widgets.OptionList.OptionSelected
) -> None:
    """Returns the chosen desk.

    Args:
        event (widgets.OptionList.OptionSelected): The choice.
    """
    self.dismiss(self._desks[event.option_index]['name'])

action_cancel

action_cancel()

Closes the dialog without a choice.

Source code in src/trading_agent/terminal/widgets/desk_picker.py
def action_cancel(self) -> None:
    """Closes the dialog without a choice."""
    self.dismiss(None)