For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > February 2006 > Scale: too many calls









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Scale: too many calls
January Weiner

2006-02-14, 7:00 pm

Hi, sorry to bother you again.

I have a fairly complicated graphics + a set of calculations which take
several seconds to draw. I create two Scales to manage some parameters of
the algorithm. To the scales, I bind a redraw command.

The setup works. But when the user touches the scales, and moves them e.g.
from value 10 to 20, you pass, consecutively, through 11..19. Each of
these call the redrawing function, which is not wanted. I would like
somehow to omit the drawing for these values.

I did the following: I bind a "mouse released" event to the scales. The
callback from this event does the redrawing.

This seems to work quite nicely, but maybe there is a more general solution
to such problems? Some kind of sink that collects frequent and similar
events and allows to catch but the last one? This would be very nice e.g.
for catching configure events on a window -- if there are two many, my
program chokes. For example, I have serious troubles when the window
manager is set to display contents while resizing.

Regards,
January

--
------------ January Weiner 3 ---------------------+---------------
Division of Bioinformatics, University of Muenster | Schloßplatz 4
(+49)(251)8321634 | D48149 Münster
http://www.uni-muenster.de/Biologie.Botanik/ebb/ | Germany
Ch Lamprecht

2006-02-14, 7:00 pm

January Weiner wrote:
> Hi, sorry to bother you again.
>
> I have a fairly complicated graphics + a set of calculations which take
> several seconds to draw. I create two Scales to manage some parameters of
> the algorithm. To the scales, I bind a redraw command.
>
> The setup works. But when the user touches the scales, and moves them e.g.
> from value 10 to 20, you pass, consecutively, through 11..19. Each of
> these call the redrawing function, which is not wanted. I would like
> somehow to omit the drawing for these values.
>
> I did the following: I bind a "mouse released" event to the scales. The
> callback from this event does the redrawing.
>
> This seems to work quite nicely, but maybe there is a more general solution
> to such problems? Some kind of sink that collects frequent and similar
> events and allows to catch but the last one? This would be very nice e.g.
> for catching configure events on a window -- if there are two many, my
> program chokes. For example, I have serious troubles when the window
> manager is set to display contents while resizing.
>
> Regards,
> January
>

Hi January,

this is not a general solution, but a short demo how it could be done.
The problem is, that there is no way for the application to determine
which will be the 'last' event. So I used a simple timer here to make
this decision:

use strict;
use warnings;
use Tk;

my $mw = tkinit;
my $text='';
my $lab = $mw->Label(-textvariable=>\$text)->pack;
$mw->Button(-text =>'switch to standard event',
-command=>sub{
$mw->bind('<Motion>',\&process_event);
})->pack;
$mw->Button(-text =>'switch to delayed event',
-command=>sub{
$mw->bind('<Motion>',\&delayed_event);
})->pack;
MainLoop();

{
my $ev;
sub delayed_event{
my $w = shift;
my $timer = 200;
$ev->cancel if $ev;
$ev = $w->after($timer,[\&process_event,$w])
}
}

sub process_event{
my $w= shift;
my $e = $w->XEvent();
my ($x,$y)=($e->x,$e->y);
$text= "x:$x y:$y";
}







--

perl -e "print scalar reverse q/ed.enilno@ergn.l.hc/"
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com