Skip to content

trading_agent.terminal.clipboard_picture

Saves a picture from the desktop clipboard, for Ctrl+V in the message box.

It asks wl-paste on Wayland, then xclip on X11 (which also serves Wayland through XWayland), for a PNG or JPEG on the clipboard. When neither has a picture, the message box pastes text as usual.

Typical usage example:

path = ClipboardPicture().save(folder)

ClipboardPicture

Reads a picture from the clipboard.

save

save(folder)

Writes the clipboard's picture to a file.

Parameters:

Name Type Description Default
folder Path

Where to write it.

required

Returns:

Type Description
Path | None

The picture's file, or None when the clipboard holds no picture or no clipboard program is installed.

Source code in src/trading_agent/terminal/clipboard_picture.py
def save(self, folder: Path) -> Path | None:
    """Writes the clipboard's picture to a file.

    Args:
        folder (Path): Where to write it.

    Returns:
        Path | None: The picture's file, or None when the clipboard holds no picture or no clipboard program is installed.
    """
    for media_type, suffix in _PICTURE_TYPES:
        data = self._read(media_type)
        if data:
            folder.mkdir(parents=True, exist_ok=True)
            path = (
                folder
                / f'clipboard-{time.strftime("%Y%m%d-%H%M%S")}{suffix}'
            )
            path.write_bytes(data)
            return path
    return None