Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

entrycget w/ 'active'
I have a menu which is a list of files, and i want to bind keys so that
multiple actions are available when an entry is active, distinct from the
command which would be invoked by clicking the entry.  I thought the way
to do this would be like this:

#!/usr/bin/perl

use strict;
use Tk;

my $MW = MainWindow->new;
my $menu = $MW -> Menu(-type=>'menubar',-tearoff=>0);
$MW -> configure(-menu=>$menu);
$MW -> bind("<Key-F1>"=>[\&printentry]);

my $MM = $menu -> cascade(-label=>'menu',-underline=>0,-tearoff=>0);
my $one = $MM -> command(-label=>'one',-command=>sub{});
my $two = $MM -> command(-label=>'two',-command=>sub{});
my $three = $MM -> command(-label=>'three',-command=>sub{});

MainLoop;

sub printentry {
my $whM = $menu->entrycget('active','-label');
print "active:$whM\t";
}

The problem:

Using a key would seem to be the only way to go, because if you move off
the menu and click anything the menu disappears or their is no real
active entry.  Unfortunately, using my method the binding only works when
the first level cascade is active (highlighted), before it is clicked,
and never when any cascade is in use.  More unfortunately, 'active' never
returns a value even if "one" is highlighted (active).

Considering this, the use of 'active' as the index, which is documented,
can never actually apply.  Or so it it seems to me.

nb. IF IT DID WORK, i believe ->configure could be used to get the same
information from the active cascade (entrycget cannot).

Report this thread to moderator Post Follow-up to this message
Old Post
MK
03-08-08 12:10 AM


Re: entrycget w/ 'active'
On Mar 7, 7:46 pm, MK <halfcountp...@intergate.com> wrote:
> I have a menu which is a list of files, and i want to bind keys so that
> multiple actions are available when an entry is active, distinct from the
> command which would be invoked by clicking the entry.  I thought the way
> to do this would be like this:
>
> #!/usr/bin/perl
>
> use strict;
> use Tk;
>
> my $MW = MainWindow->new;
> my $menu = $MW -> Menu(-type=>'menubar',-tearoff=>0);
> $MW -> configure(-menu=>$menu);
> $MW -> bind("<Key-F1>"=>[\&printentry]);
>
> my $MM = $menu -> cascade(-label=>'menu',-underline=>0,-tearoff=>0);
> my $one = $MM -> command(-label=>'one',-command=>sub{});
> my $two = $MM -> command(-label=>'two',-command=>sub{});
> my $three = $MM -> command(-label=>'three',-command=>sub{});
>
> MainLoop;
>
> sub printentry {
>         my $whM = $menu->entrycget('active','-label');
>         print "active:$whM\t";
>
> }
>
> The problem:
>
> Using a key would seem to be the only way to go, because if you move off
> the menu and click anything the menu disappears or their is no real
> active entry.  Unfortunately, using my method the binding only works when
> the first level cascade is active (highlighted), before it is clicked,
> and never when any cascade is in use.  More unfortunately, 'active' never
> returns a value even if "one" is highlighted (active).
>
> Considering this, the use of 'active' as the index, which is documented,
> can never actually apply.  Or so it it seems to me.
>
> nb. IF IT DID WORK, i believe ->configure could be used to get the same
> information from the active cascade (entrycget cannot).


Your binding is on $MW only.  To bind to all children and send the
active window, do:
$MW -> bind('all', "<Key-F1>"=>[\&printentry, Tk('W') ]);

sub printentry {
my $wgt = shift;
my $whM = $wgt->entrycget('active','-label');
print "active:$wgt :: $whM\n";
}

This does what you want, but throws an error if no menu entry is
active -  I'll leave that as an exercise for the advanced user.
--S

Report this thread to moderator Post Follow-up to this message
Old Post
smallpond
03-11-08 12:33 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PerlTk archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:08 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.