One of the important TODO's I have for pysystray is making the menu item callbacks/handlers threaded. To acheive this, I thought of the simlplest most unobstrusive way to add it, and I decided to go with Decorators.
Uptill yesternite, I didn't really get Decorators, but back at home, Stan (my flat mate) and I took a look at the PEP, and suddently It was all clear.
I then wrote this simple decorator:
>>> import thread
>>> def run_threaded(func):
>>> def wrapper(*args):
>>> thread.start_new_thread(func, tuple(args))
>>> return wrapper
To run any function in a seperate thread of execution you'd do this:
>>> import time #just for a sleeping example :)
>>> def looper(x):
>>> for i in xrange(0, x): #gotta love generators :)
>>> print i
will run it in a seperate thread of execution.
With me finally understanding Decorators, I now have just metaclasses left to understand before I can say I'm trully upto step on python 2.4's features. But man... you just gotta love this language... Its sooooo malleable.
I've added the run_threaded decorator to pysystray, but i've not released this version yet... I'm going to refactor the files a bit more, and try to attack one or two more todo's before i release 0.5.0.
Btw, If you're wondering why this is an important addition... Currently, if a MenuItem callback/handler takes too long to complete, it hangs the UI, and the pop-up menu no more shows up. This will also be helpfull for the on_load event handler so it also doesn't lock up the UI.
Oh.. btw, I'm thinking of using the Google API message notifier for pysystray's notifier... If its possible. I'll start groking the SDK next :)