On 30.11.2009 15:12, Joonas Pulakka wrote:
2009/11/29 Alex Grönholm <alex.gronholm@nextday.fi>
On 25.11.2009 13:27, Joonas Pulakka wrote:

Swing's thread policy has apparently been getting stricter over years, and as mentioned for example here: http://stackoverflow.com/questions/491323/is-it-safe-to-construct-swing-awt-widgets-not-on-the-event-dispatch-thread 

It's "illegal" to even _construct_ Swing widgets outside the event dispatch thread, let alone manipulate them. In other words, code like this http://jythonpodcast.hostjava.net/jythonbook/chapter16.html works, strictly speaking, only by coincidence, unless the code is explicitly launched on the EDT - and generally it isn't.

This is a pity, since Jython's other features regarding Swing are quite nice, making the code concise and clear. Is there a simple workaround this? Should some "thread safety help" be built into core Jython? How have you people dealt with this issue - building workarounds, or simply Swinging outside the EDT by luck?
Check out my jython-swingutils for a fairly clean solution to this: http://bitbucket.org/agronholm/jython-swingutils/ (particularly the dispatch module).


Looks like jython-swingutils might have lots of potential to it. Anyway, I would appreciate some usage examples. Say, from http://jythonpodcast.hostjava.net/jythonbook/chapter16.html ,

Examples will follow when I have time to work on the documentation.
button = JButton('Click Me!', actionPerformed=change_text)

How exactly would this be implemented using the Dispatch module? Note that this includes both 1) creating a new component, and 2) calling an existing component. Both things should happen on the EDT.
Put all of that code in a function, and decorate it with @invokeLater. Then all you have to do is execute that function.

And by the way, is there any official license for jython-swingutils? Similar to http://www.jython.org/license.html ?
I haven't decided if it's MIT or LGPL. I'll probably be leaning towards MIT though (seeing as how it's almost identical to the PSF license).