in reply to Stop mouse wheel from moving charts up/down Tk::Scrolled

Like Marshall said, it's a LOT easier to give you help if you provide a complete runnable example of a script demonstrating the problem you are having.

There appears to be two separate problems. First, the pane doesn't seem to get scroll wheel events bound correctly. (Tk::Chart overriding / grabbing them perhaps?) Second, even if the scroll events are bound correctly, if the pane doesn't have focus, it won't receive them.

A kind of hacky fix is to bind the scroll wheel yourself, then make sure anything that grabs focus, releases it to the pane when done.

Add the following lines to the end of your create_mw{} sub:

####################################### bindmousewheel($pane); $pane->focus; for ($datebegin, $dateend, $buttonok) { $_->bind('<Leave>', sub {$pane->focus} ); } #######################################

and add the following bindmousewheel{} sub to your script:

####################################### sub bindmousewheel { my ($w) = @_; if ($^O =~ /Win32/) { $w->bind( '<MouseWheel>' => [ sub { $w->yview( 'scroll', -( $_[1] / 120 ) * 3, 'units' + ); }, Ev('D') ] ); } else { $w->bind( '<4>' => sub { $w->yview( 'scroll', -3, 'units' ) unless $Tk::strictM +otif; } ); $w->bind( '<5>' => sub { $w->yview( 'scroll', +3, 'units' ) unless $Tk::strictM +otif; } ); } } #######################################

With those changes it works for me. (Or at least how I would expect.) Activeperl 5.10.1, WinXP, YMMV

Update: you may need to override the scroll wheel binding for the individual charts and rebind to the pane. I didn't have to with the test script I used, but your circumstances might be different.

Replies are listed 'Best First'.
Re^2: Stop mouse wheel from moving charts up/down Tk::Scrolled
by Marshall (Canon) on Jan 18, 2012 at 20:09 UTC
    I congratulate you on getting the code to run!

    I am also on Active State 5.10.1, WinXP but I am so far unable to get this to run. I see the first chart drawn, then a LONG pause, then abend with output as above.

    Binding specific button presses is tricky.
    So far I haven't gotten to "first base", i.e. getting the OP's code to run. Any suggestions?
    I've never see this: [BE CARREFUL] message before.

      I started looking at it before the OP posted the links to his db, so I just hacked up some dummy data.

      I blanked out the dates and update_data routines since they didn't seem pertinent to the problem:

      sub dates {} sub update_data{}

      Then put in some dummy data at the top just after the @dataX arrays were declared:

      @data0 = @data1 = @data2 = @data3 =([0..200], [300..500]);

      That got me able to run the script to try and troubleshoot. Lots of 'uninitialized' warnings, but it ran at least. Putting "no warnings qw/uninitialized/;" at the top reduced that clutter.

      UPDATE: FWIW here is the actual code I tested with:

      UPDATE 2: Crap. It needs some further modifications to work correctly under Linux. Added some lines to the render{} subroutine to rebind the scroll buttons if you aren't running under Win32.

        Thanks!

        This explains a lot!

        I was just trying to run the OP's claimed "working" code and the OP's .db file. That didn't work. Apparently the reason why this "doesn't work" is because "it simply doesn't work". You modified the data such that it did work. Duh!

        I would ask the OP in a situation like this to post simple runnable code!

        Requiring some Monk like thundergnat to fix the code in order to run it is not the best way.

        I don't use this on a win32 system. It is purely designed to run on Linux. I've shrunk the database: http://pashanoid.ru/code/wind.db and code is http://pashanoid.ru/code/chart.pl these should be in same directory. When the charts are rendered and you hover your mouse over one of the charts and move the mouse wheel, that particular chart will move up or down. How on earth do I stop this???
Re^2: Stop mouse wheel from moving charts up/down Tk::Scrolled
by pashanoid (Scribe) on Jan 23, 2012 at 17:05 UTC

    nope, does not do the trick...

    Database: http://pashanoid.ru/code/wind.db 750kb

    Code: http://pashanoid.ru/code/chart.pl 11k

    When I'm over one of the charts and move the wheel, the chart goes up or down. Please help me stop this silly behavior

Re^2: Stop mouse wheel from moving charts up/down Tk::Scrolled
by pashanoid (Scribe) on Jan 24, 2012 at 09:21 UTC
    nope, does nothing, I'm still able to move the individual charts up and down... thank you for your help though...

      Did you follow the link I posted? Did you download and try the code that was modified to work under Linux? Since you replied to the parent node rather than the node with the actual code or the pointer to it, I assume not.

      It works for me on two different computers running two different Linux distros using two different versions of Perl.

      BTW, it is much easier to follow the conversation if you don't attach follow-up posts to random nodes in the thread.