For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > September 2007 > Menu option automatically getting activated on click









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Menu option automatically getting activated on click
nishant

2007-07-26, 8:03 am

Hi ,
I am using the following code snippet -
#!/usr/local/bin/perl
use Tk;
# Main Window
my $mw = new MainWindow;
my $mbar = $mw -> Menu();
$mw -> configure(-menu => $mbar);
my $file = $mbar -> cascade(-label=>"File", -underline=>0, -tearoff =>
0);
$file -> command(-label => "New", -underline=>0,
-command=>[\&menuClicked, "New"] );
$file -> checkbutton(-label =>"Open", -underline => 0,
-command => [\&menuClicked, "Open"]);
$file -> command(-label =>"Save", -underline => 0,
-command => [\&menuClicked, "Save"]);
$file -> separator();
$file -> command(-label =>"Exit", -underline => 1,
-command => sub { exit } );
MainLoop;
sub menuClicked {
my ($opt) = @_;
$mw->messageBox(-message=>"You have clicked $opt.
This function is not implanted yet.");
}





Now, when the window opens up, minimize the window so that you see
only the Menu button -> "File". Take the window to the bottom-right of
the window.Now,when you click on the File menu , the menu opens up and
the option where the mouse has the focus , the function corresponding
to that function gets called up. How do I avoid it ?

Mumia W.

2007-07-26, 8:03 am

On 07/26/2007 05:04 AM, nishant wrote:
> Hi ,
> I am using the following code snippet -
> #!/usr/local/bin/perl
> use Tk;
> # Main Window
> my $mw = new MainWindow;
> my $mbar = $mw -> Menu();
> $mw -> configure(-menu => $mbar);
> my $file = $mbar -> cascade(-label=>"File", -underline=>0, -tearoff =>
> 0);
> $file -> command(-label => "New", -underline=>0,
> -command=>[\&menuClicked, "New"] );
> $file -> checkbutton(-label =>"Open", -underline => 0,
> -command => [\&menuClicked, "Open"]);
> $file -> command(-label =>"Save", -underline => 0,
> -command => [\&menuClicked, "Save"]);
> $file -> separator();
> $file -> command(-label =>"Exit", -underline => 1,
> -command => sub { exit } );
> MainLoop;
> sub menuClicked {
> my ($opt) = @_;
> $mw->messageBox(-message=>"You have clicked $opt.
> This function is not implanted yet.");
> }
>
>
>
>
>
> Now, when the window opens up, minimize the window so that you see
> only the Menu button -> "File". Take the window to the bottom-right of
> the window.Now,when you click on the File menu , the menu opens up and
> the option where the mouse has the focus , the function corresponding
> to that function gets called up. How do I avoid it ?
>


I cannot do this because the program aborts when I shrink the window
down to that size:

> X Error of failed request: BadValue (integer parameter out of range for operation)
> Major opcode of failed request: 12 (X_ConfigureWindow)
> Value in failed request: 0x0
> Serial number of failed request: 324
> Current serial number in output stream: 324
>
> shell returned 1


I'm using Perl 5.8.4 / Tk v800.025 / Linux i386 / Gnome 2.8(?).

Also, what do you mean by "Take the window to the bottom-right of the
window"?

PS.
How do you "implant" a function? ;-)
nishant

2007-07-27, 4:06 am

On Jul 26, 5:14 pm, "Mumia W." <paduille.4061.mumia.w
+nos...@earthlink.net> wrote:
> On 07/26/2007 05:04 AM, nishant wrote:
>
>
>
>
>
> I cannot do this because the program aborts when I shrink the window
> down to that size:
>
>
>
> I'm using Perl 5.8.4 / Tk v800.025 / Linux i386 / Gnome 2.8(?).
>
> Also, what do you mean by "Take the window to the bottom-right of the
> window"?
>
> PS.
> How do you "implant" a function? ;-)


What i mean is that u drag the window and make it small so that only
the "File" menu is viewable.In this case, when u click on "File" ,
then the menu that opens up will be partly above "File" and partly
below "File". Thus it automatically opens one of the options in the
menu on which there is a focus.

Slaven Rezic

2007-09-16, 7:07 pm

nishant <nishant.031@gmail.com> writes:

> Hi ,
> I am using the following code snippet -
> #!/usr/local/bin/perl
> use Tk;
> # Main Window
> my $mw = new MainWindow;
> my $mbar = $mw -> Menu();
> $mw -> configure(-menu => $mbar);
> my $file = $mbar -> cascade(-label=>"File", -underline=>0, -tearoff =>
> 0);
> $file -> command(-label => "New", -underline=>0,
> -command=>[\&menuClicked, "New"] );
> $file -> checkbutton(-label =>"Open", -underline => 0,
> -command => [\&menuClicked, "Open"]);
> $file -> command(-label =>"Save", -underline => 0,
> -command => [\&menuClicked, "Save"]);
> $file -> separator();
> $file -> command(-label =>"Exit", -underline => 1,
> -command => sub { exit } );
> MainLoop;
> sub menuClicked {
> my ($opt) = @_;
> $mw->messageBox(-message=>"You have clicked $opt.
> This function is not implanted yet.");
> }
>
>
>
>
>
> Now, when the window opens up, minimize the window so that you see
> only the Menu button -> "File". Take the window to the bottom-right of
> the window.Now,when you click on the File menu , the menu opens up and
> the option where the mouse has the focus , the function corresponding
> to that function gets called up. How do I avoid it ?
>


Maybe you can use the following hack:

package Tk::Menu;
use Tk::Menu;
my $orig_menu_post;
BEGIN {
$orig_menu_post = \&Tk::Menu::post;
}
if ($Tk::VERSION < 805) {
*post = sub {
my($self, $x, $y) = @_;
if ($y + $self->reqheight > $self->screenheight) {
my $pointery = $self->pointery;
$y = $pointery - 10 - $self->reqheight;
if ($y < 0) {
$y = 0;
}
}
$orig_menu_post->($self, $x, $y);
};
}

Regards,
Slaven

--
Slaven Rezic - slaven <at> rezic <dot> de

tksm - Perl/Tk program for searching and replacing in multiple files
http://ptktools.sourceforge.net/#tksm
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com