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

Add a method of cancelling a widget's animation #2786

Closed
davep opened this issue Jun 15, 2023 · 3 comments · Fixed by #3000
Closed

Add a method of cancelling a widget's animation #2786

davep opened this issue Jun 15, 2023 · 3 comments · Fixed by #3000
Assignees
Labels
enhancement New feature or request Task

Comments

@davep
Copy link
Contributor

davep commented Jun 15, 2023

Currently we can animate properties of a widget but there is a situation where things may change just after the animation starts, such that the animation is heading towards a situation that no longer makes sense. The Underline of Tabs is one good example, where the "slide" animation of the underline might be kicked off, heading towards a tab, that is subsequently removed while the animation is still happening. This can end up with the underline highlight being the wrong size, or even highlighting a tab that's no longer there because all tabs have been removed.

Given this sort of situation could happen with other widgets (an animation is seeking an end result that might not make sense by the time it ends), it would be useful if there was a way of cancelling any current animations on a widget.

@davep davep added enhancement New feature or request Task labels Jun 15, 2023
@willmcgugan
Copy link
Collaborator

Suggest something like def stop_animation(attribute:str):

davep added a commit to davep/textual that referenced this issue Jun 15, 2023
Ideally this would use something like what Textualize#2786 intends to add, but
meanwhile this solves the problem of ghost highlights in extreme situations
of adding/removing tabs.
@davep davep assigned davep and unassigned davep Jul 20, 2023
@davep
Copy link
Contributor Author

davep commented Jul 20, 2023

After puzzling for too long over the way in here, I think it just clicked. The quick and dirty way of doing this seems to be:

del self.app._animator._animations[(id(self), "the_attribute")]

With this as the (terrible, of course, but a clue) core concept, I think I can take it from there.

@github-actions
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
enhancement New feature or request Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants