access to Menubar menu items 
Author Message
 access to Menubar menu items

There has to be a simple answer to this one.... that's why
its eluded me for days!

I have a reference to an Apps menubar,  How do I get access
to the cascade menus it contains to change  particular
menubutton  -state 's to 'disabled' based on the
application's state?

John

--



Sat, 24 Aug 2002 03:00:00 GMT  
 access to Menubar menu items

Quote:

> There has to be a simple answer to this one.... that's why
> its eluded me for days!
> I have a reference to an Apps menubar,  How do I get access
> to the cascade menus it contains to change  particular
> menubutton  -state 's to 'disabled' based on the

Do you mean menubutton or menu item?

Quote:
> application's state?

If we're talking new-style Tk8 "menu system" stuff, then the
cascades-which-act-as-menubuttons each have a menu, which cget()
can access. If you follow the code below, it works its way down
three cascade levels to the Image menu.

Once you have any 'ol menu, use entrycget() to configure an individual
menu item.

As alway, posting code helps bunches...

#!/usr/local/bin/perl -w

use Tk 800.000;
use subs qw/edit_menuitems file_menuitems help_menuitems/;
use strict;

my $mw = MainWindow->new;
$mw->configure(-menu => my $menubar = $mw->Menu);

# Create the menubar's menubuttons.

map {$menubar->cascade( -label => '~' . $_->[0], -menuitems => $_->[1] )}
     ['File', file_menuitems],
     ['Edit', edit_menuitems],
     ['Help', help_menuitems];

if ($^O eq 'MSWin32') {
    my $syst = $menubar->cascade(-label => '~System');
    my $dir = 'dir | sort | more';
    $syst->command(
        -label   => $dir,
        -command => sub {system $dir},
    );

Quote:
}

my $file_menu = $menubar->entrycget('File', -menu);
my $new_menu = $file_menu->entrycget('New', -menu);
my $image_menu = $new_menu->entrycget('Image', -menu);
print "File=$file_menu, New=$new_menu, Image=$image_menu\n";

MainLoop;

sub edit_menuitems {
    [
      ['command', 'Preferences ...'],
    ];

Quote:
}

sub file_menuitems {

    # Create the menu items for the File menu.

    my($motif, $bisque) = (1, 0);
    my $new_image_format = 'png';

    [
      [qw/cascade ~New   -accelerator Ctrl-n -menuitems/ =>
        [
          ['checkbutton', 'Strict Motif', -variable => \$motif],
          ['checkbutton', 'Bisque',       -variable => \$bisque],
          [qw/command Widget/], '',
          [qw/cascade Image -tearoff 0 -menuitems/ =>
            [
              map ['radiobutton', $_, -variable => \$new_image_format],
                  qw/bmp ppm gif png jpg tif/,
            ],
          ],
        ],
      ],                                                      '',
      [qw/command ~Open  -accelerator Ctrl-o/],               '',
      [qw/command ~Save  -accelerator Ctrl-s/],
      [qw/command/, 'S~ave As ...', qw/-accelerator Ctrl-a/], '',
      [qw/command ~Close -accelerator Ctrl-w/],               '',
      [qw/command ~Quit  -accelerator Ctrl-q -command/ => \&exit],
    ];

Quote:
} # end file_menuitems

sub help_menuitems {
    [
      ['command', 'Version', -command => sub {print "Version\n"}],
      '',
      ['command', 'About',   -command => sub {print "About\n"}],
    ];
Quote:
}



Sat, 24 Aug 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Tk 8 menubar item arrangement

2. Add Tick Mark Check button to Menubar items

3. Graying out menu items

4. activate menu items

5. Menu - long item list

6. referencing items on cascade menu?

7. Index Of Nested Menu Items

8. Getting cascade menu item to not automaticly post

9. Please Help: deleting menu items

10. "Greyed-out" menu items

11. Deleting Menu Items?

12. callback for parent of child menu item

 

 
Powered by phpBB® Forum Software