Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TabbedContent will crash if cleared and panes added too quickly #3295

Closed
TomJGooding opened this issue Sep 13, 2023 · 3 comments
Closed

TabbedContent will crash if cleared and panes added too quickly #3295

TomJGooding opened this issue Sep 13, 2023 · 3 comments

Comments

@TomJGooding
Copy link
Contributor

TomJGooding commented Sep 13, 2023

This stems from discussions #3288 and #3238, where the original poster is having problems updating the panes in TabbedContent depending on the option selected in another widget.

While trying to create a minimal reproducible example, I found that this app will crash if you hold the down key for long enough , either with a NoMatches error or ValueError.

This feels like a bug, but perhaps I am just doing something wrong?

from textual import on
from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.widgets import OptionList, TabbedContent, TabPane


class ExampleApp(App):
    CSS = """
    TabbedContent {
        width: 70%
    }

    OptionList {
        width: 30%;
        height: 100%;
    }
    """

    def compose(self) -> ComposeResult:
        with Horizontal():
            yield TabbedContent()
            yield OptionList("Hold", "the", "down", "key")

    def on_mount(self) -> None:
        option_list = self.query_one(OptionList)
        option_list.focus()

    @on(OptionList.OptionHighlighted)
    async def on_option_list_option_highlighted(
        self, event: OptionList.OptionHighlighted
    ) -> None:
        option = event.option.prompt
        tabbed_content = self.query_one(TabbedContent)
        await tabbed_content.clear_panes()
        for tab_title in (
            f"{option}-tab-1",
            f"{option}-tab-2",
            f"{option}-tab-3",
        ):
            tab_pane = TabPane(tab_title, id=tab_title)
            await tabbed_content.add_pane(tab_pane)


if __name__ == "__main__":
    app = ExampleApp()
    app.run()
@github-actions
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@TomJGooding TomJGooding changed the title TabbedContent will crash if cleared and tabs added too quickly TabbedContent will crash if cleared and panes added too quickly Sep 13, 2023
@TomJGooding
Copy link
Contributor Author

Closing this issue as It looks like this was fixed with recent changes to Tabs/TabbedContent.

Copy link

github-actions bot commented Nov 8, 2023

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant