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
2 changes: 2 additions & 0 deletions examples/mother.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ async def on_input(self, event: Input.Submitted) -> None:
await chat_view.mount(Prompt(event.value))
await chat_view.mount(response := Response())
response.anchor()

self.send_prompt(event.value, response)

@work(thread=True)
def send_prompt(self, prompt: str, response: Response) -> None:
"""Get the response in a thread."""

response_content = ""
llm_response = self.model.prompt(prompt, system=SYSTEM)
for chunk in llm_response:
Expand Down
6 changes: 3 additions & 3 deletions src/textual/css/_style_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,10 @@ def __set__(
_rich_traceback_omit = True
if offset is None:
if obj.clear_rule(self.name):
obj.refresh(layout=True)
obj.refresh(layout=True, repaint=False)
elif isinstance(offset, ScalarOffset):
if obj.set_rule(self.name, offset):
obj.refresh(layout=True)
obj.refresh(layout=True, repaint=False)
else:
x, y = offset

Expand All @@ -771,7 +771,7 @@ def __set__(
_offset = ScalarOffset(scalar_x, scalar_y)

if obj.set_rule(self.name, _offset):
obj.refresh(layout=True)
obj.refresh(layout=True, repaint=False)


class StringEnumProperty(Generic[EnumType]):
Expand Down
43 changes: 31 additions & 12 deletions src/textual/css/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@ class StylesBase:

node: DOMNode | None = None

display = StringEnumProperty(
VALID_DISPLAY, "block", layout=True, refresh_parent=True, refresh_children=True
)
display = StringEnumProperty(VALID_DISPLAY, "block", layout=True)
"""Set the display of the widget, defining how it's rendered.

Valid values are "block" or "none".
Expand All @@ -253,9 +251,7 @@ class StylesBase:
StyleValueError: If an invalid display is specified.
"""

visibility = StringEnumProperty(
VALID_VISIBILITY, "visible", layout=True, refresh_parent=True
)
visibility = StringEnumProperty(VALID_VISIBILITY, "visible", layout=True)
"""Set the visibility of the widget.

Valid values are "visible" or "hidden".
Expand All @@ -281,6 +277,7 @@ class StylesBase:
"""

auto_color = BooleanProperty(default=False)
"""Enable automatic picking of best contrasting color."""
color = ColorProperty(Color(255, 255, 255))
"""Set the foreground (text) color of the widget.
Supports `Color` objects but also strings e.g. "red" or "#ff0000".
Expand Down Expand Up @@ -326,7 +323,9 @@ class StylesBase:
"""Set the left border of the widget e.g. ("rounded", "green") or "none"."""

border_title_align = StringEnumProperty(VALID_ALIGN_HORIZONTAL, "left")
"""The alignment of the border title text."""
border_subtitle_align = StringEnumProperty(VALID_ALIGN_HORIZONTAL, "right")
"""The alignment of the border subtitle text."""

outline = BorderProperty(layout=False)
"""Set the outline of the widget e.g. ("rounded", "green") or "none".
Expand All @@ -342,8 +341,10 @@ class StylesBase:
"""Set the left outline of the widget e.g. ("rounded", "green") or "none"."""

keyline = KeylineProperty()
"""Keyline parameters."""

box_sizing = StringEnumProperty(VALID_BOX_SIZING, "border-box", layout=True)
"""Box sizing method ("border-box" or "conetnt-box")"""
width = ScalarProperty(percent_unit=Unit.WIDTH)
"""Set the width of the widget."""
height = ScalarProperty(percent_unit=Unit.HEIGHT)
Expand Down Expand Up @@ -632,14 +633,20 @@ def get_rule(self, rule_name: str, default: object = None) -> object:
raise NotImplementedError()

def refresh(
self, *, layout: bool = False, children: bool = False, parent: bool = False
self,
*,
layout: bool = False,
children: bool = False,
parent: bool = False,
repaint: bool = True,
) -> None:
"""Mark the styles as requiring a refresh.

Args:
layout: Also require a layout.
children: Also refresh children.
parent: Also refresh the parent.
repaint: Repaint the widgets.
"""

def reset(self) -> None:
Expand Down Expand Up @@ -850,17 +857,22 @@ def set_rule(self, rule: str, value: object | None) -> bool:
return changed

def refresh(
self, *, layout: bool = False, children: bool = False, parent: bool = False
self,
*,
layout: bool = False,
children: bool = False,
parent: bool = False,
repaint=True,
) -> None:
node = self.node
if node is None or not node._is_mounted:
return
if parent and node._parent is not None:
node._parent.refresh()
node._parent.refresh(repaint=repaint)
node.refresh(layout=layout)
if children:
for child in node.walk_children(with_self=False, reverse=True):
child.refresh(layout=layout)
child.refresh(layout=layout, repaint=repaint)

def reset(self) -> None:
"""Reset the rules to initial state."""
Expand Down Expand Up @@ -1334,9 +1346,16 @@ def __rich_repr__(self) -> rich.repr.Result:
yield rule_name, getattr(self, rule_name)

def refresh(
self, *, layout: bool = False, children: bool = False, parent: bool = False
self,
*,
layout: bool = False,
children: bool = False,
parent: bool = False,
repaint: bool = True,
) -> None:
self._inline_styles.refresh(layout=layout, children=children, parent=parent)
self._inline_styles.refresh(
layout=layout, children=children, parent=parent, repaint=repaint
)

def merge(self, other: StylesBase) -> None:
"""Merge values from another Styles.
Expand Down
Loading