ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-win32-users
perl-win32-users
RE: Strange Perl/Tk action
by Jack other posts by this author
Oct 25 2009 8:43PM messages near this date
view in the new Beta List Site
RE: Strange Perl/Tk action | RE: Strange Perl/Tk action
Ok. I get it now. First off - sorry for the top post. It's just the way my
mail works.

I don't see the canvas resize on Vista, however I do see it flicker. I don't
doubt that it resizes though, I just cannot reproduce it. I guess the main
question I have is "why are you rebuilding the entire menu just to disable
an entry?". Instead you should just use the entryconfigure method and target
the entry you wish to disable.

Here is one way of doing that (fully working code - just cut, paste and
run):

#######################
use Tk;
use strict;

my $mw=tkinit;
$mw-> Canvas->pack;
create_all_menus_only_once();
MainLoop;

sub create_all_menus_only_once {
  my $menub = $mw-> Menu(-type => "menubar");
  $mw-> configure (-menu => $menub);
  my $submenu = create_menu1($menub);
  $menub-> cascade(
   -label =>  "Edit",
   -underline =>  0,
   -tearoff => 0,
   -menu=> $submenu);
}

sub create_menu1 {
  my $mainmenu = shift;
  my $menu1 = $mainmenu-> Menu(-tearoff=>0);
  #First entry
  $menu1-> command(-label => 'A Switch to B',
-command=> [\&switch,$menu1,'A']);
  #Second entry
  $menu1-> command(-label => 'B Switch to A',
-command=> [\&switch,$menu1,'B'], -state=>'disabled');
  return ($menu1);
}

sub switch {
  my ($m,$val) = @_;

  if ($val eq 'A') {
    $m-> entryconfigure(0,-state=>'disabled');
	$m-> entryconfigure(1,-state=>'normal');
  }
  elsif ($val eq 'B') {
    $m-> entryconfigure(0,-state=>'normal');
	$m-> entryconfigure(1,-state=>'disabled');
  }
}
__END__
#######################

There are "so" many ways to create and manipulate menus - that I could not
cover all the scenarios. In this method, I created the submenu before
creating the "Edit" cascade. This will allow you to use the menu reference
to adjust the entries as you see fit.

There is "no flicker" with this code - so I will guess that it will solve
your resizing issue.

HTH

Jack

-----Original Message-----
From: perl-win32-users-bounces@[...].com
[mailto:perl-win32-users-bounces@[...].com] On Behalf Of
Geoff Horsnell
Sent: October-24-09 5:38 PM
To: 'Jack'; perl-win32-users@[...].com
Subject: RE: Strange Perl/Tk action

Unfortunately, it would be rather a lot of code. I will try to describe the
action with example segments.

...

sub create_all_menus {
  $mode = "A";
  $menub = $tl-> Menu(-type => "menubar");
  $tl-> configure (-menu => $menub);
  $widget1 = menub-> cascade(-label => "Edit, -underline => 0, -tearoff =>
0);
  $widget-> pack(-side => "top", -anchor => "nw");
  &create_menu1 ($widget1);
...
}

sub create_menu1 {
  my $widget = shift;
  
  $state = "disabled";
  if ($mode eq "A") {
    $widget-> command(-label => "B", -underline => 0, -command =>
\&switchToB);
    $widget-> command(-label => "A", -underline => 0, -command =>
\&switchToA, -state =>  $state);
  } else {
    $widget-> command(-label => "B", -underline => 0, -command =>
\&switchToB, -state =>  $state);
    $widget-> command(-label => "A", -underline => 0, -command =>
\&switchToA);
  }
}
...
sub switchToA {
  $mode = "A";
  &create_all_menus (...);  # repaint all menu buttons
}
Sub switchToB {
  $mode = "B";
  &create_all_menus (...);  # repaint all menu buttons
}

After calling the "create_all_menus" from the main program, option "A" is
greyed out and option "B" is active. When "B" is selected for the first
time, option "B" is then greyed out and option "A" is active. At the same
time, the height of the "canvas" window containing these menu buttons is
reduced by about 0.2 cm. Subsequent selection of the "A" or "B" menu option
(whichever is currently active) has no further effect on the size of the
window.

I hope this makes better sense.

TIA

Geoff

-----Original Message-----
From: Jack [mailto:goodcall1@[...].com] 
Sent: Saturday, October 24, 2009 10:51 PM
To: 'Geoff Horsnell'; perl-win32-users@[...].com
Subject: RE: Strange Perl/Tk action


It's hard to follow your description. Can you upload some sample code that
shows the problem?

"Shrinkage is always bad" ;)

Jack
________________________________

From: perl-win32-users-bounces@[...].com
[mailto:perl-win32-users-bounces@[...].com] On Behalf Of
Geoff Horsnell
Sent: October-24-09 10:05 AM
To: perl-win32-users@[...].com
Subject: Strange Perl/Tk action



I have created a GUI using the Tk "canvas" widget that contains a menu list
with two mutually exclusive menu items - say "A" and "B". When "A" is
selected, "B" should be disabled (greyed out) and vice versa. Therefore,
when the currently active option is selected, the menu list needs to be
repainted switching the active and disabled items. However, the first time
that this happens, the height of the canvas window shrinks - by about the
height of the menu tab. The height of the window remains unchanged for all
subsequent menu actions. I have printed out the variable containing the
nominated height of the window before and after making the selection and it
does not change. I can compensate for this action by making the original
window height slightly larger in the first place. However, I would rather
that the shrinkage did not happen at all. Has anyone seen this happen for
themselves and does anyone know how to prevent the window from shrinking in
the first place? 

Any suggestions would be most welcome.

 

Many thanks 

 

Geoff

 







_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Geoff Horsnell
Jack
Geoff Horsnell
Brian Raven
Jack
Geoff Horsnell

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved