mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
snapshot
This commit is contained in:
@@ -18,6 +18,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
- Added `bar_renderable` to `ProgressBar` widget https://github.com/Textualize/textual/pull/5963
|
||||
|
||||
|
||||
### Changed
|
||||
|
||||
- Breaking change: The `renderable` property on the `Static` widget has been changed to `content`. https://github.com/Textualize/textual/pull/6041
|
||||
|
||||
# [5.3.0] - 2025-08-07
|
||||
|
||||
### Added
|
||||
|
||||
@@ -58,15 +58,15 @@ class Static(Widget, inherit_bindings=False):
|
||||
return self._visual
|
||||
|
||||
@property
|
||||
def renderable(self) -> VisualType:
|
||||
return self._content or ""
|
||||
def content(self) -> VisualType:
|
||||
"""The content set in the constructor."""
|
||||
return self._content
|
||||
|
||||
# TODO: Should probably be renamed to `content`.
|
||||
@renderable.setter
|
||||
def renderable(self, renderable: VisualType) -> None:
|
||||
self._renderable = renderable
|
||||
self._visual = None
|
||||
@content.setter
|
||||
def content(self, content: VisualType) -> None:
|
||||
self._visual = visualize(self, content, markup=self._render_markup)
|
||||
self.clear_cached_dimensions()
|
||||
self.refresh(layout=True)
|
||||
|
||||
def render(self) -> RenderResult:
|
||||
"""Get a rich renderable for the widget's content.
|
||||
|
||||
@@ -21,7 +21,7 @@ class ListViewDisabledItemsApp(App[None]):
|
||||
if message.item is None:
|
||||
self.highlighted.append(None)
|
||||
else:
|
||||
self.highlighted.append(str(message.item.children[0].renderable))
|
||||
self.highlighted.append(str(message.item.children[0].content))
|
||||
|
||||
|
||||
async def test_keyboard_navigation_with_disabled_items() -> None:
|
||||
|
||||
@@ -44,7 +44,7 @@ class ListViewApp(App[None]):
|
||||
if message.item is None:
|
||||
self.highlighted.append(None)
|
||||
else:
|
||||
self.highlighted.append(str(message.item.children[0].renderable))
|
||||
self.highlighted.append(str(message.item.children[0].content))
|
||||
|
||||
|
||||
async def test_listview_remove_items() -> None:
|
||||
|
||||
@@ -22,11 +22,11 @@ async def test_reactive_prompt_change():
|
||||
select_current_label = select_current.query_one("#label", Static)
|
||||
select_overlay = select_widget.query_one(SelectOverlay)
|
||||
|
||||
assert select_current_label.renderable == "Old prompt"
|
||||
assert select_current_label.content == "Old prompt"
|
||||
assert select_overlay._options[0].prompt == Text("Old prompt")
|
||||
|
||||
select_widget.prompt = "New prompt"
|
||||
assert select_current_label.renderable == "New prompt"
|
||||
assert select_current_label.content == "New prompt"
|
||||
assert select_overlay._options[0].prompt == Text("New prompt")
|
||||
|
||||
|
||||
@@ -46,9 +46,9 @@ async def test_reactive_prompt_change_when_allow_blank_is_false():
|
||||
select_current_label = select_current.query_one("#label", Static)
|
||||
select_overlay = select_widget.query_one(SelectOverlay)
|
||||
|
||||
assert select_current_label.renderable == "0"
|
||||
assert select_current_label.content == "0"
|
||||
assert select_overlay._options[0].prompt == "0"
|
||||
|
||||
select_widget.prompt = "New prompt"
|
||||
assert select_current_label.renderable == "0"
|
||||
assert select_current_label.content == "0"
|
||||
assert select_overlay._options[0].prompt == "0"
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">
|
||||
<!-- Generated with Rich https://www.textualize.io -->
|
||||
<style>
|
||||
|
||||
@font-face {
|
||||
font-family: "Fira Code";
|
||||
src: local("FiraCode-Regular"),
|
||||
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Regular.woff2") format("woff2"),
|
||||
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Regular.woff") format("woff");
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Fira Code";
|
||||
src: local("FiraCode-Bold"),
|
||||
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Bold.woff2") format("woff2"),
|
||||
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bold.woff") format("woff");
|
||||
font-style: bold;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.terminal-matrix {
|
||||
font-family: Fira Code, monospace;
|
||||
font-size: 20px;
|
||||
line-height: 24.4px;
|
||||
font-variant-east-asian: full-width;
|
||||
}
|
||||
|
||||
.terminal-title {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
font-family: arial;
|
||||
}
|
||||
|
||||
.terminal-r1 { fill: #e0e0e0 }
|
||||
.terminal-r2 { fill: #c5c8c6 }
|
||||
</style>
|
||||
|
||||
<defs>
|
||||
<clipPath id="terminal-clip-terminal">
|
||||
<rect x="0" y="0" width="975.0" height="584.5999999999999" />
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-0">
|
||||
<rect x="0" y="1.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-1">
|
||||
<rect x="0" y="25.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-2">
|
||||
<rect x="0" y="50.3" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-3">
|
||||
<rect x="0" y="74.7" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-4">
|
||||
<rect x="0" y="99.1" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-5">
|
||||
<rect x="0" y="123.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-6">
|
||||
<rect x="0" y="147.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-7">
|
||||
<rect x="0" y="172.3" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-8">
|
||||
<rect x="0" y="196.7" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-9">
|
||||
<rect x="0" y="221.1" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-10">
|
||||
<rect x="0" y="245.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-11">
|
||||
<rect x="0" y="269.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-12">
|
||||
<rect x="0" y="294.3" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-13">
|
||||
<rect x="0" y="318.7" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-14">
|
||||
<rect x="0" y="343.1" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-15">
|
||||
<rect x="0" y="367.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-16">
|
||||
<rect x="0" y="391.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-17">
|
||||
<rect x="0" y="416.3" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-18">
|
||||
<rect x="0" y="440.7" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-19">
|
||||
<rect x="0" y="465.1" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-20">
|
||||
<rect x="0" y="489.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-21">
|
||||
<rect x="0" y="513.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-line-22">
|
||||
<rect x="0" y="538.3" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
|
||||
<rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="992" height="633.6" rx="8"/><text class="terminal-title" fill="#c5c8c6" text-anchor="middle" x="496" y="27">StaticApp</text>
|
||||
<g transform="translate(26,22)">
|
||||
<circle cx="0" cy="0" r="7" fill="#ff5f57"/>
|
||||
<circle cx="22" cy="0" r="7" fill="#febc2e"/>
|
||||
<circle cx="44" cy="0" r="7" fill="#28c840"/>
|
||||
</g>
|
||||
|
||||
<g transform="translate(9, 41)" clip-path="url(#terminal-clip-terminal)">
|
||||
<rect fill="#121212" x="0" y="1.5" width="85.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="85.4" y="1.5" width="890.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="25.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="50.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="74.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="99.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="123.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="147.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="172.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="196.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="221.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="245.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="269.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="294.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="318.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="343.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="367.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="391.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="416.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="440.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="465.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="489.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="513.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="538.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="562.7" width="976" height="24.65" shape-rendering="crispEdges"/>
|
||||
<g class="terminal-matrix">
|
||||
<text class="terminal-r1" x="0" y="20" textLength="85.4" clip-path="url(#terminal-line-0)">FOO BAR</text><text class="terminal-r2" x="976" y="20" textLength="12.2" clip-path="url(#terminal-line-0)">
|
||||
</text><text class="terminal-r2" x="976" y="44.4" textLength="12.2" clip-path="url(#terminal-line-1)">
|
||||
</text><text class="terminal-r2" x="976" y="68.8" textLength="12.2" clip-path="url(#terminal-line-2)">
|
||||
</text><text class="terminal-r2" x="976" y="93.2" textLength="12.2" clip-path="url(#terminal-line-3)">
|
||||
</text><text class="terminal-r2" x="976" y="117.6" textLength="12.2" clip-path="url(#terminal-line-4)">
|
||||
</text><text class="terminal-r2" x="976" y="142" textLength="12.2" clip-path="url(#terminal-line-5)">
|
||||
</text><text class="terminal-r2" x="976" y="166.4" textLength="12.2" clip-path="url(#terminal-line-6)">
|
||||
</text><text class="terminal-r2" x="976" y="190.8" textLength="12.2" clip-path="url(#terminal-line-7)">
|
||||
</text><text class="terminal-r2" x="976" y="215.2" textLength="12.2" clip-path="url(#terminal-line-8)">
|
||||
</text><text class="terminal-r2" x="976" y="239.6" textLength="12.2" clip-path="url(#terminal-line-9)">
|
||||
</text><text class="terminal-r2" x="976" y="264" textLength="12.2" clip-path="url(#terminal-line-10)">
|
||||
</text><text class="terminal-r2" x="976" y="288.4" textLength="12.2" clip-path="url(#terminal-line-11)">
|
||||
</text><text class="terminal-r2" x="976" y="312.8" textLength="12.2" clip-path="url(#terminal-line-12)">
|
||||
</text><text class="terminal-r2" x="976" y="337.2" textLength="12.2" clip-path="url(#terminal-line-13)">
|
||||
</text><text class="terminal-r2" x="976" y="361.6" textLength="12.2" clip-path="url(#terminal-line-14)">
|
||||
</text><text class="terminal-r2" x="976" y="386" textLength="12.2" clip-path="url(#terminal-line-15)">
|
||||
</text><text class="terminal-r2" x="976" y="410.4" textLength="12.2" clip-path="url(#terminal-line-16)">
|
||||
</text><text class="terminal-r2" x="976" y="434.8" textLength="12.2" clip-path="url(#terminal-line-17)">
|
||||
</text><text class="terminal-r2" x="976" y="459.2" textLength="12.2" clip-path="url(#terminal-line-18)">
|
||||
</text><text class="terminal-r2" x="976" y="483.6" textLength="12.2" clip-path="url(#terminal-line-19)">
|
||||
</text><text class="terminal-r2" x="976" y="508" textLength="12.2" clip-path="url(#terminal-line-20)">
|
||||
</text><text class="terminal-r2" x="976" y="532.4" textLength="12.2" clip-path="url(#terminal-line-21)">
|
||||
</text><text class="terminal-r2" x="976" y="556.8" textLength="12.2" clip-path="url(#terminal-line-22)">
|
||||
</text>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 9.3 KiB |
@@ -4570,3 +4570,21 @@ def test_pretty_auto(snap_compare):
|
||||
yield Pretty("hello world")
|
||||
|
||||
assert snap_compare(Demo())
|
||||
|
||||
|
||||
def test_static_content_property(snap_compare):
|
||||
"""Test that the Static.content property.
|
||||
|
||||
You should see the text "FOO BAR"
|
||||
|
||||
"""
|
||||
|
||||
class StaticApp(App):
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("Hello, World")
|
||||
|
||||
def on_mount(self) -> None:
|
||||
self.query_one(Static).content = "FOO BAR"
|
||||
|
||||
assert snap_compare(StaticApp())
|
||||
|
||||
@@ -82,25 +82,25 @@ async def test_mode_setup(ModesApp: Type[App]):
|
||||
app = ModesApp()
|
||||
async with app.run_test():
|
||||
assert isinstance(app.screen, BaseScreen)
|
||||
assert str(app.screen.query_one(Label).renderable) == "one"
|
||||
assert str(app.screen.query_one(Label).content) == "one"
|
||||
|
||||
|
||||
async def test_switch_mode(ModesApp: Type[App]):
|
||||
app = ModesApp()
|
||||
async with app.run_test() as pilot:
|
||||
await pilot.press("2")
|
||||
assert str(app.screen.query_one(Label).renderable) == "two"
|
||||
assert str(app.screen.query_one(Label).content) == "two"
|
||||
await pilot.press("1")
|
||||
assert str(app.screen.query_one(Label).renderable) == "one"
|
||||
assert str(app.screen.query_one(Label).content) == "one"
|
||||
|
||||
|
||||
async def test_switch_same_mode(ModesApp: Type[App]):
|
||||
app = ModesApp()
|
||||
async with app.run_test() as pilot:
|
||||
await pilot.press("1")
|
||||
assert str(app.screen.query_one(Label).renderable) == "one"
|
||||
assert str(app.screen.query_one(Label).content) == "one"
|
||||
await pilot.press("1")
|
||||
assert str(app.screen.query_one(Label).renderable) == "one"
|
||||
assert str(app.screen.query_one(Label).content) == "one"
|
||||
|
||||
|
||||
async def test_switch_unknown_mode(ModesApp: Type[App]):
|
||||
@@ -115,7 +115,7 @@ async def test_remove_mode(ModesApp: Type[App]):
|
||||
async with app.run_test() as pilot:
|
||||
await app.switch_mode("two")
|
||||
await pilot.pause()
|
||||
assert str(app.screen.query_one(Label).renderable) == "two"
|
||||
assert str(app.screen.query_one(Label).content) == "two"
|
||||
app.remove_mode("one")
|
||||
assert "one" not in app._modes
|
||||
|
||||
@@ -133,7 +133,7 @@ async def test_add_mode(ModesApp: Type[App]):
|
||||
app.add_mode("three", lambda: BaseScreen("three"))
|
||||
await app.switch_mode("three")
|
||||
await pilot.pause()
|
||||
assert str(app.screen.query_one(Label).renderable) == "three"
|
||||
assert str(app.screen.query_one(Label).content) == "three"
|
||||
|
||||
|
||||
async def test_add_mode_duplicated(ModesApp: Type[App]):
|
||||
@@ -152,7 +152,7 @@ async def test_screen_stack_preserved(ModesApp: Type[App]):
|
||||
# Build the stack up.
|
||||
for _ in range(N):
|
||||
await pilot.press("p")
|
||||
fruits.append(str(app.screen.query_one(Label).renderable))
|
||||
fruits.append(str(app.screen.query_one(Label).content))
|
||||
|
||||
assert len(app.screen_stack) == N + 1
|
||||
|
||||
@@ -164,7 +164,7 @@ async def test_screen_stack_preserved(ModesApp: Type[App]):
|
||||
# Check the stack.
|
||||
assert len(app.screen_stack) == N + 1
|
||||
for _ in range(N):
|
||||
assert str(app.screen.query_one(Label).renderable) == fruits.pop()
|
||||
assert str(app.screen.query_one(Label).content) == fruits.pop()
|
||||
await pilot.press("o")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user