Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Perl Tk unable to return from MainLoop when implemented in a subroutine

by kevbot (Vicar)
on Mar 23, 2016 at 07:04 UTC ( [id://1158594]=note: print w/replies, xml ) Need Help??


in reply to Perl Tk unable to return from MainLoop when implemented in a subroutine

Hello ngocanh,

Could you post the code that reproduces the problem (as suggested in How do I post a question effectively?)?
  • Comment on Re: Perl Tk unable to return from MainLoop when implemented in a subroutine

Replies are listed 'Best First'.
Re^2: Perl Tk unable to return from MainLoop when implemented in a subroutine
by ngocanh (Novice) on Mar 23, 2016 at 10:12 UTC

    I'm not sure what you want to see, so below is the code for the whole subroutine I'm writing

    The whole reason I have this subroutine is for user to select some items in the @newSeqUnique array and return the selected array to the calling function

    Currently the code is stuck at the MainLoop; statement

    sub getSelectedSeq { my $newSeqUniqueRef = shift; my $grp = shift; my @newSeqUnique = @$newSeqUniqueRef; my @newSeqUniqueSorted = sort{$a->{ID} cmp $b->{ID} || $a->{folder} cmp $b->{folder}} @newSeqUnique; my @displayedArr; my $displayedStr; my @selectedArr; foreach (@newSeqUniqueSorted) { $displayedStr = $_->{ID}." - ".$_->{folder}; push (@displayedArr, $displayedStr); } select STDOUT; foreach (@displayedArr) { print "$_\n"; } # my $mw = MainWindow->new(-title=>"Select sequences"); my $mw = new MainWindow; $mw->Label(-text => "Below is a list of sequences not found in exi +sting group $grp table")->pack(); $mw->Label(-text => "Please select sequences to be added to new ta +ble")->pack(); my $lb = $mw->Scrolled("Listbox", -scrollbars => "osoe", -height =>10, -width => 30, -selectmode => "extended"); my $real_lb = $lb->Subwidget('scrolled'); $real_lb->configure(-borderwidth=>2); $lb->insert("end", @displayedArr); $lb->pack(-fill=>"both"); $mw->Button(-text => "Select", -command => sub{@selectedArr=$lb->curselection;$m +w->destroy();})->pack(); $lb->selectionSet('end'); $lb->see('end'); MainLoop(); foreach (@selectedArr) { print "$_\n"; } my @arr; my @temp; my ($index, $ID, $folder, $obj); if ((@selectedArr)&&(defined $selectedArr[0])) { foreach (@selectedArr) { push (@arr, $newSeqUniqueSorted[$_]); } }else { @arr = (); } return \@arr; }
      I can't replicate your problem. I added use Tk; to the top of the script, and the following to the bottom:
      print %{ getSelectedSeq([{ ID => 1, folder => '/' }, { ID => 2, folder => 'home' }], 12)->[0] };

      I'm getting the output and the program terminates.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

        I have spent more than 1 day on this bug and I have completely no idea why I have this problem. In my program there are also other subroutines which display popup windows but none of them have this problem. I notice that to display other pop-ups I used $main->Show;, probably that's why I never encountered this problem?

        Is there any other way of displaying this selection box without having to write MainLoop; at all? So far I have tried 2 ways as shown in the code but they all hang. I'm using Perl 5.8.4 and I can't install any additional library.

        When I try Tk::exit;, the whole program terminates, not just the GUI :(((

        Can you enlighten me on how I can use dialog box to do the same purpose? :P

        I wanted to use dialog to do this, but could not find any code example on how :(. If can do this with dialog box it would be great!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1158594]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-18 03:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found