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
6 changes: 5 additions & 1 deletion src/toad/client/prompt_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from agent_comms.messaging.message_files import FileUpload
from metaclass_registry import AbstractHooksMeta
from ui_theme.scheme import PromptToneColour, ThemeColour
from ui_theme.scheme import InputToneColour, PromptToneColour, ThemeColour, TurnBandColour

from toad.client.input_decision import InputDecision
from toad.setting_declarations import EachOpenWidget
Expand Down Expand Up @@ -56,6 +56,10 @@ class PromptComposer(metaclass=AbstractHooksMeta):
pushes the history further."""
# The surface the composer's area is painted on, a tier off the transcript above it.
area_tone: ClassVar[type[ThemeColour]] = PromptToneColour
# The delivery and queue lines' band over that area, and the field typed into, a tier off
# both: each interactive part of the composer is its own surface, in both frontends.
queue_tone: ClassVar[type[ThemeColour]] = TurnBandColour
input_tone: ClassVar[type[ThemeColour]] = InputToneColour

@property
@abstractmethod
Expand Down
68 changes: 51 additions & 17 deletions src/toad/qt/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,11 @@ def __init__(self, host: ComposerHost, renderer: QtLineRenderer, placeholder: st
renderer.themed(self, self.paint_colours)
# Textual's QueueSummary + DeliveryControls, reading the shared submissions owner.
self.submitting = QtQueueSummary(self)
self.submitting.setObjectName("composer-queue")
self.delivery_controls = QtDeliveryControls(self)
self.delivery_controls.setObjectName("composer-delivery")
for line in (self.submitting, self.delivery_controls):
line.setAttribute(Qt.WidgetAttribute.WA_StyledBackground, True)
# Textual's `QueueHint`: the info bar's held count while the delivery preview is off,
# before the status line as Textual composes it.
self.held = QtQueueHint(self)
Expand All @@ -357,8 +361,9 @@ def __init__(self, host: ComposerHost, renderer: QtLineRenderer, placeholder: st
# button beside the box is the box's one-line height, pinned to its bottom
# (`fit_buttons`).
self.frame_row = frame_row = QHBoxLayout()
frame_row.setSpacing(UiGap.normal)
frame_row.addWidget(self.frame, 1)
frame_row.addWidget(self.send_button, 0, Qt.AlignmentFlag.AlignBottom)
self.add_box_button(self.send_button)
layout = QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
Expand Down Expand Up @@ -395,9 +400,14 @@ def cells(spacing):
return spacing.left * cell, spacing.top * line, spacing.right * cell, spacing.bottom * line

self.frame_row.setContentsMargins(*cells(box.frame_margin))
self.frame.layout().setContentsMargins(*cells(box.frame_padding))
# The box's touch room sits evenly above and below the text, so one line is centred in
# the box as Textual's prompt is; the editor itself is exactly its lines' height.
left, top, right, bottom = cells(box.frame_padding)
room = self.TOUCH_ROOM // 2
self.frame.layout().setContentsMargins(left, top + room, right, bottom + room)
left, top, right, bottom = cells(box.label_padding)
self.glyph.setContentsMargins(left, top, right, bottom)
# The glyph's text sits on the editor's first line, below the document's own margin.
self.glyph.setContentsMargins(left, top + self.document_margin(), right, bottom)
self.focus_changed(self.editor.hasFocus())
self.fit_buttons()

Expand All @@ -408,16 +418,28 @@ def one_line_box_height(self) -> int:
border = 2 if self.settings.ui.input.box.bordered else 0
return self.editor_height(1) + padding.top() + padding.bottom() + border

def add_box_button(self, button: QPushButton) -> None:
"""The one way a button joins the box's row (Send, and any a composer adds, Attach
first): placed before Send, bottom-aligned, and the whole row sized again, so a button
added after the composer was built is sized like the rest (Attach was not, 2026-11-18)."""
# Send is added first and stays last; every later button goes before it.
self.frame_row.insertWidget(self.frame_row.count() - len(self.box_buttons),
button, 0, Qt.AlignmentFlag.AlignBottom)
self.box_buttons = (*self.box_buttons[:-1], button, *self.box_buttons[-1:]) \
if self.box_buttons else (button,)
self.fit_buttons()

box_buttons: tuple[QPushButton, ...] = ()

def fit_buttons(self) -> None:
"""Every button in the box's row (send, and any a composer adds beside it) is the
box's one-line height and at least as wide as tall: level with a one-line box, and
pinned to the bottom of a taller one (each is added bottom-aligned)."""
"""Every button in the box's row is one size: the box's one-line height, and the
widest one's width (at least as wide as tall), level with a one-line box and pinned to
the bottom of a taller one."""
height = self.one_line_box_height()
for index in range(self.frame_row.count()):
button = self.frame_row.itemAt(index).widget()
if button is not None and button is not self.frame:
button.setFixedHeight(height)
button.setMinimumWidth(height)
buttons = self.box_buttons
width = max((height, *(button.sizeHint().width() for button in buttons)))
for button in buttons:
button.setFixedSize(width, height)

def update_prompt(self) -> None:
"""A leading symbol or the placeholder setting changed: draw both again."""
Expand All @@ -435,7 +457,12 @@ def submissions(self) -> BusSubmissions:
def paint_colours(self) -> None:
"""The area's tone, the muted placeholder, the offer list, the glyph and the frame's
border, under the renderer's current scheme."""
self.setStyleSheet(f"#composer {{ background: {self.renderer.theme(self.area_tone)} }}")
# The area, the band its delivery and queue lines sit on, and the field typed into: the
# shared composer's three tones (Textual paints the same ones through TonePaint).
queue = self.renderer.theme(self.queue_tone)
self.setStyleSheet(
f"#composer {{ background: {self.renderer.theme(self.area_tone)} }}"
f" #composer-queue, #composer-delivery {{ background: {queue} }}")
palette = self.editor.palette()
palette.setColor(QPalette.ColorRole.PlaceholderText, QColor(self.renderer.colour(MutedRole)))
self.editor.setPalette(palette)
Expand All @@ -447,10 +474,11 @@ def focus_changed(self, focused: bool) -> None:
"""The frame's border follows focus (Textual's `PromptContainer.border`), and the
badge shows the editing mode only while focused."""
colour = self.renderer.theme(PrimaryColour if focused else MutedColour)
field = self.renderer.theme(self.input_tone)
self.renderer.apply_sheet(self.frame,
f"#prompt-frame {{ border: 1px solid {colour}; border-radius: 2px }}"
f"#prompt-frame {{ background: {field}; border: 1px solid {colour}; border-radius: 2px }}"
if self.settings.ui.input.box.bordered
else "#prompt-frame { border: none }")
else f"#prompt-frame {{ background: {field}; border: none }}")
self.info_bar.badge.present_editing_mode(self.editor.editing_mode, focused)

def refresh_editing_mode(self) -> None:
Expand Down Expand Up @@ -485,9 +513,15 @@ def fit_height(self) -> None:
Qt.ScrollBarPolicy.ScrollBarAsNeeded if typed > 5 else Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
self.editor.setFixedHeight(self.editor_height(lines))

TOUCH_ROOM: ClassVar[int] = 16
"""Room the box adds around its text for a finger, split evenly above and below."""

def document_margin(self) -> int:
return round(self.editor.document().documentMargin())

def editor_height(self, lines: int) -> int:
"""The editor's height showing `lines` lines."""
return self.editor.fontMetrics().lineSpacing() * lines + 24
"""The editor's height showing `lines` lines: the lines and the document's margins."""
return self.editor.fontMetrics().lineSpacing() * lines + 2 * self.document_margin()

@property
def text(self) -> str:
Expand Down Expand Up @@ -673,7 +707,7 @@ def __init__(self, host: ComposerHost, renderer: QtLineRenderer, placeholder: st
self.attach_button = QPushButton(AttachFileAction.title, self)
self.attach_button.setFocusPolicy(Qt.FocusPolicy.NoFocus) # tapping keeps the keyboard up
self.attach_button.clicked.connect(self.attach_file)
self.frame_row.insertWidget(1, self.attach_button, 0, Qt.AlignmentFlag.AlignBottom)
self.add_box_button(self.attach_button)
self.attached_row = QWidget(self)
chips = QHBoxLayout(self.attached_row)
chips.setContentsMargins(UiGap.frame, 0, UiGap.frame, 0)
Expand Down
5 changes: 4 additions & 1 deletion src/toad/qt/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,10 @@ async def _refresh_thread_config(self) -> None:
"""Read compose access, status, label and mentions — facts that change when thread
config changes (ThreadsObserved), not on every bus message."""
source = self.app.source()
label = self.conversation.label(source.references())
# The label reads Core's thread references: off the GUI loop, as compose access is.
# Read on the loop it held a tab's opening for 104 ms on the desktop (frame probe).
references = await asyncio.to_thread(source.references)
label = self.conversation.label(references)
self.on_composer("label", lambda composer: composer.labelled(label))
compose = await asyncio.to_thread(self.conversation.compose_access, source.core)
await self.refresh_composer(compose)
Expand Down
10 changes: 8 additions & 2 deletions src/toad/widgets/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,12 @@ class QueueSummary(
MutedText,
StartsHidden,
AutoHeight,
TonePaint,
Label,
can_focus=True,
):
"""Shows queued messages and opens their delivery status when selected."""
tone = PromptComposer.queue_tone


def apply_native_layout(self) -> None:
Expand All @@ -265,7 +267,8 @@ def activate(self) -> None:
self.query_ancestor(Prompt).conversation.open_queue_menu()


class DeliveryControls(QueueDeliveryControls, ComposedWhenShown, StartsHidden, OneRow, containers.HorizontalGroup):
class DeliveryControls(TonePaint, QueueDeliveryControls, ComposedWhenShown, StartsHidden, OneRow, containers.HorizontalGroup):
tone = PromptComposer.queue_tone
"""Shown while Enter queues behind a running turn; `QueueDeliveryControls` owns its text."""

def shown_children(self) -> tuple[Widget, ...]:
Expand Down Expand Up @@ -348,7 +351,10 @@ def render(self):
return self.query_ancestor(Prompt).label_glyph()


class PromptContainer(SettingsReader, FocusWithinView, containers.HorizontalGroup):
class PromptContainer(TonePaint, SettingsReader, FocusWithinView, containers.HorizontalGroup):
# The field typed into: the composer's input tone, a tier off the prompt and its band.
tone = PromptComposer.input_tone

@property
def margin(self):
return self.settings.ui.input.box.frame_margin
Expand Down
Loading