mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge pull request #5298 from Textualize/fix-remove-tab
auto generate tab ids
This commit is contained in:
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- Fixed infinite loop in `Widget.anchor` https://github.com/Textualize/textual/pull/5290
|
||||
- Restores the ability to supply console markup to command list https://github.com/Textualize/textual/pull/5294
|
||||
- Fixed delayed App Resize event https://github.com/Textualize/textual/pull/5296
|
||||
- Fixed issue with auto-generated tab IDs https://github.com/Textualize/textual/pull/5298
|
||||
|
||||
## [0.87.1] - 2024-11-24
|
||||
|
||||
|
||||
@@ -332,6 +332,7 @@ class TabbedContent(Widget):
|
||||
self.titles = [self.render_str(title) for title in titles]
|
||||
self._tab_content: list[Widget] = []
|
||||
self._initial = initial
|
||||
self._tab_counter = 0
|
||||
super().__init__(name=name, id=id, classes=classes, disabled=disabled)
|
||||
|
||||
@property
|
||||
@@ -357,6 +358,15 @@ class TabbedContent(Widget):
|
||||
content.id = f"tab-{new_id}"
|
||||
return content
|
||||
|
||||
def _generate_tab_id(self) -> int:
|
||||
"""Auto generate a new tab id.
|
||||
|
||||
Returns:
|
||||
An auto-incrementing integer.
|
||||
"""
|
||||
self._tab_counter += 1
|
||||
return self._tab_counter
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
"""Compose the tabbed content."""
|
||||
|
||||
@@ -368,7 +378,7 @@ class TabbedContent(Widget):
|
||||
if isinstance(content, TabPane)
|
||||
else TabPane(title or self.render_str(f"Tab {index}"), content)
|
||||
),
|
||||
index,
|
||||
self._generate_tab_id(),
|
||||
)
|
||||
for index, (title, content) in enumerate(
|
||||
zip_longest(self.titles, self._tab_content), 1
|
||||
@@ -424,7 +434,7 @@ class TabbedContent(Widget):
|
||||
if isinstance(after, TabPane):
|
||||
after = after.id
|
||||
tabs = self.get_child_by_type(ContentTabs)
|
||||
pane = self._set_id(pane, tabs.tab_count + 1)
|
||||
pane = self._set_id(pane, self._generate_tab_id())
|
||||
assert pane.id is not None
|
||||
pane.display = False
|
||||
return AwaitComplete(
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
<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-43154064-matrix {
|
||||
font-family: Fira Code, monospace;
|
||||
font-size: 20px;
|
||||
line-height: 24.4px;
|
||||
font-variant-east-asian: full-width;
|
||||
}
|
||||
|
||||
.terminal-43154064-title {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
font-family: arial;
|
||||
}
|
||||
|
||||
.terminal-43154064-r1 { fill: #c5c8c6 }
|
||||
.terminal-43154064-r2 { fill: #ddedf9;font-weight: bold }
|
||||
.terminal-43154064-r3 { fill: #797979 }
|
||||
.terminal-43154064-r4 { fill: #e0e0e0 }
|
||||
.terminal-43154064-r5 { fill: #4f4f4f }
|
||||
.terminal-43154064-r6 { fill: #0178d4 }
|
||||
.terminal-43154064-r7 { fill: #ffa62b;font-weight: bold }
|
||||
.terminal-43154064-r8 { fill: #495259 }
|
||||
</style>
|
||||
|
||||
<defs>
|
||||
<clipPath id="terminal-43154064-clip-terminal">
|
||||
<rect x="0" y="0" width="975.0" height="584.5999999999999" />
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-0">
|
||||
<rect x="0" y="1.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-1">
|
||||
<rect x="0" y="25.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-2">
|
||||
<rect x="0" y="50.3" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-3">
|
||||
<rect x="0" y="74.7" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-4">
|
||||
<rect x="0" y="99.1" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-5">
|
||||
<rect x="0" y="123.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-6">
|
||||
<rect x="0" y="147.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-7">
|
||||
<rect x="0" y="172.3" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-8">
|
||||
<rect x="0" y="196.7" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-9">
|
||||
<rect x="0" y="221.1" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-10">
|
||||
<rect x="0" y="245.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-11">
|
||||
<rect x="0" y="269.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-12">
|
||||
<rect x="0" y="294.3" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-13">
|
||||
<rect x="0" y="318.7" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-14">
|
||||
<rect x="0" y="343.1" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-15">
|
||||
<rect x="0" y="367.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-16">
|
||||
<rect x="0" y="391.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-17">
|
||||
<rect x="0" y="416.3" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-18">
|
||||
<rect x="0" y="440.7" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-19">
|
||||
<rect x="0" y="465.1" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-20">
|
||||
<rect x="0" y="489.5" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-line-21">
|
||||
<rect x="0" y="513.9" width="976" height="24.65"/>
|
||||
</clipPath>
|
||||
<clipPath id="terminal-43154064-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-43154064-title" fill="#c5c8c6" text-anchor="middle" x="496" y="27">ExampleApp</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-43154064-clip-terminal)">
|
||||
<rect fill="#0178d4" x="0" y="1.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#0178d4" x="12.2" y="1.5" width="61" height="24.65" shape-rendering="crispEdges"/><rect fill="#0178d4" x="73.2" y="1.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="85.4" y="1.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="97.6" y="1.5" width="85.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="183" y="1.5" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="207.4" y="1.5" width="85.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="292.8" y="1.5" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="305" y="1.5" width="671" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="0" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="12.2" y="25.9" width="61" height="24.65" shape-rendering="crispEdges"/><rect fill="#121212" x="73.2" y="25.9" width="902.8" 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="#242f38" x="0" y="562.7" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#242f38" x="36.6" y="562.7" width="219.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#242f38" x="256.2" y="562.7" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#242f38" x="292.8" y="562.7" width="536.8" height="24.65" shape-rendering="crispEdges"/><rect fill="#242f38" x="829.6" y="562.7" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#242f38" x="841.8" y="562.7" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#242f38" x="866.2" y="562.7" width="97.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#242f38" x="963.8" y="562.7" width="12.2" height="24.65" shape-rendering="crispEdges"/>
|
||||
<g class="terminal-43154064-matrix">
|
||||
<text class="terminal-43154064-r2" x="12.2" y="20" textLength="61" clip-path="url(#terminal-43154064-line-0)">tab-2</text><text class="terminal-43154064-r3" x="97.6" y="20" textLength="85.4" clip-path="url(#terminal-43154064-line-0)">New tab</text><text class="terminal-43154064-r3" x="207.4" y="20" textLength="85.4" clip-path="url(#terminal-43154064-line-0)">New tab</text><text class="terminal-43154064-r1" x="976" y="20" textLength="12.2" clip-path="url(#terminal-43154064-line-0)">
|
||||
</text><text class="terminal-43154064-r5" x="0" y="44.4" textLength="12.2" clip-path="url(#terminal-43154064-line-1)">╸</text><text class="terminal-43154064-r6" x="12.2" y="44.4" textLength="61" clip-path="url(#terminal-43154064-line-1)">━━━━━</text><text class="terminal-43154064-r5" x="73.2" y="44.4" textLength="902.8" clip-path="url(#terminal-43154064-line-1)">╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</text><text class="terminal-43154064-r1" x="976" y="44.4" textLength="12.2" clip-path="url(#terminal-43154064-line-1)">
|
||||
</text><text class="terminal-43154064-r4" x="0" y="68.8" textLength="976" clip-path="url(#terminal-43154064-line-2)">tab-2                                                                           </text><text class="terminal-43154064-r1" x="976" y="68.8" textLength="12.2" clip-path="url(#terminal-43154064-line-2)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="93.2" textLength="12.2" clip-path="url(#terminal-43154064-line-3)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="117.6" textLength="12.2" clip-path="url(#terminal-43154064-line-4)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="142" textLength="12.2" clip-path="url(#terminal-43154064-line-5)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="166.4" textLength="12.2" clip-path="url(#terminal-43154064-line-6)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="190.8" textLength="12.2" clip-path="url(#terminal-43154064-line-7)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="215.2" textLength="12.2" clip-path="url(#terminal-43154064-line-8)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="239.6" textLength="12.2" clip-path="url(#terminal-43154064-line-9)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="264" textLength="12.2" clip-path="url(#terminal-43154064-line-10)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="288.4" textLength="12.2" clip-path="url(#terminal-43154064-line-11)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="312.8" textLength="12.2" clip-path="url(#terminal-43154064-line-12)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="337.2" textLength="12.2" clip-path="url(#terminal-43154064-line-13)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="361.6" textLength="12.2" clip-path="url(#terminal-43154064-line-14)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="386" textLength="12.2" clip-path="url(#terminal-43154064-line-15)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="410.4" textLength="12.2" clip-path="url(#terminal-43154064-line-16)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="434.8" textLength="12.2" clip-path="url(#terminal-43154064-line-17)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="459.2" textLength="12.2" clip-path="url(#terminal-43154064-line-18)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="483.6" textLength="12.2" clip-path="url(#terminal-43154064-line-19)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="508" textLength="12.2" clip-path="url(#terminal-43154064-line-20)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="532.4" textLength="12.2" clip-path="url(#terminal-43154064-line-21)">
|
||||
</text><text class="terminal-43154064-r1" x="976" y="556.8" textLength="12.2" clip-path="url(#terminal-43154064-line-22)">
|
||||
</text><text class="terminal-43154064-r7" x="0" y="581.2" textLength="36.6" clip-path="url(#terminal-43154064-line-23)"> r </text><text class="terminal-43154064-r4" x="36.6" y="581.2" textLength="219.6" clip-path="url(#terminal-43154064-line-23)">Remove first pane </text><text class="terminal-43154064-r7" x="256.2" y="581.2" textLength="36.6" clip-path="url(#terminal-43154064-line-23)"> a </text><text class="terminal-43154064-r4" x="292.8" y="581.2" textLength="536.8" clip-path="url(#terminal-43154064-line-23)">Add pane                                    </text><text class="terminal-43154064-r8" x="829.6" y="581.2" textLength="12.2" clip-path="url(#terminal-43154064-line-23)">▏</text><text class="terminal-43154064-r7" x="841.8" y="581.2" textLength="24.4" clip-path="url(#terminal-43154064-line-23)">^p</text><text class="terminal-43154064-r4" x="866.2" y="581.2" textLength="97.6" clip-path="url(#terminal-43154064-line-23)"> palette</text>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 14 KiB |
@@ -35,6 +35,8 @@ from textual.widgets import (
|
||||
Tab,
|
||||
Tabs,
|
||||
TextArea,
|
||||
TabbedContent,
|
||||
TabPane,
|
||||
)
|
||||
from textual.widgets.text_area import BUILTIN_LANGUAGES, Selection, TextAreaTheme
|
||||
from textual.theme import Theme
|
||||
@@ -2752,7 +2754,6 @@ def test_select_width_auto(snap_compare):
|
||||
snap_compare(TallSelectApp(), run_before=run_before)
|
||||
|
||||
|
||||
|
||||
def test_markup_command_list(snap_compare):
|
||||
"""Regression test for https://github.com/Textualize/textual/issues/5276
|
||||
You should see a command list, with console markup applied to the action name and help text."""
|
||||
@@ -2769,6 +2770,7 @@ def test_markup_command_list(snap_compare):
|
||||
|
||||
snap_compare(MyApp())
|
||||
|
||||
|
||||
def test_app_resize_order(snap_compare):
|
||||
"""Regression test for https://github.com/Textualize/textual/issues/5284
|
||||
You should see a placeholder with text "BAR", focused and scrolled down so it fills the screen.
|
||||
@@ -2810,3 +2812,32 @@ def test_app_resize_order(snap_compare):
|
||||
|
||||
snap_compare(SCApp())
|
||||
|
||||
|
||||
def test_add_remove_tabs(snap_compare):
|
||||
"""Regression test for https://github.com/Textualize/textual/issues/5215
|
||||
You should see a TabbedContent with three panes, entitled 'tab-2', 'New tab' and 'New tab'"""
|
||||
|
||||
class ExampleApp(App):
|
||||
BINDINGS = [
|
||||
("r", "remove_pane", "Remove first pane"),
|
||||
("a", "add_pane", "Add pane"),
|
||||
]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
with TabbedContent(initial="tab-2"):
|
||||
with TabPane("tab-1"):
|
||||
yield Label("tab-1")
|
||||
with TabPane("tab-2"):
|
||||
yield Label("tab-2")
|
||||
yield Footer()
|
||||
|
||||
def action_remove_pane(self) -> None:
|
||||
tabbed_content = self.query_one(TabbedContent)
|
||||
tabbed_content.remove_pane("tab-1")
|
||||
|
||||
def action_add_pane(self) -> None:
|
||||
tabbed_content = self.query_one(TabbedContent)
|
||||
new_pane = TabPane("New tab", Label("new"))
|
||||
tabbed_content.add_pane(new_pane)
|
||||
|
||||
snap_compare(ExampleApp(), press=["a", "r", "a"])
|
||||
|
||||
Reference in New Issue
Block a user