Re: Tk::Pane yview - Perl
This is a discussion on Re: Tk::Pane yview - Perl ; Hello,
I try to bind the mouse wheel to the scrollbar of a Tk::Pane. I use
example code from the book 'Mastering Perl/Tk' (see below). However, it
doesn't work in conjunction with the pane. I get "Failed to AUTOLOAD
'Tk::Frame::yview'". ...
-
Re: Tk::Pane yview
Hello,
I try to bind the mouse wheel to the scrollbar of a Tk::Pane. I use
example code from the book 'Mastering Perl/Tk' (see below). However, it
doesn't work in conjunction with the pane. I get "Failed to AUTOLOAD
'Tk::Frame::yview'". It does work with a Scrolled() text widget. I am
aware that a Frame/Pane is different from normal widgets. But as far as
I can see, Pane.pm supports the yview method. So what is going on, and
how can the desired behaviour be achieved?
I have only tested it on Win32 so far: perl v5.8.6, Tk 804.027.
Thank you!
Martin
--example code--
#!/usr/local/bin/perl -w
use Tk;
use Tk::Pane;
use strict;
use Data:
umper;
my $mw = MainWindow->new;
=pod
# these two work
my $t = $mw->Text->pack;
$t->insert('end', "line $_\n") for (1 .. 200);
my $t = $mw->Scrolled('Text',-scrollbars=>'osoe')->pack();
$t->insert('end', "line $_\n") for (1 .. 200);
=cut
# doesn't
my $t = $mw->Scrolled('Pane',-scrollbars=>'osoe')->pack();
$t->Label(-text=>"line $_\n")->pack() for (1 .. 20);
$t->focus;
&BindMouseWheel($t);
MainLoop;
sub BindMouseWheel {
my($w) = @_;
if ($^O eq 'MSWin32') {
$w->bind('<MouseWheel>' =>
[ sub { $_[0]->yview('scroll', -($_[1] / 120) * 3, 'units') },
Ev('D') ]
);
} else {
# Support for mousewheels on Linux commonly comes through
# mapping the wheel to buttons 4 and 5. If you have a
# mousewheel ensure that the mouse protocol is set to
# "IMPS/2" in your /etc/X11/XF86Config (or XF86Config-4)
# file:
#
# Section "InputDevice"
# Identifier "Mouse0"
# Driver "mouse"
# Option "Device" "/dev/mouse"
# Option "Protocol" "IMPS/2"
# Option "Emulate3Buttons" "off"
# Option "ZAxisMapping" "4 5"
# EndSection
$w->bind('<4>' => sub {
$_[0]->yview('scroll', -3, 'units') unless $Tk::strictMotif;
});
$w->bind('<5>' => sub {
$_[0]->yview('scroll', +3, 'units') unless $Tk::strictMotif;
});
}
} # end BindMouseWheel
-
Re: Tk::Pane yview
Martin Mohr wrote:
> Hello,
>
> I try to bind the mouse wheel to the scrollbar of a Tk::Pane. I use
> example code from the book 'Mastering Perl/Tk' (see below). However, it
> doesn't work in conjunction with the pane. I get "Failed to AUTOLOAD
> 'Tk::Frame::yview'". It does work with a Scrolled() text widget. I am
> aware that a Frame/Pane is different from normal widgets. But as far as
> I can see, Pane.pm supports the yview method. So what is going on, and
> how can the desired behaviour be achieved?
>
> I have only tested it on Win32 so far: perl v5.8.6, Tk 804.027.
The Pane doesn't seem to pass MouseWheel events to the apropriate
subwidget. Change the lines below to get it to work under Windows.
Not sure what changes, if any, may be necessary to get it to work
under Linux.
>
> Thank you!
>
> Martin
>
> --example code--
>
> #!/usr/local/bin/perl -w
> use Tk;
> use Tk::Pane;
> use strict;
> use Data:
umper;
>
> my $mw = MainWindow->new;
>
> =pod
>
> # these two work
>
> my $t = $mw->Text->pack;
> $t->insert('end', "line $_\n") for (1 .. 200);
>
> my $t = $mw->Scrolled('Text',-scrollbars=>'osoe')->pack();
> $t->insert('end', "line $_\n") for (1 .. 200);
>
> =cut
>
> # doesn't
>
> my $t = $mw->Scrolled('Pane',-scrollbars=>'osoe')->pack();
> $t->Label(-text=>"line $_\n")->pack() for (1 .. 20);
>
> $t->focus;
> &BindMouseWheel($t);
>
> MainLoop;
>
> sub BindMouseWheel {
>
> my($w) = @_;
>
> if ($^O eq 'MSWin32') {
> $w->bind('<MouseWheel>' =>
# [ sub { $_[0]->yview('scroll', -($_[1] / 120) * 3, 'units') },
# Ev('D') ]
[ sub {
if ($_[0]->isa('Tk::Frame') and ($_[0]->Parent)->isa('Tk::Pane')) {
$_[0] = $_[0]->Parent;
}
$_[0]->yview('scroll', -($_[1] / 120) * 3, 'units') },
Ev('D')]
> );
> } else {
>
> # Support for mousewheels on Linux commonly comes through
> # mapping the wheel to buttons 4 and 5. If you have a
> # mousewheel ensure that the mouse protocol is set to
> # "IMPS/2" in your /etc/X11/XF86Config (or XF86Config-4)
> # file:
> #
> # Section "InputDevice"
> # Identifier "Mouse0"
> # Driver "mouse"
> # Option "Device" "/dev/mouse"
> # Option "Protocol" "IMPS/2"
> # Option "Emulate3Buttons" "off"
> # Option "ZAxisMapping" "4 5"
> # EndSection
>
> $w->bind('<4>' => sub {
> $_[0]->yview('scroll', -3, 'units') unless $Tk::strictMotif;
> });
>
> $w->bind('<5>' => sub {
> $_[0]->yview('scroll', +3, 'units') unless $Tk::strictMotif;
> });
> }
>
> } # end BindMouseWheel
>
-
Re: Tk::Pane yview
thundergnat schrieb:
> The Pane doesn't seem to pass MouseWheel events to the apropriate
> subwidget. Change the lines below to get it to work under Windows.
> Not sure what changes, if any, may be necessary to get it to work
> under Linux.
Hello,
thank you! This works very well. I applied the same changes to the two
Linux subs and there it also works, if the mouse is over some empty room
in the pane. Maybe Slaven Rezic will come up with a solution for this in
the german group de.comp.lang.perl.misc.
Bye
Martin
-
Re: Tk::Pane yview
thundergnat <thundergnat@hotmail.com> wrote:
> Martin Mohr wrote:
> > Hello,
> >
> > I try to bind the mouse wheel to the scrollbar of a Tk::Pane. I use
> > example code from the book 'Mastering Perl/Tk' (see below). However, it
> > doesn't work in conjunction with the pane. I get "Failed to AUTOLOAD
> > 'Tk::Frame::yview'". It does work with a Scrolled() text widget. I am
> > aware that a Frame/Pane is different from normal widgets. But as far as
> > I can see, Pane.pm supports the yview method. So what is going on, and
> > how can the desired behaviour be achieved?
> >
> > I have only tested it on Win32 so far: perl v5.8.6, Tk 804.027.
>
>
> The Pane doesn't seem to pass MouseWheel events to the apropriate
> subwidget. Change the lines below to get it to work under Windows.
> Not sure what changes, if any, may be necessary to get it to work
> under Linux.
A Tk::Frame widget has no yview method, hence the error. Bind the the
Scrolled widget (the Pane) rather than the Frame. Use Subwidget to get
the widget reference of the scrolled widget (untested):
my $pane = $$->Subwidget( 'sccrolled' );
Now bind to $pane rather than $t. Should work, because I used Scrolled
Panes all the time ...
>
>
> >
> > Thank you!
> >
> > Martin
> >
> > --example code--
> >
> > #!/usr/local/bin/perl -w
> > use Tk;
> > use Tk::Pane;
> > use strict;
> > use Data:
umper;
> >
> > my $mw = MainWindow->new;
> >
> > =pod
> >
> > # these two work
> >
> > my $t = $mw->Text->pack;
> > $t->insert('end', "line $_\n") for (1 .. 200);
> >
> > my $t = $mw->Scrolled('Text',-scrollbars=>'osoe')->pack();
> > $t->insert('end', "line $_\n") for (1 .. 200);
> >
> > =cut
> >
> > # doesn't
> >
> > my $t = $mw->Scrolled('Pane',-scrollbars=>'osoe')->pack();
> > $t->Label(-text=>"line $_\n")->pack() for (1 .. 20);
> >
> > $t->focus;
> > &BindMouseWheel($t);
> >
> > MainLoop;
> >
> > sub BindMouseWheel {
> >
> > my($w) = @_;
> >
> > if ($^O eq 'MSWin32') {
> > $w->bind('<MouseWheel>' =>
> # [ sub { $_[0]->yview('scroll', -($_[1] / 120) * 3, 'units') },
> # Ev('D') ]
>
> [ sub {
> if ($_[0]->isa('Tk::Frame') and ($_[0]->Parent)->isa('Tk::Pane')) {
> $_[0] = $_[0]->Parent;
> }
> $_[0]->yview('scroll', -($_[1] / 120) * 3, 'units') },
> Ev('D')]
>
> > );
> > } else {
> >
> > # Support for mousewheels on Linux commonly comes through
> > # mapping the wheel to buttons 4 and 5. If you have a
> > # mousewheel ensure that the mouse protocol is set to
> > # "IMPS/2" in your /etc/X11/XF86Config (or XF86Config-4)
> > # file:
> > #
> > # Section "InputDevice"
> > # Identifier "Mouse0"
> > # Driver "mouse"
> > # Option "Device" "/dev/mouse"
> > # Option "Protocol" "IMPS/2"
> > # Option "Emulate3Buttons" "off"
> > # Option "ZAxisMapping" "4 5"
> > # EndSection
> >
> > $w->bind('<4>' => sub {
> > $_[0]->yview('scroll', -3, 'units') unless $Tk::strictMotif;
> > });
> >
> > $w->bind('<5>' => sub {
> > $_[0]->yview('scroll', +3, 'units') unless $Tk::strictMotif;
> > });
> > }
> >
> > } # end BindMouseWheel
> >
--
--
@_=map{eval"100${_}"}split/!/,'/5!*2!+$]!/10+$]';use Tk;$m=tkinit;$t='just an'.
'other perl hacker';$z='createText';$c=$m->Canvas(-wi,$_[1],-he,25)->grid;$c->$
z(@_[2,3],-te,$t,-fi,'gray50');$c->$z($_[2]-$],$_[3]-$],-te,$t);$m->bind('<En'.
'ter>',sub{$y=int(rand($m->screenheight));$m->geometry("+$y+$y")});MainLoop;
Similar Threads
-
By Application Development in forum Pine
Replies: 0
Last Post: 10-31-2007, 11:13 PM
-
By Application Development in forum TCL
Replies: 0
Last Post: 05-06-2007, 11:38 PM
-
By Application Development in forum Perl
Replies: 13
Last Post: 03-14-2007, 02:22 PM
-
By Application Development in forum Microsoft Exchange
Replies: 1
Last Post: 02-21-2005, 02:57 AM
-
By Application Development in forum Microsoft Exchange
Replies: 1
Last Post: 01-07-2004, 04:51 AM