<?xml version="1.0" encoding="windows-1252"?>
<node id="1006201" title="How to control a Tk::AbstractCanvas with a second one" created="2012-11-29 03:59:56" updated="2012-11-29 03:59:56">
<type id="115">
perlquestion</type>
<author id="850009">
KuntalBhusan</author>
<data>
<field name="doctext">
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.

&lt;p&gt;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.&lt;/p&gt;

My code is something like this :

&lt;code&gt;

$abstractcanvas1  = $SomeFrame-&gt;Scrolled(qw/
       AbstractCanvas -bg white
       -confine 1
       -scrollbars se/,
       )-&gt;pack(-fill   =&gt; 'both',-expand =&gt; 1);


$can = $abstractcanvas2-&gt;Subwidget('scrolled');



$abstractcanvas2  = $SomeFrame-&gt;Scrolled(qw/
       AbstractCanvas -bg white
       -confine 1
       -scrollbars se/,
       )-&gt;pack(-fill   =&gt; 'both',-expand =&gt; 1);


$can = $abstractcanvas2-&gt;Subwidget('scrolled');


## code to display the network in $Canvas1

&lt;/code&gt;


Where should I now use this code part as described in the Module help of Tk::AbstractCanvas

&lt;code&gt;
$abstractcanvas2  = $f_Left-&gt;Scrolled(qw/
       AbstractCanvas -bg white
       -confine 1
       -scrollbars se/,
       )-&gt;pack(-fill   =&gt; 'both',-expand =&gt; 1);

$can_1 = $abstractcanvas2-&gt;Subwidget('scrolled');



$abstractcanvas1-&gt;configure(-changeView =&gt; [\&amp;changeView, $abstractcanvas2]);


  # viewAll if AbstractCanvas2 widget is resized.


  $abstractcanvas2-&gt;CanvasBind('&lt;Configure&gt;' =&gt; sub {$abstractcanvas2-&gt;viewAll});
  {
    my $viewBox;
    sub changeView {
      my ($canvas2, @coords) = @_;
      $canvas2-&gt;delete($viewBox) if $viewBox;
      $viewBox = $canvas2-&gt;createRectangle(@coords, -outline =&gt; 'orange');
    }
  }

&lt;/code&gt;


And how to do it ?? 

Thanks,

Kuntal
</field>
</data>
</node>
