Skip to content

Commit

Permalink
Revert "Prevent reactive-watcher loop in Tabs / TabbedContent. (#2305)"
Browse files Browse the repository at this point in the history
This reverts commit 66a6448.
  • Loading branch information
willmcgugan authored Apr 18, 2023
1 parent cc41a7f commit f420b44
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 196 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fix empty ListView preventing bindings from firing https://github.com/Textualize/textual/pull/2281
- Fix `get_component_styles` returning incorrect values on first call when combined with pseudoclasses https://github.com/Textualize/textual/pull/2304
- Fixed `active_message_pump.get` sometimes resulting in a `LookupError` https://github.com/Textualize/textual/issues/2301
- Fixed issue arising when active tab was changed too quickly in succession https://github.com/Textualize/textual/pull/2305

## [0.19.1] - 2023-04-10

Expand Down
27 changes: 20 additions & 7 deletions src/textual/widgets/_tabbed_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class TabbedContent(Widget):
}
"""

active: reactive[str] = reactive("", init=False)
"""The ID of the active tab, or empty string if none are active."""

class TabActivated(Message):
"""Posted when the active tab changes."""

Expand Down Expand Up @@ -113,16 +116,21 @@ def __init__(self, *titles: TextType, initial: str = "") -> None:
self._initial = initial
super().__init__()

@property
def active(self) -> str:
"""The ID of the active tab, or empty string if none are active."""
return self.get_child_by_type(Tabs).active
def validate_active(self, active: str) -> str:
"""It doesn't make sense for `active` to be an empty string.
Args:
active: Attribute to be validated.
Returns:
Value of `active`.
@active.setter
def active(self, active: str) -> None:
Raises:
ValueError: If the active attribute is set to empty string.
"""
if not active:
raise ValueError("'active' tab must not be empty string.")
self.get_child_by_type(Tabs).active = active
return active

def compose(self) -> ComposeResult:
"""Compose the tabbed content."""
Expand Down Expand Up @@ -178,6 +186,7 @@ def _on_tabs_tab_activated(self, event: Tabs.TabActivated) -> None:
switcher = self.get_child_by_type(ContentSwitcher)
assert isinstance(event.tab, ContentTab)
switcher.current = event.tab.id
self.active = event.tab.id
self.post_message(
TabbedContent.TabActivated(
tabbed_content=self,
Expand All @@ -188,3 +197,7 @@ def _on_tabs_tab_activated(self, event: Tabs.TabActivated) -> None:
def _on_tabs_cleared(self, event: Tabs.Cleared) -> None:
"""All tabs were removed."""
event.stop()

def watch_active(self, active: str) -> None:
"""Switch tabs when the active attributes changes."""
self.get_child_by_type(Tabs).active = active
159 changes: 0 additions & 159 deletions tests/snapshot_tests/__snapshots__/test_snapshots.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -19676,165 +19676,6 @@

'''
# ---
# name: test_quickly_change_tabs
'''
<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-1586716314-matrix {
font-family: Fira Code, monospace;
font-size: 20px;
line-height: 24.4px;
font-variant-east-asian: full-width;
}

.terminal-1586716314-title {
font-size: 18px;
font-weight: bold;
font-family: arial;
}

.terminal-1586716314-r1 { fill: #c5c8c6 }
.terminal-1586716314-r2 { fill: #737373 }
.terminal-1586716314-r3 { fill: #e1e1e1;font-weight: bold }
.terminal-1586716314-r4 { fill: #323232 }
.terminal-1586716314-r5 { fill: #0178d4 }
.terminal-1586716314-r6 { fill: #e1e1e1 }
</style>

<defs>
<clipPath id="terminal-1586716314-clip-terminal">
<rect x="0" y="0" width="975.0" height="584.5999999999999" />
</clipPath>
<clipPath id="terminal-1586716314-line-0">
<rect x="0" y="1.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-1">
<rect x="0" y="25.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-2">
<rect x="0" y="50.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-3">
<rect x="0" y="74.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-4">
<rect x="0" y="99.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-5">
<rect x="0" y="123.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-6">
<rect x="0" y="147.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-7">
<rect x="0" y="172.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-8">
<rect x="0" y="196.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-9">
<rect x="0" y="221.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-10">
<rect x="0" y="245.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-11">
<rect x="0" y="269.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-12">
<rect x="0" y="294.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-13">
<rect x="0" y="318.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-14">
<rect x="0" y="343.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-15">
<rect x="0" y="367.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-16">
<rect x="0" y="391.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-17">
<rect x="0" y="416.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-18">
<rect x="0" y="440.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-19">
<rect x="0" y="465.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-20">
<rect x="0" y="489.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-line-21">
<rect x="0" y="513.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-1586716314-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-1586716314-title" fill="#c5c8c6" text-anchor="middle" x="496" y="27">QuicklyChangeTabsApp</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-1586716314-clip-terminal)">
<rect fill="#1e1e1e" x="0" y="1.5" width="73.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="73.2" y="1.5" width="73.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="146.4" y="1.5" width="97.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="244" y="1.5" width="732" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="25.9" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="24.4" y="25.9" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="61" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="73.2" y="25.9" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="97.6" y="25.9" width="36.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="134.2" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="146.4" y="25.9" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="170.8" y="25.9" width="61" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="231.8" y="25.9" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="244" y="25.9" width="732" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="50.3" width="158.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="158.6" y="50.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="170.8" y="50.3" width="61" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="231.8" y="50.3" width="12.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="244" y="50.3" width="732" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="74.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="99.1" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="24.4" y="99.1" width="61" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="85.4" y="99.1" width="866.2" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="951.6" y="99.1" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="123.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="147.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="172.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="196.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="221.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="245.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="269.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="294.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="318.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="343.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="367.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="391.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="416.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="440.7" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="465.1" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="489.5" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="513.9" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="538.3" width="976" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="562.7" width="976" height="24.65" shape-rendering="crispEdges"/>
<g class="terminal-1586716314-matrix">
<text class="terminal-1586716314-r1" x="976" y="20" textLength="12.2" clip-path="url(#terminal-1586716314-line-0)">
</text><text class="terminal-1586716314-r2" x="24.4" y="44.4" textLength="36.6" clip-path="url(#terminal-1586716314-line-1)">one</text><text class="terminal-1586716314-r2" x="97.6" y="44.4" textLength="36.6" clip-path="url(#terminal-1586716314-line-1)">two</text><text class="terminal-1586716314-r3" x="170.8" y="44.4" textLength="61" clip-path="url(#terminal-1586716314-line-1)">three</text><text class="terminal-1586716314-r1" x="976" y="44.4" textLength="12.2" clip-path="url(#terminal-1586716314-line-1)">
</text><text class="terminal-1586716314-r4" x="0" y="68.8" textLength="158.6" clip-path="url(#terminal-1586716314-line-2)">━━━━━━━━━━━━━</text><text class="terminal-1586716314-r4" x="158.6" y="68.8" textLength="12.2" clip-path="url(#terminal-1586716314-line-2)">╸</text><text class="terminal-1586716314-r5" x="170.8" y="68.8" textLength="61" clip-path="url(#terminal-1586716314-line-2)">━━━━━</text><text class="terminal-1586716314-r4" x="231.8" y="68.8" textLength="12.2" clip-path="url(#terminal-1586716314-line-2)">╺</text><text class="terminal-1586716314-r4" x="244" y="68.8" textLength="732" clip-path="url(#terminal-1586716314-line-2)">━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</text><text class="terminal-1586716314-r1" x="976" y="68.8" textLength="12.2" clip-path="url(#terminal-1586716314-line-2)">
</text><text class="terminal-1586716314-r1" x="976" y="93.2" textLength="12.2" clip-path="url(#terminal-1586716314-line-3)">
</text><text class="terminal-1586716314-r6" x="24.4" y="117.6" textLength="61" clip-path="url(#terminal-1586716314-line-4)">three</text><text class="terminal-1586716314-r1" x="976" y="117.6" textLength="12.2" clip-path="url(#terminal-1586716314-line-4)">
</text><text class="terminal-1586716314-r1" x="976" y="142" textLength="12.2" clip-path="url(#terminal-1586716314-line-5)">
</text><text class="terminal-1586716314-r1" x="976" y="166.4" textLength="12.2" clip-path="url(#terminal-1586716314-line-6)">
</text><text class="terminal-1586716314-r1" x="976" y="190.8" textLength="12.2" clip-path="url(#terminal-1586716314-line-7)">
</text><text class="terminal-1586716314-r1" x="976" y="215.2" textLength="12.2" clip-path="url(#terminal-1586716314-line-8)">
</text><text class="terminal-1586716314-r1" x="976" y="239.6" textLength="12.2" clip-path="url(#terminal-1586716314-line-9)">
</text><text class="terminal-1586716314-r1" x="976" y="264" textLength="12.2" clip-path="url(#terminal-1586716314-line-10)">
</text><text class="terminal-1586716314-r1" x="976" y="288.4" textLength="12.2" clip-path="url(#terminal-1586716314-line-11)">
</text><text class="terminal-1586716314-r1" x="976" y="312.8" textLength="12.2" clip-path="url(#terminal-1586716314-line-12)">
</text><text class="terminal-1586716314-r1" x="976" y="337.2" textLength="12.2" clip-path="url(#terminal-1586716314-line-13)">
</text><text class="terminal-1586716314-r1" x="976" y="361.6" textLength="12.2" clip-path="url(#terminal-1586716314-line-14)">
</text><text class="terminal-1586716314-r1" x="976" y="386" textLength="12.2" clip-path="url(#terminal-1586716314-line-15)">
</text><text class="terminal-1586716314-r1" x="976" y="410.4" textLength="12.2" clip-path="url(#terminal-1586716314-line-16)">
</text><text class="terminal-1586716314-r1" x="976" y="434.8" textLength="12.2" clip-path="url(#terminal-1586716314-line-17)">
</text><text class="terminal-1586716314-r1" x="976" y="459.2" textLength="12.2" clip-path="url(#terminal-1586716314-line-18)">
</text><text class="terminal-1586716314-r1" x="976" y="483.6" textLength="12.2" clip-path="url(#terminal-1586716314-line-19)">
</text><text class="terminal-1586716314-r1" x="976" y="508" textLength="12.2" clip-path="url(#terminal-1586716314-line-20)">
</text><text class="terminal-1586716314-r1" x="976" y="532.4" textLength="12.2" clip-path="url(#terminal-1586716314-line-21)">
</text><text class="terminal-1586716314-r1" x="976" y="556.8" textLength="12.2" clip-path="url(#terminal-1586716314-line-22)">
</text>
</g>
</g>
</svg>

'''
# ---
# name: test_radio_button_example
'''
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">
Expand Down
24 changes: 0 additions & 24 deletions tests/snapshot_tests/snapshot_apps/quickly_change_tabs.py

This file was deleted.

5 changes: 0 additions & 5 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,3 @@ def test_scroll_to_center(snap_compare):
# scrolled so that the red string >>bullseye<< is centered on the screen.
# When this snapshot "breaks" because #2254 is fixed, this snapshot can be updated.
assert snap_compare(SNAPSHOT_APPS_DIR / "scroll_to_center.py", press=["s"])


def test_quickly_change_tabs(snap_compare):
# https://github.com/Textualize/textual/issues/2229
assert snap_compare(SNAPSHOT_APPS_DIR / "quickly_change_tabs.py", press=["p"])

0 comments on commit f420b44

Please sign in to comment.