moses-palmer / pystray

GNU General Public License v3.0
469 stars 59 forks source link

Taking control of the main loop. #168

Open BMaxV opened 1 month ago

BMaxV commented 1 month ago

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?