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

After becoming the proud new owner of a Logitech Optical Wheel USB/PS2 mouse (which BTW installed beautifully on RH 7.1 Linux) I began exploring ways to add wheel scroll support to my favorite apps which don't support the wheel directly.

Two those apps are Shendai's Tk Monkchat and Tk Newest Nodes.

Monkchat worked perfectly with just the addition of 4 lines of code.

# ## from monkchat.pl # # chatfield $Chatfield = $lframe->Scrolled("ROText", -font => $pgmfont, -width => 20, -height => 2, -bg => $options{'background'}, -wrap => 'word', -relief => 'sunken', -scrollbars => 'osoe', )->pack(-side => 'top', -fill => 'both', -expand => 1); # ## Added 09/09/2001 MitD -- wheel mouse support # $Chatfield->bind("<Button-4>", sub { $Chatfield->yviewScroll(1,"un +its") }); $Chatfield->bind("<Button-5>", sub { $Chatfield->yviewScroll(-1,"u +nits") }); ... $Userlist->bind("<Button-4>", sub { $Userlist->yviewScroll(1,"unit +s") }); $Userlist->bind("<Button-5>", sub { $Userlist->yviewScroll(-1,"uni +ts") });

Unfortunatly Tk Newest Node has proven to be move difficult.

# ## from pmnewnodes.pl # $tree = $uframe->Scrolled("Tree", -width => 80, -height => 5, -background => "$options{background}", -selectbackground => "$options{background}", -itemtype => 'text', -separator => '.', -selectmode => 'single', -relief => 'sunken', -scrollbars => 'osoe', -command => \&command, )->pack(-side => 'top', -fill => 'both', -expand => 1); # ## Added 09/09/2001 MitD -- This code DOES NOT WORK # # $tree->bind("<Button-4>", sub { $tree->yviewScroll(1,"units") }); # $tree->bind("<Button-5>", sub { $tree->yviewScroll(-1,"units") }); #
Tk::Tree does not seem to be supported the same way as other Scrollable widgets (or in Tk Terminalogy Scrolled Widgets).

You can see in the above code that both Monk chat's ROText object and Newest Nodes Tree object are constructed in the same way but when $tree->yviewScroll(... is invoked the method cannot be found for Tk::Tree.

I have looked around Tk::Tree and its parent classes and still come up short.

Any ideas ?? I'll buy beer!

mitd-Made in the Dark
'My favourite colour appears to be grey.'

Replies are listed 'Best First'.
Re: Perl/Tk Mouse wheel support
by Ven'Tatsu (Deacon) on Aug 11, 2001 at 00:03 UTC
    for HList and the Tree derivative you can't use the yviewScroll(...) method to mean yview('scroll', ...)
    You must use the yview('scroll', ...) form:
    $tree->bind("<Button-4>", sub { $tree->yview('scroll',1,"units") } +); $tree->bind("<Button-5>", sub { $tree->yview('scroll',-1,"units") +});
      'Holy LED Sparks!'

      you da man/women/person!

      mitd passes Ven'Tatsu beer while he happly wheels his way through Newest Nodes.

      mitd-Made in the Dark
      'My favourite colour appears to be grey.'

OT - Re: Perl/Tk Mouse wheel support
by blakem (Monsignor) on Aug 11, 2001 at 03:02 UTC
    Totally off topic, but my dad makes the Agilent chips that go inside that mouse. Glad to hear it worked under RH, I didn't know if it would. ;-)

    -Blake

      I think RH 7.1 deals well with a lot of wheel mice. My MS IntelliMouse (PS/2) worked fine on the default install.

      redmist
      Purple Monkey Dishwasher
Re: Perl/Tk Mouse wheel support
by Shendal (Hermit) on Aug 13, 2001 at 19:19 UTC
    I'm glad you found my scripts useful. I haven't looked at them in quite a while, as this new job has kept me really busy. If you send me some diffs on what you've done, I'll add them to the existing scripts online.

    If any other monks out there have done the same, I can add those changes as well. I'm sure there are quite a few divergent versions at this point.

    Cheers,
    Shendal
      This was super helpful. For me the issue was the "MouseWheel" binding didn't work - need to use the <Button-4> and <Button-5> bindings for scrolling different directions... which is somewhat confusing now that mice actually have 5 buttons.