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

Taking control of the main loop. #168

Open
BMaxV opened this issue Jul 17, 2024 · 2 comments
Open

Taking control of the main loop. #168

BMaxV opened this issue Jul 17, 2024 · 2 comments

Comments

@BMaxV
Copy link

BMaxV commented Jul 17, 2024

Hey there,

I really like the package, it's doing what I want, and behaves as expected.

There is a single thing I would like to have and I would write the PR for it: I want to be in control of the main loop, like this:

import random
import pystray
class MyApp:
    def __init__(self):
        self.pystrayIcon = pystray.icon("foo")
    
    def whatever(self):
        print("bar")
        r = random.random()
        if r < 0.01:
            return True
        else:
            return False
    
    def main(self):
        while True:
            r = self.whatever()
            self.pystrayIcon.mainstep() # this would be new
            if r:
                self.pystrayIcon.stop()
                break
            
if __name__=="__main__":
    myapp_instance = MyApp()
    myapp_instance.main()

From what I can see, all that's required is to not while True: yield the events?

Would you accept such a PR?

@moses-palmer
Copy link
Owner

Thank you for you suggestion!

I agree that this would be a very helpful addition, and if you managed I would certainly accept such a merge request. I think, however, that it may not be possible to implement for all supported backends, and I am very reluctant to add special functionality for single backends.

@BMaxV
Copy link
Author

BMaxV commented Oct 16, 2024

I agree that the idea is to have a unified solution, so if a specific exception has to be made, that would be bad. Are there tests to find out if a solution would work? Or would it have to be a manual trial and error?

Anyway, now that you've given your ok, I think it's worth the time to investigate. So I will do that.

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