Re: [pysystray-users] Threads and "global variable"
Status: Beta
Brought to you by:
essiene
From: Essien I. E. <es...@da...> - 2006-09-14 17:06:47
|
Christian Keydel wrote: > Thank you Essien for this great tool! > Thanks for the compliment :) Unfortunately, I no more work at a Windows shop so I don't have the need to improve it much... mayhap someone else may be interested in doing this incrementally? At least fixing bugs that crop up in real world scenarios? *hint* *hint* at Greg @ bittorrent ;) > I am stuck at what seems like a simple thing: I have spawned one thread > automatically on load of the taskbar icon. That was easy. Now I need > this thread to change it's behaviour depending on what menu items I > selected. I have a global variable that each menu item can set, but the > thread doesn't see it. > > After what I could google on it it seems the threads run in their own > space. I found some examples for communication between threads but only > for class-threads and not the type function-thread that pysystray uses, > plus it seems complicated. > Indeed threads can't communicate via 'global' anythings really, unless via some complex mechanisms... Windows I think builds up that frame work for threads into a message passing system i think. must have read that somewhere. > What is the most simplistic approach to change a parameter "globally" so > that the thread can see it? I tried a get_val() function but that > doesn't work either and the thread always sees 0. > The way I see, it, what you could do would be to use sockets. On UNIX i would say use socket.AF_LOCAL but in windows, you can just use the normal INET sockets. It seems to me that your on_load thread is the main thread that others can control no? In that case, you can make it a server, that listens for values from clients. Then each of your menu items will do a simple socket.socket(), connect(), send(). The server picks up the message and works with it. You can make this all simple by building a simple module to abstract the client messages, so you could have: foobar.client_send(foobar.COOL_VALUE) then in the server you could do, while 1: msg = foobar_server.get_msg() if msg == foobar.COOL_VALUE: #meh if msg == foobar.UNCOOL_VALUE: #more meh! that's the way I would do it :) Hope that helps. > Cheers, > Chris > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > pysystray-users mailing list > pys...@li... > https://lists.sourceforge.net/lists/listinfo/pysystray-users > |