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

Button.watch_variant does not remove old_variant class #1048

Closed
n-doerrer opened this issue Oct 28, 2022 · 3 comments · Fixed by #1051
Closed

Button.watch_variant does not remove old_variant class #1048

n-doerrer opened this issue Oct 28, 2022 · 3 comments · Fixed by #1051
Assignees
Labels
bug Something isn't working

Comments

@n-doerrer
Copy link

When changing the variant of a Button widget, the new variant gets added to the classes, but the old one is not removed.
Minimal example:

from textual.app import App, ComposeResult
from textual.widgets import Button


class MyApp(App):
	def __init__(self):
		super().__init__()
		self.button = Button()
		self.button.variant = "warning"
		self.button.variant = "default"

	def compose(self) -> ComposeResult:
		yield self.button

MyApp().run()

This still displays the button in "warning" style as it has both classes.
I believe the problem is the underscore instead of a dash in the watch_variant method.
https://github.com/Textualize/textual/blob/main/src/textual/widgets/_button.py#L218

textual version 0.2.1
terminal: xterm-256color on linux ubuntu 22.04 (Regolith)

@davep davep added the bug Something isn't working label Oct 28, 2022
davep added a commit to davep/textual-sandbox that referenced this issue Oct 28, 2022
@davep davep self-assigned this Oct 28, 2022
@davep
Copy link
Contributor

davep commented Oct 28, 2022

Good catch. Slightly more interactive display of this, allowing watching the classes develop:

from textual.app import App, ComposeResult
from textual.widgets import Button, Static


class MyApp( App[None] ):

    def compose( self ) -> ComposeResult:
        yield Button( "Push Me" )
        yield Static( "Push the above!", id="classes" )

    def on_button_pressed( self, event: Button.Pressed ) -> None:
        event.button.variant = (
            "warning" if event.button.variant == "default" else "default"
        )
        self.query_one( "#classes", Static ).update(
            ", ".join( event.button.classes )
        )

if __name__ == "__main__":
    MyApp().run()

davep added a commit to davep/textual that referenced this issue Oct 28, 2022
@davep davep linked a pull request Oct 28, 2022 that will close this issue
@github-actions
Copy link

Did we solve your problem?

Glad we could help!

@davep
Copy link
Contributor

davep commented Oct 28, 2022

Now fixed for the next release: #1051

Thanks @n-doerrer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants