Skip to content

Commit f48b71b

Browse files
authored
Merge pull request #5289 from Textualize/update-tweaks
update tweaks
2 parents add4daa + e355ad3 commit f48b71b

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

examples/mother.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ async def on_input(self, event: Input.Submitted) -> None:
8383
await chat_view.mount(Prompt(event.value))
8484
await chat_view.mount(response := Response())
8585
response.anchor()
86+
8687
self.send_prompt(event.value, response)
8788

8889
@work(thread=True)
8990
def send_prompt(self, prompt: str, response: Response) -> None:
9091
"""Get the response in a thread."""
92+
9193
response_content = ""
9294
llm_response = self.model.prompt(prompt, system=SYSTEM)
9395
for chunk in llm_response:

src/textual/css/_style_properties.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,10 +745,10 @@ def __set__(
745745
_rich_traceback_omit = True
746746
if offset is None:
747747
if obj.clear_rule(self.name):
748-
obj.refresh(layout=True)
748+
obj.refresh(layout=True, repaint=False)
749749
elif isinstance(offset, ScalarOffset):
750750
if obj.set_rule(self.name, offset):
751-
obj.refresh(layout=True)
751+
obj.refresh(layout=True, repaint=False)
752752
else:
753753
x, y = offset
754754

@@ -771,7 +771,7 @@ def __set__(
771771
_offset = ScalarOffset(scalar_x, scalar_y)
772772

773773
if obj.set_rule(self.name, _offset):
774-
obj.refresh(layout=True)
774+
obj.refresh(layout=True, repaint=False)
775775

776776

777777
class StringEnumProperty(Generic[EnumType]):

src/textual/css/styles.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,7 @@ class StylesBase:
238238

239239
node: DOMNode | None = None
240240

241-
display = StringEnumProperty(
242-
VALID_DISPLAY, "block", layout=True, refresh_parent=True, refresh_children=True
243-
)
241+
display = StringEnumProperty(VALID_DISPLAY, "block", layout=True)
244242
"""Set the display of the widget, defining how it's rendered.
245243
246244
Valid values are "block" or "none".
@@ -253,9 +251,7 @@ class StylesBase:
253251
StyleValueError: If an invalid display is specified.
254252
"""
255253

256-
visibility = StringEnumProperty(
257-
VALID_VISIBILITY, "visible", layout=True, refresh_parent=True
258-
)
254+
visibility = StringEnumProperty(VALID_VISIBILITY, "visible", layout=True)
259255
"""Set the visibility of the widget.
260256
261257
Valid values are "visible" or "hidden".
@@ -281,6 +277,7 @@ class StylesBase:
281277
"""
282278

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

328325
border_title_align = StringEnumProperty(VALID_ALIGN_HORIZONTAL, "left")
326+
"""The alignment of the border title text."""
329327
border_subtitle_align = StringEnumProperty(VALID_ALIGN_HORIZONTAL, "right")
328+
"""The alignment of the border subtitle text."""
330329

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

344343
keyline = KeylineProperty()
344+
"""Keyline parameters."""
345345

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

634635
def refresh(
635-
self, *, layout: bool = False, children: bool = False, parent: bool = False
636+
self,
637+
*,
638+
layout: bool = False,
639+
children: bool = False,
640+
parent: bool = False,
641+
repaint: bool = True,
636642
) -> None:
637643
"""Mark the styles as requiring a refresh.
638644
639645
Args:
640646
layout: Also require a layout.
641647
children: Also refresh children.
642648
parent: Also refresh the parent.
649+
repaint: Repaint the widgets.
643650
"""
644651

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

852859
def refresh(
853-
self, *, layout: bool = False, children: bool = False, parent: bool = False
860+
self,
861+
*,
862+
layout: bool = False,
863+
children: bool = False,
864+
parent: bool = False,
865+
repaint=True,
854866
) -> None:
855867
node = self.node
856868
if node is None or not node._is_mounted:
857869
return
858870
if parent and node._parent is not None:
859-
node._parent.refresh()
871+
node._parent.refresh(repaint=repaint)
860872
node.refresh(layout=layout)
861873
if children:
862874
for child in node.walk_children(with_self=False, reverse=True):
863-
child.refresh(layout=layout)
875+
child.refresh(layout=layout, repaint=repaint)
864876

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

13361348
def refresh(
1337-
self, *, layout: bool = False, children: bool = False, parent: bool = False
1349+
self,
1350+
*,
1351+
layout: bool = False,
1352+
children: bool = False,
1353+
parent: bool = False,
1354+
repaint: bool = True,
13381355
) -> None:
1339-
self._inline_styles.refresh(layout=layout, children=children, parent=parent)
1356+
self._inline_styles.refresh(
1357+
layout=layout, children=children, parent=parent, repaint=repaint
1358+
)
13401359

13411360
def merge(self, other: StylesBase) -> None:
13421361
"""Merge values from another Styles.

0 commit comments

Comments
 (0)