From: Jeff E. <jem...@fr...> - 2008-02-08 16:48:01
|
Oops, asyncExec is a function from another GUI toolkit. You want invokeLater. Jeff Emanuel wrote: > Beware that updating the GUI from a thread other than > the event thread can fail or cause corruption. You > may need to do self.refresh() in asyncExec. > > > DOUTCH GARETH-GDO003 wrote: >> Many thanks to all who replied. >> This comment by Jeff Emanuel was the clue that I needed. >> In the end the fix looked like this: >> >> class SomePanel(swing.JPanel) >> def buildUI(self): >> self.add(swing.JButton('Update', actionPerformed=self.update)) >> >> def update(self, event): >> import threading >> t = threading.Thread(target=self.__update) >> t.start() >> >> def __update(self): >> self.safety(True) # disable the ui from further inputs >> long_running_process() # run the long process >> self.refresh() # update with fresh info from the >> process >> self.safety(False) # re-able the ui for further inputs >> >> And that works! >> >> Regards, >> Gareth >> >> >> >> -----Original Message----- >> From: Jeff Emanuel [mailto:jem...@fr...] >> Sent: 07 February 2008 18:22 >> To: DOUTCH GARETH-GDO003 >> Cc: jyt...@li... >> Subject: Re: [Jython-users] Swing JButton dispatch long processes on >> thread? >> >> join() blocks until the thread completes. >> >> DOUTCH GARETH-GDO003 wrote: >>> Hi, >>> >>> Want to dispatch a long running process from a JButton and while it is >>> running: >>> * release the JButton from it's depressed state >>> * update my UI into a 'busy / wait' state until the process finishes >>> when I will return my UI into it's normal state. >>> >>> But there's something basic that I am missing here, can anyone help? >>> >>> Regards, >>> Gareth >>> >>> >>> Samples of my have attempts: >>> >>> class SomePanel(swing.JPanel) >>> def buildUI(self): >>> self.add(swing.JButton('Update', actionPerformed=self.update)) >>> >>> def update(self, event): >>> import threading >>> self.safety(True) # disable the ui from further inputs >>> t = threading.Thread(target=long_running_process) >>> t.start() >>> t.join() >>> self.refresh() # update with fresh info from the process >>> >>> self.safety(False) # restore user inputs >>> >>> >>> and >>> >>> def update(self, event): >>> self.safety(True) # disable the ui from further inputs >>> long_running_process() >>> self.refresh() # update with fresh info from the process >>> >>> self.safety(False) # restore user inputs >>> >>> >>> >>> >>> ---------------------------------------------------------------------- >>> -- >>> >>> ---------------------------------------------------------------------- >>> --- This SF.net email is sponsored by: Microsoft Defy all challenges. >>> Microsoft(R) Visual Studio 2008. >>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >>> >>> >>> ---------------------------------------------------------------------- >>> -- >>> >>> _______________________________________________ >>> Jython-users mailing list >>> Jyt...@li... >>> https://lists.sourceforge.net/lists/listinfo/jython-users >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2008. >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> _______________________________________________ >> Jython-users mailing list >> Jyt...@li... >> https://lists.sourceforge.net/lists/listinfo/jython-users > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |