Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

getOpenFile & -filetypes option probem

by merrymonk (Hermit)
on Nov 01, 2007 at 16:07 UTC ( #648505=perlquestion: print w/replies, xml ) Need Help??
merrymonk has asked for the wisdom of the Perl Monks concerning the following question:

Below is a simple Perl/Tk program that creates a button and calls getOpenFile when the button is used.
This has the –filetypes option so that different sets of files can be displayed.
This test works as required in that as the pull down menu for ‘File of type’ is used I see the set of file corresponding to the option chosen.
However, when I use the org_select sub in a bigger application, the pull down menu for file type does not work and any selection results in no files being shown.
Can anyone explain how to overcome this?
use strict "vars"; use Tk; my ($mw); sub org_select { my $filetypes = [ ['Drawing Files', '.drg'], ['All files', '*'] ]; my $select_file_full = $mw->getOpenFile( -filetypes => $filetypes); } $mw = MainWindow->new; $mw->Button(-text => 'Select File', -command => \&org_select )->pack; MainLoop;

Replies are listed 'Best First'.
Re: getOpenFile & -filetypes option probem
by zentara (Archbishop) on Nov 01, 2007 at 17:06 UTC
    Well, you didn't show any code where it dosn't work. I would guess that it might be the odd way you embed your sub in the main code block, before MainLoop is called. I would write it as follows. If you can modify the code below, so it dosn't work right, please post it.
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new; $mw->Button(-text => 'Select File', -command => \&org_select )->pack; MainLoop; sub org_select { my $filetypes = [ ['Drawing Files', '.drg'], ['All files', '*'] ]; my $select_file_full = $mw->getOpenFile( -filetypes => $filetypes); }

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Thank you for the suggestion.
      I have now tried this but it made no difference.
      I would be interested to know why you said
      "it might be the odd way you embed your sub in the main code block"
      since I did not realise that the order of subs etc can affect they way the application works.
      I could not send the whole code for the failing application since this involves the use of a number of library modules.
      However I have tried expanding the test code but the addtional features I added did not make the test case fail!
        It was just a wild guess, because oddities like you experienced are sometimes caused by code being set before the event loop is started, and not being updated properly when called after the MainLoop starts. It probably would be classified as a bug.

        It's really not a good idea to just put subs wherever you want, because nested subs are not seen outside their nest in older versions of Perl (AFAIR) , and I don't know how win32 might handle it. It also could just be that it dosn't look like good style to me. :-)

        It still would be useful if you could post the non-working code. It might be that you may need your filetypes in a global array, or something like that type of glitch.

        I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://648505]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2018-10-18 19:48 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (105 votes). Check out past polls.