I would also suggest using a class to encapsulate all computations with all its internal variables like y which get updated whenever something is done internally and are never exposed. The class could have a stop() method which will interrupt any loops via a stop-flag for example.
Passing a ref to a method in the class, e.g. in
my $plot = $mw->Button(-text=>'Plot', -command=>\&init) ->pack(-side=>'left');
can be done like:
my $computator = Computator->new($p, $mw, whatever ...); $computator->reset(); my $plot = $mw->Button(-text=>'Plot', -command=>sub { $computator->ini +t()} ) ->pack(-side=>'left'); # create a stop-button my $stop = $mw->Button(-text=>'Stop', -command=>sub { $computator->sto +p()}) ->pack(-side=>'left');
Warning, my Tk skills are minimal.
What I do not like is that the side-effect of the long computation seems to go away when you break the long computation in a lot of per-row computations. But this is very subjective to given photo size, host computer speed, Tk internals.
Can you not tell Tk to process event queue every time you complete the innermost loop? So as to have long loops without Tk becoming unresponsive?
If that fails, spawning a thread to do the long computation sounds to me like a good idea but it's tricky and it may open a can of worms, as per Perl Tk and Threads
In reply to Re: long computation in TK
by bliako
in thread long computation in TK
by BillKSmith
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |