from zentara:

-> Now you may not see the usefulness of the entryconfigure or the cget,
-> but what if you had a more complex menu, and needed to dynamically
-> grey out items?

That is exactly what i did (the cascading menus are a recursive tree, with several hundred+ total entries dynamically generated). I want some entries grayed out when some operation is/has been performed and also to completely disappear (and appear) for other reasons. To do this i simply included all the:

-> my $menu = $menubar->cascade(-label => '~File');
->        $menu->command(-label => '~New');
->        $menu->command(-label => '~Open');

inside a subroutine ("scanmenus"), run once initially and then called with:

$mw->bind("<Mouse or Key>"=>sub{scanmenus();$menu->Popup;});
A $mw->Button will also work.

That way, rather than having to use cget and reconfiguring an existing menu, the menu is generated anew every time it pops up (a menubar would be harder; you will have to dynamically "destroy" widgets). Since every instance is just the same as the original (only different) there is no need for additional entryconfigure code. It also means the initial state is not a preformatted default, and deals with:

-> I still havn't figured out how to grey out
-> an arbitrary item in a deeply cascaded menu.

because you would also then need to track the index numbers of these arbitrary items for "entryconfigure" (even more code). Forget entryconfigure; instead, just include a possible -state=>disabled in the "command", governed by a conditional expression in the menu-generating subroutine:

} elsif ( $Ldata !~ /$this1/ ) {
$MM{$this1} = $MM{$this}->command(-label=>"$this1",-command=>[\&dosub, "$this1"]);
} elsif ( $Ldata =~ /$this1/ ) {
$MM{$this1} = $MM{$this}->command(-label=>"$this1",-state=>'disabled');

Note that widget names can be elements of a hash (%MM, the main menu; $this would be a cascade submenu, $this1 an entry). Perl creates the cascaded menu tree (again, hundreds of total entries) instantaneously.

You would have to include your own "my's" (i never "use strict" because i am convinced that declaring a variable LOCALLY should be the exception, not the rule, instead of vice versa w/ strict). But it will still be the same thing...

thanks, b/t/w for the Ternary operator and the "& 1" test

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to