I usually make a progress window that pops up and shows the percent completed. If you can predict or calculate in advance how many "work units" are to be done, I prefer that over just some raw count of lines processed as the user can tell how fast things are going.

Below is one code snippet from something I wrote many moons ago - just to demo the idea. You call something like this within your data processing loop. It is important to note that updating the GUI is an "expensive" operation and you don't want to be going crazy updating it otherwise actual work progress will grind to a snail's pace! Below I check if the percentage value has changed, if not then I return without doing a GUI operation. You will have to decide what kind of "throttle" makes sense for your application. I've got other code with an "abort" button - can't find it right now, but you can check if user has pressed that button and take appropriate action (like exit your processing loop).

When I'm finished with the progress window, I just hide it instead of destroying it. When I need it again, I just put it back on the screen.

sub update_WorkingScreen_Progress { my $ratio = shift; #number like .32 means 32% my $new_percent = int ($ratio*100); #updating screen is expensive computationally #if number hasn't changed, then forget it... #let 0% go through first time if ( ($new_percent == $percent) && ($new_percent > 0)) {return;} $percent = $new_percent; $text = "Program is working - $extra_text...\n\n". "$percent percent complete\n"; $workingScreen->update(); #this is necessary for to #get the new value of $text to display!!!!! }
Update: I am updating this post as perhaps I assumed that you have more control over this cpu intensive loop than you really do? If you don't have much control, then things do get more complex and zentara's post is right on target. However from the problem statement, it sounds to me like you are translating spreadsheet lines into CSV. An Excel spreadsheet can get huge nowadays. But if you can put your program into a loop that say translates X lines at a time (10, 100, or whatever) and call some simple subroutine on each loop iteration, I think you'll be happy. Updating the screen only when you need to will make a HUGE difference.

In reply to Re: TK GUI frozen windows by Marshall
in thread TK GUI frozen windows by fanticla

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.