Path: usenet.cise.ufl.edu!huron.eel.ufl.edu!usenet.eel.ufl.edu!nntp1.jpl.nasa.gov!newsfeed1.earthlink.net!feed2.news.erols.com!erols!chippy.visi.com!news-out.visi.com!nac!nntp.teleport.com!news.teleport.com!not-for-mail
From: Zenin <zenin@best.com>
Newsgroups: comp.lang.perl.announce,comp.lang.perl.misc
Subject: ANNOUNCE: Call for testing new module: Tk::Tie::MenuHash
Followup-To: comp.lang.perl.misc
Date: 27 Feb 1998 16:07:15 GMT
Organization: Zenin's Rocky Horror Archive
Lines: 139
Sender: news-merlyn@gadget.cscaper.com
Approved: merlyn@stonehenge.com (comp.lang.perl.announce)
Message-ID: <6d6obj$kb0$1@news1.teleport.com>
NNTP-Posting-Host: gadget.cscaper.com
X-Disclaimer: The "Approved" header verifies header information for article transmission and does not imply approval of content.
Xref: usenet.cise.ufl.edu comp.lang.perl.announce:84 comp.lang.perl.misc:18167

I've created a new module to ease the use of Tk menubuttons.  It's more of
an abstraction layer over Tk::Menubutton.  The module's perldoc is listed
below.  Please try it out and post any comments you have about it, the name,
the interface, the code, bugs, flames, love letters, etc.  The module's
tar ball can be found at:

	ftp://thrush.omix.com/pub/perl/modules/Tk-Tie-MenuHash-1.9.tar.gz

Standard module install, no C code.  Make test will try to bring up a window
with a menubutton in it.  It's only been tested on FreeBSD, so any feedback
on how it works with other systems would be great.

It also only handles single level menus right now (at least, internally)
because perl only supports single layer tied hashes.  You can still access
them via standard Tk::Menubutton methods however, as they all get mapped to
the real menubutton.

Thanks!

-- 
-Zenin
 zenin@best.com

NAME
    Tk::Tie::MenuHash - Ties a Tk::Menubutton widget to a hash object thingy

SYNOPSIS
      use Tk::Tie::MenuHash;

      my $MB = new Tk::Tie::MenuHash ($Menubutton);
      my $MB = new Tk::Tie::MenuHash (
          $MW->Menubutton (
              -relief       => 'raised',
              -text         => 'Pick something',
              -underline    => 0,
          )->pack (
              -side         => 'left',
          )
      );

      $MB->{'Some lable name'}        = 'default';
      $MB->{'Some list item label'}   = [ \&CommandFunction, 'args' ];
      $MB->{'Some other label'}       = \&CommandFunction;

      delete $MB->{'Some other label'};

      $MB->configure ( -text => 'Pick something else' );

      my $menuText = $MB->{"Anything, it doesn't matter"};

      ##############################################################
      ## Or you can do it this way, but it needs two vars so I don't
      ## recommend it...  It's only useful for prexisting code, IMHO.

      tie my %MB, 'Tk::Tie::MenuHash', $Menubutton;
      ## Or...
      tie my %MB, 'Tk::Tie::MenuHash', $MW->Menubutton (
          -relief       => 'raised',
          -text         => 'Pick something',
          -underline    => 0,
      )->pack (
          -side         => 'left',
      );

      $MB{'Some list item label'}   = [ \&CommandFunction, 'args' ];
      $MB{'Some other label'}       = \&CommandFunction;
      $MB{'Some lable name'}        = 'default';

      delete $MB{'Some other label'};

      $Menubutton->configure ( -text => 'Pick something else' );

      my $menuText = $MB{"Anything, it doesn't matter"};

DESCRIPTION
    Creates a tied Tk::Menubutton widget hash reference object kinda
    thingy....

    It's actually much simplier then it sounds, at least to use. It walks
    and talks half like an object, and half like a (tied) hash reference.
    This is because it's both in one (it's a blessed reference to a tied
    hash of the same class, but don't worry about that).

    When you add a key (label) to the hash it added it to the menubutton.
    The value assigned must be either a valid Tk::Menubutton -command
    option, or the string 'default' (case is not important). The default is
    simply a function that configure()s the Menubuttons -text to that of the
    selected label. You can then retrieve the text by just reading a key
    (any key, even if it doesn't exist, it doesn't matter) from the hash.

    The new() method passes back a reference to a tie()d MenuHash, but with
    all the properties (and methods) of the Menubutton you passed it. With
    this type you can set and delete fields as hash keys references:

            $MenuHash->{'Some label'} = 'default';

    But also call Tk::Menubutton (or sub-classes of it, if that's what you
    passed the constructor) methods:

            $MenuHash->configure ( -text => 'Pick something' );

    This involves black magic to do, but it works. See the AUTOLOAD method
    code if you have a morbid interest in this, however it's more that we
    are dealing with 3 objects in 2 classes.

    I prefer this useage myself as it meens I only need to carry around one
    var that walks and talks almost exactly like a "real" Tk::Menubutton
    (that is, you can call any valid Tk::Menubutton method off it directly),
    but with the added (and much needed IMHO) feature of being able to
    easily add, delete, select, and read menu options as simple hash ref
    keys.

HISTORY
     $Log: MenuHash.pm,v $
     Revision 1.9  1998/02/12 22:15:45  byron
            -More doc changes

     Revision 1.4  1997/12/24 00:39:59  byron
            -Made the 'default' string case independant
            -Modified docs

     Revision 1.3  1997/12/24 00:28:28  byron
            -Fixed class name bug
            -Fixed DESTROY autoload problem

     Revision 1.2  1997/11/22 01:06:45  byron
            -Added new() constuctor, and ability to call widget methods off the tied()
             value reference.

AUTHOR
    Zenin <zenin@best.com>
    aka Byron Brummer <byron@omix.com>

COPYRIGHT
    Copyright (c) 1997,1998 OMIX, Inc.

    Available for use under the same terms as perl.


