Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

How to control a Tk::AbstractCanvas with a second one

by KuntalBhusan (Acolyte)
on Nov 29, 2012 at 08:59 UTC ( #1006201=perlquestion: print w/replies, xml ) Need Help??
KuntalBhusan has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I want to create two Tk::Abstract canvases. One (lets call it Canvas1) would display a huge graph (consisting of nodes and edges) and other small canvas (lets call it Canvas2) which will contain a smaller view of the same graph (using the ViewAll function of AbstractCanvas). I want to use some simple interactions like a small rectangle in Canvas2 to scroll and view the big network of Canvas1.

Under the module description part of Tk::Abstract Canvas, I can find the topic "updating a second AbstractCanvas which is displaying the view region of the first AbstractCanvas" and a code example too, but I cannot figure out how to implement the same.

My code is something like this :
$abstractcanvas1 = $SomeFrame->Scrolled(qw/ AbstractCanvas -bg white -confine 1 -scrollbars se/, )->pack(-fill => 'both',-expand => 1); $can = $abstractcanvas2->Subwidget('scrolled'); $abstractcanvas2 = $SomeFrame->Scrolled(qw/ AbstractCanvas -bg white -confine 1 -scrollbars se/, )->pack(-fill => 'both',-expand => 1); $can = $abstractcanvas2->Subwidget('scrolled'); ## code to display the network in $Canvas1
Where should I now use this code part as described in the Module help of Tk::AbstractCanvas
$abstractcanvas2 = $f_Left->Scrolled(qw/ AbstractCanvas -bg white -confine 1 -scrollbars se/, )->pack(-fill => 'both',-expand => 1); $can_1 = $abstractcanvas2->Subwidget('scrolled'); $abstractcanvas1->configure(-changeView => [\&changeView, $abstractcan +vas2]); # viewAll if AbstractCanvas2 widget is resized. $abstractcanvas2->CanvasBind('<Configure>' => sub {$abstractcanvas2- +>viewAll}); { my $viewBox; sub changeView { my ($canvas2, @coords) = @_; $canvas2->delete($viewBox) if $viewBox; $viewBox = $canvas2->createRectangle(@coords, -outline => 'orang +e'); } }
And how to do it ?? Thanks, Kuntal

Replies are listed 'Best First'.
Re: How to control a Tk::AbstractCanvas with a second one
by Anonymous Monk on Nov 29, 2012 at 09:33 UTC

    My code is something like this ...

    Why don't you start with ex/, it shows this exactly?

    Ctrl+MouseRight zooms the first canvas, and the second canvas

    Ctrl+MouseMiddle moves the first canvas, and the second canvas

    LeftMouse rotates the first canvas, doesn't do much for the second :)

      And here it is, busywork

      #!/usr/bin/perl -- use strict; use warnings; use Tk; use Tk::AbstractCanvas; { my $mwin = my $mw = tkinit; my $acnv = $mwin->AbstractCanvas()->pack(-expand => 1, -fill => 'b +oth'); $acnv->controlNav(1); # advanced CtrlKey+MouseDrag Navigation $acnv->rectToPoly(1); $acnv->ovalToPoly(1); my $rect = $acnv->createRectangle( 7, 8, 24, 23, -fill => 'r +ed'); my $oval = $acnv->createOval( 23, 24, 32, 27, -fill => 'gre +en'); my $line = $acnv->createLine( 0, 1, 31, 32, -fill => 'bl +ue', -arrow => 'la +st'); my $labl = $mwin->Label(-text => 'Hello AbstractCanvas! =)'); my $wind = $acnv->createWindow(15, 16, -window => $labl); $acnv->CanvasBind('<x>' => \&exit); $acnv->CanvasFocus(); $acnv->viewAll(); my $c2 = $mwin->Canvas( -background => 'black', #~ -width => 100, #~ -height => 100, #~ -width => 20, #~ -height => 20, -width => 30, -height => 30, ); $c2->createOval(0, 0, 5, 5, -fill => 'white',-tags => ['shabba'] ) +; $mw->bind( $c2, '<ButtonPress-1>' => [ \&shabba , $acnv ]); $c2->place( qw/ -x 10 -y 10 / ); } MainLoop; sub shabba { my( $c2, $acnv ) = @_; #~ my $c2 = $Tk::event->W; my $x = $Tk::event->x; my $y = $Tk::event->y; #~ use Data::Dump; #~ dd [ $c2->configure ], [ $c2->itemconfigure( 'shabba' )] ; $c2->coords( 'shabba', $x, $y , $x+5, $y+5); # size is 5 my $width = $c2->cget('-width'); my $height = $c2->cget('-height'); my $xview = $x / $width; my $yview = $y / $height; $acnv->xviewMoveto( $xview ); $acnv->yviewMoveto( $yview ); }

      See also Tk::Zinc /

      Thanks for the reply....but I actually wanted the reverse...I want to move the orange rectangle in the second canvas (which will have a scaled down view of the original) and the first canvas display should move it possible ?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1006201]
Approved by kcott
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2016-10-23 03:25 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (300 votes). Check out past polls.