Skip to content

trading_agent.terminal.widgets.outputs_card

The side panel's Outputs card: pictures and documents the desk sent today, newest first.

Choosing one downloads it and opens it with the desktop's default program.

Typical usage example:

card = OutputsCard(opener) card.show('general', events)

OutputsCard

OutputsCard(opener, collapsed=False)

Bases: SideCard

The Outputs card.

Creates the card.

Parameters:

Name Type Description Default
opener AttachmentOpener

Downloads and opens the files.

required
collapsed bool

Whether it starts folded.

False
Source code in src/trading_agent/terminal/widgets/outputs_card.py
def __init__(
    self,
    opener: attachment_opener.AttachmentOpener,
    collapsed: bool = False,
):
    """Creates the card.

    Args:
        opener (attachment_opener.AttachmentOpener): Downloads and opens the files.
        collapsed (bool): Whether it starts folded.
    """
    self._list = widgets.OptionList(classes='output-list')
    super().__init__('outputs', 'Outputs', self._list, collapsed=collapsed)
    self._opener = opener
    self._formatter = formatter.Formatter()
    self._outputs: list[dict[str, Any]] = []
    self._desk_name = ''

show

show(desk_name, events)

Lists the files in the desk's messages of today.

Parameters:

Name Type Description Default
desk_name str

The desk.

required
events Sequence[dict[str, Any]]

The desk's events of today.

required
Source code in src/trading_agent/terminal/widgets/outputs_card.py
def show(self, desk_name: str, events: Sequence[dict[str, Any]]) -> None:
    """Lists the files in the desk's messages of today.

    Args:
        desk_name (str): The desk.
        events (Sequence[dict[str, Any]]): The desk's events of today.
    """
    self._desk_name = desk_name
    outputs = []
    for event in events:
        if event.get('kind') != 'message':
            continue
        attachments = (event.get('payload') or {}).get('attachments')
        if not isinstance(attachments, list):
            continue
        for attachment in attachments:
            outputs.append(
                {
                    'attachment': attachment,
                    'sent_at': event.get('created_at', ''),
                }
            )
    outputs.reverse()
    if [item['attachment'].get('attachment_id') for item in outputs] == [
        item['attachment'].get('attachment_id') for item in self._outputs
    ]:
        return
    self._outputs = outputs
    self.show_aside(str(len(outputs)))
    if not outputs:
        self.show_body(
            self.note('Pictures and documents the desk sends appear here.')
        )
    else:
        self.show_body(self.note('Enter opens one in its own program.'))
    self._list.clear_options()
    for output in outputs:
        attachment = output['attachment']
        icon = '▣'
        if attachment.get('kind') == 'image':
            icon = '▨'
        self._list.add_option(
            option_list.Option(
                Content.from_markup(
                    '$icon $name [dim]$time[/dim]',
                    icon=icon,
                    name=str(attachment.get('file_name', 'file')),
                    time=self._formatter.time(output['sent_at'])[:5],
                )
            )
        )
    self._list.display = bool(outputs)

on_option_list_option_selected

on_option_list_option_selected(event)

Opens the chosen file.

Parameters:

Name Type Description Default
event OptionSelected

The choice.

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

    Args:
        event (widgets.OptionList.OptionSelected): The choice.
    """
    event.stop()
    self._open(self._outputs[event.option_index]['attachment'])