Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

Background. I have a perl script that runs on a win32 machine, k.pl, and it have several .pms located in perl site/lib/k. One of these .pms is a menu .pm and it has a pull down menu option called "select all" for selecting all of the elements on the canvas. It's also worth pointing out the my GUI is Perl Tk.

What I'm trying to do is to have the "select all" command run without the user having to pull down and select it, in one part of k.pl. So far no luck.

Here's the code from menu.pm to select all of the elements on the canvas

$C{'Select All'} = [ command => 'Select All', -command => [ sub { select_all(@_); }, $c ] ]; Here's the select_all sub # # Select all proteins in a canvas. # # Input: $c canvas # Output: - # Global: %global trace_me(); my ($c) = @_; our (%global); Globals->debug(1, "select_all called.\n"); my (@list, $count, $pb, $pct_complete, $step, $tag, $tag_count); @list = grep(/^id/, map { $c->gettags($_) } $c->find('all')); $tag_count = $#list; $step = int($tag_count / 15); $pb = progress_bar({-title => 'Selecting all proteins', -variable => \$pct_complete, }); $pb->Busy(); # Loop through tags and select. foreach $tag (@list) { # Skip if already selected. next if (exists($global{$c}->{selected}->{$tag})); # Change outline to selected. $global{$c}->{selected}->{$tag} = $c->itemcget($tag, '-fill'); $c->itemconfigure($tag, -fill => 'black', -outline => 'blue', -width => 2); $global{$c}->{selected_count}++; $count++; if ($count % $step == 0) { $pct_complete = ($count / $tag_count) * 100; $pb->update(); } } select_update($c); $pb->Unbusy(); $pb->destroy(); }
Any help would be greatly appreciated.

Mark

update (broquaint): added <code> tags and fixed formatting

Replies are listed 'Best First'.
Re: Doing what a menu command would do with out selecting it
by jdtoronto (Prior) on Aug 13, 2003 at 22:51 UTC
    Hi,

    When you select the menu item you specify a subroutine to run. In this code

    $C{'Select All'} = command => 'Select All',<br> -command => [ sub { select_all(@_); }, $c + ];
    You need to work out what is in
    @_
    before the call to select_all, then figure out how to make it work.

    In essence it would seem that this is a scoping issue (without seeing more of the code!).

    ....john

Re: Doing what a menu command would do with out selecting it
by benn (Vicar) on Aug 13, 2003 at 18:59 UTC
    As no Tk experts seem to be forthcoming, (I'm certainly not), I have just one suggestion - have you checked that $c (your canvas?) is being passed into your routine? When called from the menu command, it passes in @_ - maybe that's the canvas being passed into the menu handler.

    just my farthing's worth...
    Ben.

      Ben,
      What would that look like?
      I've inhereted the code, and I'm no master at Perl or Tk.
      Thanks,
      Mark
        Well, presumably somewhere you're calling "select_all". Try calling select_all($canvas), where $canvas is whatever variable is used to store/create your canvas.

        One way to find out what is being passed is to add some debugging - try printing out the value of $c at the top of the "select_all" routine, running the program and using your menu command to 'Select All'. Hopefully you should be able to see what's being passed in, and emulate it in your own "select_all" call.

        Hope this helps,
        Ben.