Training, Open Source computer languages

This is page http://www.wellho.net/forum/The-Tcl- ... guage/Handling-long-running-processes-in-tk.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Handling long running processes in tk

Posted by rgm1960 (rgm1960), 19 September 2005
Hi,
I am creating a gui for a scientific app that has a couple of long running processes. For instance when I push a button "Run", the callback proc of "Run" calls another function (loaded during initialization by doing "load my.dll RunCmd") This function takes about 60sec or so to return and during this whole time the button "Run" stays pushed (active). How do I get the button to be in a normal state immediately after its callback is invoked and instead have my cursor turn to, say an hour glass until the function returns to the tcl script? Any insights will be appreciated. Thanks.
Regards,
Raghu

Posted by admin (Graham Ellis), 20 September 2005
You're looking for the update idletasks command ... and we've an example of it in use in a live application at http://www.wellho.net/resources/ex.php4?item=t221/mb3

In normal running, Tk only updates the display when it has nothing else to do, for the very good reason that you don't want to see you GUI growing slowly as you first build it up, nor see a whole long series of incremental changes flash by you when you take some action that results in (for example) a window being resized.

In cases where you make a selection on the GUI that's going to tie the process up for a while, though, you want to be able to change this behaviour and give an immediate feedback to the user that, yes, his button press was noted and is being acted on.  So add an update idletasks command near the start of the long-to-run process, just after you have made the GUI command calls to alter the display; this forces all pending GUI changes to be actioned

You may want to go further; if you want to give some sort of progress bar for your long rinning process ... let's say it's of the form of a loop that runs 3 times (like my ping example), you could updatethe display every time through the loop.   But be very careful that you don't put the update within a tight loop - it would be very easy to slow down the process as a whole.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho