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

"Proper" way of pausing timers when switching MODES? #5189

Closed
froggleston opened this issue Oct 28, 2024 · 5 comments
Closed

"Proper" way of pausing timers when switching MODES? #5189

froggleston opened this issue Oct 28, 2024 · 5 comments

Comments

@froggleston
Copy link

froggleston commented Oct 28, 2024

Spurred on by a comment in #3405 ...

Alternatively, maybe a timer could have a "pause if not in active screen" setting.

This would be interesting to me - I am trying to manually pause timers when switching screens as my timers control the updates to active screens based on an elapsed timeframe, e.g. when screen 1 is active, update x once every 5 sec.

I have a class TimedScreen that provides functions to track, initiate, and pause/resume timers. It uses the ScreenSuspend and ScreenResume events. When switching screens (via MODES), I attempt to pause the screen's timers, but the events are still firing. However, the messages are being relayed so it seems the actual pause()/resume() functions should be being called

You can see a MRE class that you can include in a test exhibiting the issue here: https://github.com/freqtrade/ftui/blob/main/ftui/widgets/timed_screen.py

Timers are added to a screen via on_mount(), as shown here: https://github.com/freqtrade/ftui/blob/main/ftui/screens/dashboard_screen.py#L86

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

@willmcgugan
Copy link
Collaborator

How about putting the following in your timer functions?

if not self.screen.is_active:
    return

@froggleston
Copy link
Author

Thanks @willmcgugan ! I'll give this a go later this week - thank you for the suggestion!

@froggleston
Copy link
Author

This worked perfectly. Thanks @willmcgugan

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
None yet
Projects
None yet
Development

No branches or pull requests

2 participants