Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Perl/Tkx Mousewheel

by chiron (Novice)
on Mar 10, 2009 at 14:23 UTC ( [id://749609]=perlquestion: print w/replies, xml ) Need Help??

chiron has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm writing a perl app that uses mouse events, however i'm stuck trying to get the delta value for the MouseWheel event, supposedly it should be accessible through Tkx::Ev('%D'); however all that it prints is differing array refs, ie Tcl::Ev=ARRAY(0x335715c). Is there anyway i can extract the delta value for mouseevents, here is a cutdown version of the offending code:
use Tkx; $mw = Tkx::widget->new("."); $canvas = $mw->new_tk__canvas; $canvas->g_grid(-column=>0, -row=>0, -sticky=>"nwes"); $mw->g_grid_columnconfigure(0, -weight=>1); $mw->g_grid_rowconfigure(0, -weight=>1); $canvas->g_bind('<Enter>' => sub { Tkx::focus($canvas); }); $canvas->g_bind("<1>", sub { print "Button 1\n"; }); $canvas->g_bind("<Double-1>", sub { print "Button 1x2\n"; }); $canvas->g_bind("<2>", sub { print "Button 2\n"; }); $canvas->g_bind("<3>", sub { print "Button 3\n"; }); $canvas->g_bind("<Double-3>", sub { print "Button 3x2\n"; }); $canvas->g_bind("<MouseWheel>", sub { print Tkx::Ev('%D') . "\n"; +}); Tkx::MainLoop();

Replies are listed 'Best First'.
Re: Perl/Tkx Mousewheel
by Crian (Curate) on Mar 10, 2009 at 14:41 UTC

    In one of my programs i found this lines:

    $mw->bind('<MouseWheel>', [ sub { my $wert = -($_[1]/120); $wert = '+' . $wert unless $wert =~ /^-/; animation_schalten($wert); }, Tk::Ev('D') ] );

    Perhaps it helps?

      $canvas->g_bind("<MouseWheel>", [ sub { my $wert = -($_[1]/120); $wert = '+' . $wert unless $wert =~ /^-/; print $wert . "\n"; }, Tkx::Ev('D') ]);
      just gives me '-0' all the time

        Note: I use Tk::Ev not Tkx::Ev. I don't know, but it might be a difference.

Re: Perl/Tkx Mousewheel
by jethro (Monsignor) on Mar 10, 2009 at 16:07 UTC

    You might use Data::Dumper to show you the contents of the array you are getting, i.e.

    use Data::Dumper; ... $canvas->g_bind("<MouseWheel>", sub { Dumper( Tkx::Ev('%D')) . "\n";

    Presumably the information you are looking for is in that array, just an indirection away

    UPDATE: Tkx::Ev seems to return an object!!! Accessing the array would be a hack, maybe you can find the right accessor in the documentation.

      I've worked out a solution to this problem, however I'm still slightly unsure of whats going on here. Thanks for your help.
      $canvas->g_bind("<MouseWheel>", [ sub { my($D) = @_; print $D . "\n"; +}, Tkx::Ev("%D") ]);

        This seems to be a special two-parameter form for the binding (it uses an anonymous array), where the first parameter (or array value) is the sub as before, and the second furnishes the parameters for the sub. Tkx::Ev just does that. See for this explanation:

        Tkx lets us provide command callbacks as just a Perl function (the first four), or as a two element array (the last case). The first element is the Perl code to be called, while the second array element specifies parameters to pass to that code. The function "Tkx::Ev()" will expand its parameter ("%x %y" in this case) when the callback is invoked, which will perform the percent substitutions. These then are passed as parameters to our function.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-05-22 04:35 GMT
Find Nodes?
    Voting Booth?

    No recent polls found