From: Pavel T. <pau...@ya...> - 2001-07-19 21:44:07
|
Kevin, By running your long task in invokeLater() you explicitly ask for running your task in AWT Event dispatching thread (the same thread that updates GUI). Just call your long task in timer (with no invokeLater) and GUI must update. If you need some data computed by your long tasks to redraw the gui you must synchronize an access to them explicitly. Hope this helps, Pavel --- Kevin McNamee <qk...@lm...> wrote: > > I am trying to use threads so that I can revalidate > some panes while > performing a series of long tasks, i.e. > > long task > update & revalidate pane > long task > update & revalidate pane > etc. > > This would be done in a loop. I have tried several > things: > > synchronize module > ------------------ > This is used with the notify() & wait() methods. > While there are seperate > threads they are not running concurrently. This is > no good, What I need is > synchronous threads. A good example at > http://groups.yahoo.com/group/jpython/message/1641 > > swing.Timer > ----------- > More promising. I started a timer to update the GUI > every 5 seconds and > ran long tasks as > swing.SwingUtilities.invokeLater(task). However, > this > didn't work. It seems the timer is blocked until the > task is completed > (demo attached). > > SwingWorker Class > ----------------- > ? > > > Can someone point me in the right direction here? > Any good examples,links? > > > Any help appreciated, > Kevin > > > > _________________________________________________ > Name/Title : Kevin McNamee, Software Consultant > Phone : +46 13 32 1165 > E-Mail : kev...@er... > > > > from pawt import swing, awt > from java.io import * > from java.lang import Runtime, Runnable > > class GUI: > def __init__(self): > self.timer = None > button = swing.JButton("Start", > actionPerformed=self.do_task) > self.frame = swing.JFrame("Test", > windowClosing=self.do_quit) > self.frame.getContentPane().add(button) > self.frame.setSize(awt.Dimension(100,100)) > self.frame.visible = 1 > > > def do_task(self, event): > if self.timer != None: > self.timer.stop() > self.timer = swing.Timer(1000, repeater()) > self.timer.start() > swing.SwingUtilities.invokeLater(longTask()) > > def do_quit(self, event): > import sys > sys.exit(0) > > class repeater(awt.event.ActionListener): > def actionPerformed(self, evt): > print "Timer Expired" > > class longTask(Runnable): > def run(self): > print "Doing long task" > proc = Runtime.getRuntime().exec('find / -name a') > stdin = proc.getInputStream() > isr = InputStreamReader(stdin) > br=BufferedReader(isr) > line = br.readLine() > while line != None: > line = br.readLine() > print "Finished long task" > > GUI() > > # End of script > __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/ |