in reply to Re^2: Perl-Tk MouseWheel support for Scale
in thread Perl-Tk MouseWheel support for Scale

Well, focusFollowsMouse works on win32 just fine  perl -MTk -le " $mw = tkinit; $mw->Button->pack for 1..3; $mw->  focusFollowsMouse ; MainLoop; "

But are you sure you want to do that?

DynaMouseWheelBind allows scrolling at mouse position without changing focus :P

#~ http://perlmonks.com/?node_id=765209# Re: Perl-Tk MouseWheel and Pa +ne #~ file Tk/DynaMouseWheelBind.pm: #!/usr/bin/perl use Tk; use strict; use warnings; require Tk::DynaMouseWheelBind; my $mw = MainWindow->new(); $mw->geometry('300x300'); my @scrollables = ('Tk::Canvas', 'Tk::Text', 'Tk::Pane', 'Tk::Listbox', ); $mw->DynaMouseWheelBind(@scrollables); my $p = $mw->Scrolled('Pane')->pack(-expand => 1, -fill => 'both'); $p = $p->Subwidget('scrolled'); for (1..20){ $p->Entry->pack; } $p->Scrolled('Listbox')->pack->insert('end',(1..40)); MainLoop(); ##</code><code>## BEGIN { $INC{'Tk/DynaMouseWheelBind.pm'}=__FILE__; require Tk::Widget; package Tk::Widget; use strict; use warnings; # keep Tk::Widgets namespace clean my($motion, $do_scroll, $mousewheel_event, $setup, ); sub DynaMouseWheelBind{ my $w = shift; my @classes = @_; my $mw = $w->MainWindow; $setup->($mw); for my $class (@classes) { eval "require $class" or die $@; # initialize class bindings so the following changes # won't get overridden $class->InitClass($mw); # replace MouseWheel bindings - these should be processed # through the $mw binding only my @mw_events = ('<MouseWheel>', '<4>', '<5>', ); $mw->bind($class,$_,'') for (@mw_events); $mw->bind($class,'<<DynaMouseWheel>>',$do_scroll); } } # setup two bindings to track the window under the cursor # and globally receive <MouseWheel> $setup = sub{ my $mw = shift; $mw->bind('all','<Motion>',$motion); # could be <Enter> as wel +l $mw->bind('all','<MouseWheel>',[$mousewheel_event, Tk::Ev('D') +]); $mw->bind('all','<4>',[$mousewheel_event, 120]); $mw->bind('all','<5>',[$mousewheel_event, -120]); }; { my $under_cursor ; my $scrollable; my $delta; $motion = sub { $under_cursor = $_[0]->XEvent->Info('W'); }; $do_scroll = sub{ $scrollable->yview('scroll', -($delta/120)*3, 'units'); }; $mousewheel_event = sub{ my $widget = shift; $delta = shift; # just in case, the mouse has not been moved yet: my $w = $under_cursor ||= $widget; my @tags = $w->bindtags; my $has_binding; until ($has_binding || $w->isa('Tk::Toplevel')){ if($w->Tk::bind(ref($w),'<<DynaMouseWheel>>')){ $has_binding = 1 ; }else{ $w = $w->parent; } } if ($has_binding) { $scrollable = $w; $w->eventGenerate('<<DynaMouseWheel>>'); } }; } # end of scope for $under_cursor, $scrollable, $delta 1; }

Replies are listed 'Best First'.
Re^4: Perl-Tk MouseWheel support for Scale ( Tk/DynaMouseWheelBind.pm )
by perltux (Monk) on Mar 07, 2015 at 00:33 UTC
    DynaMouseWheelBind does not seem to work with Tk::Scale, I get:

    Tk::Error: Failed to AUTOLOAD 'Tk::Scale::yview' at /usr/lib/perl5/ven +dor_perl/5.10.0/i386-linux-thread-multi/Tk/Submethods.pm line 19 Carp::croak at /usr/lib/perl5/5.10.0/Carp.pm line 44 Tk::Widget::__ANON__ at /usr/lib/perl5/vendor_perl/5.10.0/i386-linux- +thread-multi/Tk/Widget.pm line 347 Tk::Widget::__ANON__ at Tk/DynaMouseWheelBind.pm line 54 <<DynaMouseWheel>> (command bound to event) Tk::Error: Failed to AUTOLOAD 'Tk::Scale::yview' at /usr/lib/perl5/ven +dor_perl/5.10.0/i386-linux-thread-multi/Tk/Submethods.pm line 19


    $mw->focusFollowsMouse seems to work fine with regards to mousewheel support for Scale widgets, but on Windows I get weird dotted boxes around Checkbuttons and Radiobuttons when the mouse passes over them, that persist even after the mouse is already over some other widget. :(

      DynaMouseWheelBind does not seem to work with Tk::Scale, I get:

      Ok, so Tk::Scale is not Scrollable ... no yview ... so you gotta bind your own binding or update the module