Re: Synchronizing two Paned widgets



* ofey aikon <ofey aikon gmail com> [2005-02-25 20:25]:
However, this will result in an infinite loop because the two
widgets will keep changing each others position and executing
the callback forever.

Then don't, unless you need to.

    $hpaned1->signal_connect( 'notify::position' => sub {
        my $pos1 = $hpaned1->get_position;
        my $pos2 = $hpaned2->get_position;
        $hpaned2->set_position( $pos1 ) if $pos1 != $pos2;
    } );

    $hpaned2->signal_connect( 'notify::position' => sub {
        my $pos1 = $hpaned1->get_position;
        my $pos2 = $hpaned2->get_position;
        $hpaned1->set_position( $pos2 ) if $pos1 != $pos2;
    } );

It's not exactly an elegant design since it has a race condition
which may cause extra loops, but as soon as the user stops moving
the mouse, the ping-pong signals will stop too, so who cares. It
works.

Regards,
-- 
#Aristotle
*AUTOLOAD=*_=sub{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]