update tweaks

This commit is contained in:
Will McGugan
2024-11-26 16:11:42 +00:00
parent 6f1f7536a2
commit d117ed4d38
3 changed files with 34 additions and 15 deletions

View File

@@ -83,11 +83,13 @@ class MotherApp(App):
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:

View File

@@ -745,10 +745,10 @@ class OffsetProperty:
_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
@@ -771,7 +771,7 @@ class OffsetProperty:
_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]):

View File

@@ -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".
@@ -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".
@@ -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".
@@ -342,8 +339,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)
@@ -632,7 +631,12 @@ class StylesBase:
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.
@@ -640,6 +644,7 @@ class StylesBase:
layout: Also require a layout.
children: Also refresh children.
parent: Also refresh the parent.
repaint: Repaint the widgets.
"""
def reset(self) -> None:
@@ -850,17 +855,22 @@ class Styles(StylesBase):
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."""
@@ -1334,9 +1344,16 @@ class RenderStyles(StylesBase):
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.