in reply to Re^2: Stop mouse wheel from moving charts up/down Tk::Scrolled
in thread Stop mouse wheel from moving charts up/down Tk::Scrolled

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.

#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Chart; use Tk::Chart::Lines; use Tk::Canvas::GradientColor; use Tk::Pane; use DBI; use utf8; use Tk::DateEntry; use POSIX qw/strftime/; use Time::Local; no warnings qw/uninitialized/; my ( $mw, $pane ); my ( @data0, @data1, @data2, @data3 ); @data0 = @data1 = @data2 = @data3 = ( [ 0 .. 200 ], [ 300 .. 500 ] ); my $datemin; my $datemax; my $color_start = '#ffffff'; #my $color_end = '#DF776F'; my $color_end = '#bbbbbb'; &dates; my ( $chart0, $chart1, $chart2, $chart3, $xlabelskip ); my ( $powermax, $powermin, $poweravg ); my ( $speedmax, $speedmin, $speedavg, $powersum ); my ( $battmax, $battmin, $battavg ); my ( $powersunmax, $powersunmin, $powersunavg, $powersunsum ); my ( @timeline, @speed, @power, @v_acc, @powersun ); &update_data; &create_mw; &set_charts; &render; MainLoop(); sub draw_charts { $chart0->clearchart; $chart1->clearchart; $chart2->clearchart; $chart3->clearchart; $chart0->destroy; $chart1->destroy; $chart2->destroy; $chart3->destroy; $mw->destroy; &create_mw; &update_data; &set_charts; &render; } sub render { $chart0->plot( \@data0 ); #u akb $chart1->plot( \@data1 ); #sun p $chart2->plot( \@data2 ); #wind p $chart3->plot( \@data3 ); #wind speed unless ($^O =~ /Win32/){ for my $w ( $chart0, $chart1, $chart2, $chart3 ) { $w->CanvasBind( '<4>', sub { $pane->yview( 'scroll', -3, +'units' ); $w->yviewMoveto(0); return;} ); $w->CanvasBind( '<5>', sub { $pane->yview( 'scroll', 3, ' +units' ); $w->yviewMoveto(1); return;} ); } } } sub create_mw { $mw = MainWindow->new(); $mw->geometry("840x800"); $mw->title("SA wind generation from $datemin to $datemax"); $mw->optionAdd( "*font", "*utf-8" ); $mw->fontCreate( 'giant_rus', -family => 'nimbus sans l', -weight => 'normal', -size => int( -13 * 13 / 10 ) ); $mw->fontCreate( 'tiny_rus', -family => 'nimbus sans l', -weight => 'normal', -size => int( -12 * 12 / 10 ) ); $pane = $mw->Scrolled(qw/Pane -scrollbars e -width 990 -height 960 +/)->pack; my $dateframe = $pane->Frame()->pack( -side => 'top', -anchor => 'nw', -padx => +'15' ); my $datelabel = $dateframe->Label( -text => "\x{0414}\x{0438}\x{0430}\x{043f}\x{0430}\x{0439}\x{043e}\x{ +1085}: ", -font => 'giant_rus' )->pack( -side => 'left' ); my @daynames = (); foreach ( 0 .. 6 ) { push @daynames, strftime( "%a", 0, 0, 0, 1, 1, 1, $_ ); } my $datebegin = $dateframe->DateEntry( -font => 'giant_rus', -daynames => \@daynames, -todaybackground => 'green', -textvariable => \$datemin, -formatcmd => sub { sprintf( "%d-%02d-%02d 00:00:00", $_[0], $_[1], $_[2] +); }, -width => 18 )->pack( -side => 'left' ); my $dateend = $dateframe->DateEntry( -font => 'giant_rus', -daynames => \@daynames, -todaybackground => 'green', -textvariable => \$datemax, -formatcmd => sub { sprintf( "%d-%02d-%02d 00:00:00", $_[0], $_[1], $_[2] +); }, -width => 18 )->pack( -side => 'left' ); my $buttonok = $dateframe->Button( -text => 'Ok', -command => \&draw_charts ) ->pack( -side => 'left' ); bindmousewheel($pane); $pane->focus; for ( $datebegin, $dateend, $buttonok ) { $_->bind( '<Leave>', sub { $pane->focus } ); } } sub set_charts { $chart0 = $pane->Lines( -title => "U \x{0430}\x{043a}\x{0431} min: $battmin max: $battmax avg: $battav +g (m/s)", -titlefont => 'giant_rus', -textfont => 'tiny_rus', -titleheight => '5', -xlabelfont => 'tiny_rus', -ylabelfont => 'tiny_rus', -ylabel => 'V', -boxaxis => 1, -yticknumber => 5, -linewidth => 2, -bezier => 1, -alltickview => 1, -pointline => 0, -markers => [ 10, 9, 9 ], -xtickheight => 5, -ylongticks => 1, -ylongtickscolor => 'white', -xlongticks => 1, -xlongtickscolor => 'white', -width => 800, -height => 220, -yminvalue => $battmin, -ymaxvalue => $battmax, -xlabelskip => $xlabelskip, )->pack(); $chart0->enabled_gradientcolor(); $chart0->set_gradientcolor( -start_color => $color_start, -end_color => $color_end, -type => 'linear_vertical', ); $chart3 = $pane->Lines( -title => "\x{0421}\x{043e}\x{043b}\x{043d}\x{0446}\x{0435}\x{0433}\x{0435}\x{04 +3d}\x{0435}\x{0440}\x{0430}\x{0446}\x{0438}\x{044f} min: $powersunmin + max: $powersunmax avg: $powersunavg (Wt) sum: $powersunsum (kWt*h) +", -titlefont => 'giant_rus', -textfont => 'tiny_rus', -titleheight => '5', -xlabelfont => 'tiny_rus', -ylabelfont => 'tiny_rus', -ylabel => 'P', -boxaxis => 1, -yticknumber => 5, -linewidth => 2, -bezier => 1, -alltickview => 1, -pointline => 0, -markers => [ 10, 9, 9 ], -xtickheight => 5, -ylongticks => 1, -ylongtickscolor => 'white', -xlongticks => 1, -xlongtickscolor => 'white', -width => 800, -height => 220, -yminvalue => $powersunmin, -ymaxvalue => $powersunmax, -xlabelskip => $xlabelskip, -colordata => [qw(orange)], )->pack(); $chart3->enabled_gradientcolor(); $chart3->set_gradientcolor( -start_color => $color_start, -end_color => $color_end, -type => 'linear_vertical', ); $chart2 = $pane->Lines( -title => "\x{0412}\x{0435}\x{0442}\x{0440}\x{043e}\x{0433}\x{0435}\x{043d}\x{04 +35}\x{0440}\x{0430}\x{0446}\x{044f} min: $powermin max: $powermax a +vg: $poweravg (Wt) sum: $powersum (kWt*h)", -titlefont => 'giant_rus', -textfont => 'tiny_rus', -titleheight => '5', -xlabelfont => 'tiny_rus', -ylabelfont => 'tiny_rus', -ylabel => 'P', -boxaxis => 1, -yticknumber => 5, -linewidth => 2, -bezier => 1, -alltickview => 1, -pointline => 0, -markers => [ 10, 9, 9 ], -xtickheight => 5, -ylongticks => 1, -ylongtickscolor => 'white', -xlongticks => 1, -xlongtickscolor => 'white', -width => 800, -height => 220, -yminvalue => $powermin, -ymaxvalue => $powermax, -xlabelskip => $xlabelskip, -colordata => [qw(blue)], )->pack(); $chart2->enabled_gradientcolor(); $chart2->set_gradientcolor( -start_color => $color_start, -end_color => $color_end, -type => 'linear_vertical', ); $chart1 = $pane->Lines( -title => "\x{0421}\x{043a}\x{043e}\x{0440}\x{043e}\x{0441}\x{0442}\x{044c} \x{0 +432}\x{0435}\x{0442}\x{0440}\x{0430}min: $speedmin max: $speedmax a +vg: $speedavg (m/s)", -titlefont => 'giant_rus', -textfont => 'tiny_rus', -titleheight => '5', -xlabelfont => 'tiny_rus', -ylabelfont => 'tiny_rus', -ylabel => 'V', -boxaxis => 1, -yticknumber => 5, -linewidth => 2, -bezier => 1, -alltickview => 1, -pointline => 0, -markers => [ 10, 9, 9 ], -xtickheight => 5, -ylongticks => 1, -ylongtickscolor => 'white', -xlongticks => 1, -xlongtickscolor => 'white', -width => 800, -height => 220, -yminvalue => $speedmin, -ymaxvalue => $speedmax, -xlabelskip => $xlabelskip, -colordata => [qw(green)], )->pack(); $chart1->enabled_gradientcolor(); $chart1->set_gradientcolor( -start_color => $color_start, -end_color => $color_end, -type => 'linear_vertical', ); } sub dates { } sub update_data { } 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; } ); } }

Replies are listed 'Best First'.
Re^4: Stop mouse wheel from moving charts up/down Tk::Scrolled
by Marshall (Canon) on Jan 18, 2012 at 20:34 UTC
    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^4: Stop mouse wheel from moving charts up/down Tk::Scrolled
by pashanoid (Scribe) on Jan 23, 2012 at 16:59 UTC
    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???

      Did you look at / try the code I posted the the previous node? Particularly the code I added to the render{} subroutine so it would work under Linux?

      If you download that script and test it, does it act as you would expect? It does for me.