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

Tabs.Cleared documentation a little ambiguous #4241

Closed
davep opened this issue Feb 29, 2024 · 3 comments · Fixed by #4298
Closed

Tabs.Cleared documentation a little ambiguous #4241

davep opened this issue Feb 29, 2024 · 3 comments · Fixed by #4298
Assignees
Labels
documentation Improvements or additions to documentation Task

Comments

@davep
Copy link
Contributor

davep commented Feb 29, 2024

The Tabs.Cleared message is documented as being "Sent when there are no active tabs. This can occur when Tabs are cleared, or if all tabs are hidden". This suggests that Tabs.cleared or hiding every single Tab are the only routes to causing this message to be posted.

From what I can see simply setting Tabs.active to an empty string will cause this message to be posted too. The documentation should probably make it clear that this will also be a cause.

A followup question, which might need to spin off into another issue, is: does it make sense that Tabs.active can be set (outwith of the workings of Tabs) to an empty string? And if the answer is yes, the next question would be "why does doing this cause Tabs to behave as if the last-active-tab were still the active tab?"

@davep davep added documentation Improvements or additions to documentation Task labels Feb 29, 2024
@davep
Copy link
Contributor Author

davep commented Feb 29, 2024

Related to this, TabbedContent.active can't be set to an empty string:

╭──────────────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────────────╮
│ /Users/davep/develop/python/textual/../textual-sandbox/tabbed_content_message_testing.py:37 in empty_active                        │
│                                                                                                                                    │
│   34 │                                                                                        ╭────────── locals ──────────╮       │
│   35 │   @on(Button.Pressed, "#empty-active")                                                 │ self = WrapperForTesting() │       │
│   36 │   def empty_active(self) -> None:                                                      ╰────────────────────────────╯       │
│ ❱ 37 │   │   self.query_one(TabbedContent).active = ""                                                                             │
│   38 │                                                                                                                             │
│   39 │   @on(Button.Pressed, "#hide-all")                                                                                          │
│   40 │   def hide_all(self) -> None:                                                                                               │
│                                                                                                                                    │
│ /Users/davep/develop/python/textual/src/textual/widgets/_tabbed_content.py:345 in validate_active                                  │
│                                                                                                                                    │
│   342 │   │   │   ValueError: If the active attribute is set to empty string when there are ta ╭───────── locals ─────────╮        │
│   343 │   │   """                                                                              │ active = ''              │        │
│   344 │   │   if not active and self.get_child_by_type(ContentSwitcher).current:               │   self = TabbedContent() │        │
│ ❱ 345 │   │   │   raise ValueError("'active' tab must not be empty string.")                   ╰──────────────────────────╯        │
│   346 │   │   return active                                                                                                        │
│   347 │                                                                                                                            │
│   348 │   @staticmethod                                                                                                            │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: 'active' tab must not be empty string.

This does raise the question: should there be this difference between Tabs and TabbedContent?

@willmcgugan
Copy link
Collaborator

The probably should be the same.

Copy link

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
documentation Improvements or additions to documentation Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants