Skip to content

trading_agent.terminal.widgets.picture_view

A picture in the chat: one a tool showed the model, one the desk sent, or one the user attached.

The picture is downloaded from the gateway and drawn with textual-image, which uses the terminal's own graphics (the Kitty protocol or Sixel) when it has them, and coloured half-blocks otherwise. Enter, or a click, opens the full picture with the desktop's default program.

Typical usage example:

view = PictureView('general', picture_path='charts/nifty.png') view = PictureView('general', attachment=attachment)

PictureView

PictureView(desk_name, picture_path=None, attachment=None)

Bases: Vertical

A picture with its name.

Creates the view; the picture loads once it is on screen.

Parameters:

Name Type Description Default
desk_name str

The desk the picture belongs to.

required
picture_path str | None

A picture inside the desk's folder, from a tool result.

None
attachment dict[str, Any] | None

An attachment, from a message.

None
Source code in src/trading_agent/terminal/widgets/picture_view.py
def __init__(
    self,
    desk_name: str,
    picture_path: str | None = None,
    attachment: dict[str, Any] | None = None,
):
    """Creates the view; the picture loads once it is on screen.

    Args:
        desk_name (str): The desk the picture belongs to.
        picture_path (str | None): A picture inside the desk's folder, from a tool result.
        attachment (dict[str, Any] | None): An attachment, from a message.
    """
    super().__init__(classes='picture')
    self._desk_name = desk_name
    self._picture_path = picture_path
    self._attachment = attachment
    self._saved: Path | None = None
    self._caption = widgets.Static(
        Content.from_markup(
            '[dim]▨ $name · loading…[/dim]', name=self._file_name()
        ),
        classes='picture-caption',
    )

compose

compose()

Builds the view.

Yields:

Type Description
Widget

The caption; the picture is added once loaded.

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

    Yields:
        Widget: The caption; the picture is added once loaded.
    """
    yield self._caption

on_mount

on_mount()

Starts loading the picture.

Source code in src/trading_agent/terminal/widgets/picture_view.py
def on_mount(self) -> None:
    """Starts loading the picture."""
    self._load()

on_click

on_click(event)

Opens the picture on a click.

Parameters:

Name Type Description Default
event Click

The click.

required
Source code in src/trading_agent/terminal/widgets/picture_view.py
def on_click(self, event: events.Click) -> None:
    """Opens the picture on a click.

    Args:
        event (events.Click): The click.
    """
    del event
    self.action_open_picture()

action_open_picture

action_open_picture()

Opens the full picture with the desktop's default program.

Source code in src/trading_agent/terminal/widgets/picture_view.py
def action_open_picture(self) -> None:
    """Opens the full picture with the desktop's default program."""
    if self._saved is None:
        self.notify('The picture has not loaded yet.', timeout=3)
        return
    if not self.app.opener.open(self._saved):
        self.notify(
            f'Saved to {self._saved}', title='xdg-open is not installed'
        )