From: Greg M. <gr...@in...> - 2010-01-08 02:29:27
|
Hi, Although this has nothing to do with Pmw, I'd like to point out that you can do this more elegantly (IMHO) by using the Tk.after() command to poll the status of the file. No threads required. I attach a rewrite of Peter's thread example. Greg On Fri 08 Jan 2010 at 10:43:01AM +1100, Peter Milliken wrote: > I can't resist sometimes. Others may find this of interest as I > don't believe there are too many people who know or are aware of the > power offered by the threading module. > > Attached is a small (extremely crudely written!) example of a GUI > that displays a single Tkinter.Text object that shows the last > modified time of a file. The example shows how to create a task > (which modifies and updates the Text GUI element whenever the file > is modified) and a simplistic mechanism for gracefully shutting down > the task when the user wants to close the GUI. The task runs at 1 > second intervals (see time.sleep(1) at line 41). > > The example creates and uses an Event object (again see the > threading module documentation) to control when the thread should > shutdown/exit. There are other mechanisms available - usually my > application code is (much) more complicated than this and I > typically use Queues (see the Queue module documentation) to > communicate parameters and entire messages between various threads > (one of which usually includes a 'stop' indication/message). > > To run this, just create a file called abc.txt in the same directory > where you put trial.py and then run it - change the file contents > using whatever you favourite editor is and watch the GUI display the > new modification time after you save the changed contents. > > Hopes this helps > > Peter > > -----Original Message----- > From: reckoner [mailto:rec...@gm...] > Sent: Friday, 8 January 2010 8:40 AM > To: pmw...@li... > Subject: [Pmw-general] Create auto-updating status window? > > Is it possible to automatically update a gui based upon changes in a > certain file? I know the GUI has a > > root.mainloop() > > call where it polls for user input in the GUI. But, can it also poll for > changes in a separate file, say, when that file is written to? > > I'm trying to create an auto updating GUI that monitors and reacts to > changes in certain files. > > Thanks in advance > > ------------------------------------------------------------------------------ > This SF.Net email is sponsored by the Verizon Developer Community > Take advantage of Verizon's best-in-class app development support > A streamlined, 14 day to market process makes app distribution fast and easy > Join now and get one step closer to millions of Verizon customers > http://p.sf.net/sfu/verizon-dev2dev > _______________________________________________ > Pmw-general mailing list > Pmw...@li... > https://lists.sourceforge.net/lists/listinfo/pmw-general > > Warning: Copyright ResMed. Where the contents of this email and/or attachment includes materials prepared by ResMed, the use of those > materials is subject exclusively to the conditions of engagement between ResMed and the intended recipient. > > This communication is confidential and may contain legally privileged information. > By the use of email over the Internet or other communication systems, ResMed is not waiving either confidentiality of, or legal > privilege in the content of the email and of any attachments. > If the recipient of this message is not the intended addressee, please call ResMed immediately on +61 2 8884 1000 Sydney, Australia. > ------------------------------------------------------------------------------ > This SF.Net email is sponsored by the Verizon Developer Community > Take advantage of Verizon's best-in-class app development support > A streamlined, 14 day to market process makes app distribution fast and easy > Join now and get one step closer to millions of Verizon customers > http://p.sf.net/sfu/verizon-dev2dev > _______________________________________________ > Pmw-general mailing list > Pmw...@li... > https://lists.sourceforge.net/lists/listinfo/pmw-general -- Greg McFarlane "Shower the people you love with love" |