Oh Monks, I humble myself in your presence,as it is the first time I have dared seek your wisdom. I am attempting to write a simple "Zoom In/Out" feature for a Tk plotting program, and I am greatly confused.

I have multiple bindings for both mouse buttons, and they are identical in structure. Each button has four bindings: three which control a press/move/release routine, and one double click routine.

All bindings except the double-button-3 one works perfectly, and, when I remove the button-3, the double-button-3 works fine as well. But with the other bindings in place, perl refuses to acknowledge a Double-Right-Click.

Is there any hope for my soul? Or am I doomed to abandon the Double-Right-Click entirely? Why would these bindings work for the left button, but not the right?

Here's the code for each of the bindings. I believe the problem is deeper, as each of these works fine by themselves. First, the Button-1 bindings, which all work fine:
my ($xlock,$ylock); # These keep track of the first coordinate +clicked on $PLOT->CanvasBind("<ButtonPress-1>", [sub { $DRAWING_IN_PROGRESS=1; my ($canv,$x,$y)=@_; ($xlock,$ylock)=($canv->canvasx($x),$canv->can +vasy($y)); $canv->delete("zoombox"); $canv->createRectangle($xlock,$ylock,$xlock,$y +lock,-tag=>"zoombox",-outline=>'lightgray'); }, Ev('x'), Ev('y')]); $PLOT->CanvasBind("<ButtonRelease-1>", [sub { my ($canv,$x,$y)=@_; if ($DRAWING_IN_PROGRESS==1) { $DRAWING_IN_PROGRESS=0; $canv->delete("zoombox"); $xend=$canv->canvasx($x); $yend=$canv->canvasy($y); if ($xlock==$xend || $ylock==$yend){ $canv->delete("zoombox"); return 0; } # Convert back to real coordinates ($X1,$Y1)=(($xend-$xzero)/$xscale,-($yend-$y +zero)/$yscale); ($X2,$Y2)=(($xlock-$xzero)/$xscale,-($ylock- +$yzero)/$yscale); if ($X1==$X2 || $Y1==$Y2) { return 0; } if ($X1<$X2) { $XMAX=$X2; $XMIN=$X1; } else { $XMAX=$X1; $XMIN=$X2; } if ($Y1<$Y2) { $YMAX=$Y2; $YMIN=$Y1; } else { $YMAX=$Y1; $YMIN=$Y2; } plot($plot_f_ref,\$canv,$data_ref); } }, Ev('x'), Ev('y')]); $PLOT->CanvasBind("<Double-Button-1>", [sub { my ($canv,$x,$y)=@_; my ($xm,$ym,$xx,$yx)=($XMIN,$YMIN,$XMAX,$YMAX) +; $x=$canv->canvasx($x); $y=$canv->canvasy($y); ($x,$y)=(($x-$xzero)/$xscale,-($y-$yzero)/$ysc +ale); $XMIN=$x-($xx-$xm)/4; $XMAX=$x+($xx-$xm)/4; $YMIN=$y-($yx-$ym)/4; $YMAX=$y+($yx-$ym)/4; ($XTIC,$YTIC)=($XTIC/2,$YTIC/2); plot($plot_f_ref,\$canv,$data_ref); }, Ev('x'), Ev('y')]);
Here's the Button-3 bindings. Note the similarity to the Double-Button-1 binding:
$PLOT->CanvasBind("<ButtonPress-3>", [sub { my ($canv,$x,$y)=@_; $x=$canv->canvasx($x); $y=$canv->canvasy($y); + $MOVING_IN_PROGRESS=1; $canv->createLine($x,$y,$x,$y,-tag=>'zoombox') +; ($xlock2,$ylock2)=($x,$y) }, Ev('x'), Ev('y')]); $PLOT->CanvasBind("<ButtonRelease-3>", [sub { my ($canv,$x,$y)=@_; if ($MOVING_IN_PROGRESS==1) { $x=$canv->canvasx($x); $y=$canv->canvasy($y); ($x,$y)=(($x-$xzero)/$xscale,-($y-$yzero)/$y +scale); ($xlock2,$ylock2)=(($xlock2-$xzero)/$xscale, +-($ylock2-$yzero)/$yscale); $XMIN=$XMIN+($x-$xlock2); $XMAX=$XMAX+($x-$xlock2); $YMIN=$YMIN+($y-$ylock2); $YMAX=$YMAX+($y-$ylock2); plot($plot_f_ref,$plot_ref,$data_ref); + $MOVING_IN_PROGRESS=0; } }, Ev('x'), Ev('y')]);
And here's the problem child:
$PLOT->CanvasBind("<Double-Button-3>", [sub { print "Button 3 pressed"; my ($canv,$x,$y)=@_; my ($width,$height)=($XMAX-$XMIN,$YMAX-$YMIN); $x=$canv->canvasx($x); $y=$canv->canvasy($y); ($x,$y)=(($x-$xzero)/$xscale,-($y-$yzero)/$ysc +ale); $XMIN=$x-$width; $XMAX=$x+$height; $YMIN=$y-$width; $YMAX=$y+$height; ($XTIC,$YTIC)=($XTIC*2,$YTIC*2); plot($plot_f_ref,\$canv,$data_ref); }, Ev('x'), Ev('y')]);

In reply to Obnoxious Button-3 Binding by critically_damped

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.