BETA TEST: Tk::Tie::MenuHash - Ties a Tk::Menubutton widget to a hash, kinda 
Author Message
 BETA TEST: Tk::Tie::MenuHash - Ties a Tk::Menubutton widget to a hash, kinda

I've created an extention/wraper to Menubutton that (IMHO) makes it easier
to use.  It ties a Menubutton to a hash.  The interface perldoc is listed
below, and the module itself can be found at:

I'd like feed back on all aspects of it.  The interface, bugs, wish lists,
the module name, etc.  Thanks!


----CUT HERE----

    Tk::Tie::MenuHash - Ties a Tk::Menubutton widget to a hash object thingy

      use Tk::Tie::MenuHash;

      my $MB = new Tk::Tie::MenuHash ($Menubutton);
      ## Or, if you don't need the real Menubutton anymore:
      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"};

    Creates a tied Tk::Menubutton widget hash reference object kinda

    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.

     $Log:,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.


    Copyright (c) 1998 OMIX, Inc.

    Available for use under the same terms as perl.

----CUT HERE----

Sun, 13 Aug 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. BETA TEST: Tk::Tie::MenuHash - Ties a Tk::Menubutton widget to a hash, kinda

2. ANNOUNCE: Call for testing new module: Tk::Tie::MenuHash

3. bizarre(?) problem, tied hash of tied hashes

4. Questions to perl/Tk gurus (was: TK Problems with Menu/MenuButton)

5. ANNOUNCE: Tie::Tk::Listbox

6. tie and Tk::Text

7. tk, tie, and textvariable

8. ANNOUNCE: Tie::Registry beta, new Win32API::Registry

9. PERL coredumps with tie but not tied

10. Proposal... Tie::RangeHash or Tie::Range

11. tie a hash in a hash

12. PERL coredumps with tie but not tied


Powered by phpBB® Forum Software