in reply to Re^2: FBox, getOpenFile, -multiple
in thread FBox, getOpenFile, -multiple

ActiveStatePerl is the easiest way to go, and Tk is automatically included in ActiveStatePerl. The one drawback to ActiveState is the need to get precompiled ppms for the various binary modules, it's very hard to compile them yourself. If you are looking for something that will allow you to compile your binary modules, see Are you using Vanilla/Strawberry Perl? Tell me about it!

Most people have little trouble with running Tk on ActiveState ( there are the minor incompatibilities).

You can also avoid using getopenfile on windows with something like the following:

#!/usr/bin/perl use strict; use Tk; require Tk::DirTree; require Tk::Adjuster; require Tk::TList; # The initial directory my $initial_dir = '/'; # The main window... my $main = new MainWindow( -title => 'Explorer)' ); # A frame for the tree, adjuster and tlist my $tree_adj_tablist = $main->Frame(); $tree_adj_tablist->pack( -expand => 'yes', -fill => 'both', -side => 'top' ); # A scrolled directory tree my $tree = $tree_adj_tablist->Scrolled( 'DirTree', -width => 35, -height => 25, -scrollbars => 'osoe', -background => 'White', -selectmode => 'single', -selectbackground => 'DarkBlue', -selectforeground => 'White', -showhidden => 1, -directory => $initial_dir ); $tree->pack( -expand => 'yes', -fill => 'both', -padx => 2, -pady => 2, -side => 'left' ); # An adjuster my $adjuster = $tree_adj_tablist->Adjuster( -widget => $tree, -side => 'left' ); $adjuster->pack( -side => 'left', -fill => 'y' ); # A scrolled tab_list widget my $tab_list = $tree_adj_tablist->Scrolled( 'TList', -background => 'White', -orient => 'vertical', -selectmode => 'extended', -scrollbars => 'os' ); $tab_list->pack( -expand => 'yes', -fill => 'both', -padx => 2, -pady => 2, -side => 'right' ); # Ok button my $ok = $main->Button( -text => 'Ok', -underline => 0, -width => 4, -command => sub { my $selected = $tab_list->info('selection'); #print "@{$selected}\n"; foreach( @{$selected} ){ print $tab_list->entrycget($_, '-text'),"\n"; } })->pack( -side => 'right', -padx => 10, -pady => 10 ); # A Quit button (will be suppressed???...) my $quit = $main->Button( -text => 'Quit', -underline => 0, -width => 6, -command => sub { exit } ); $quit->pack( -side => 'right', -padx => 10, -pady => 10 ); # Configuring tree and tab_list widgets... $tree->configure( -browsecmd => sub { list_dir( $tab_list, @_ ); } ); # We list the content of the initial dir inside the tab_list list_dir( $tab_list, $initial_dir ); MainLoop(); #--------------------------------------------------------------------- +------- # Displays Dirs and files in TList widget sub list_dir { my ( $tab_list, $path ) = @_; # Erase the TList content $tab_list->delete( 0, 'end' ); opendir MY_DIR, $path or return; foreach my $file ( sort readdir(MY_DIR) ) { # Do not display '.' and '..' next if ( $file eq '.' or $file eq '..' ); # Insert the files in the TList $tab_list->insert( 'end', -text => $file ); } closedir MY_DIR; }

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

Replies are listed 'Best First'.
Re^4: FBox, getOpenFile, -multiple
by Anonymous Monk on Jan 30, 2007 at 16:01 UTC
    thanks so much for the sample code. i'm still a little confused... you say that (mostly) Tk under ActiveState runs fine - does that imply that it does not use Win32? i'm not making the connection on where Win32 fits into the picture. I thought it would be necessary for any/all Tk calls (when i include the TK package, i thought the Win32 got included too).

    also, this might be a dumb question, but why does your code execute fine when activestate executes it, but not when cygwin's perl executes it. with cygwin, the code runs, by a window, nor an error msg, ever appear. i eventually just kill'ed the process.

    hope i'm not being too dense here. thanks for your time.

      Tk on ActiveState runs pretty much the same as on linux. There are a few bugs, most noticed is that on win32 , select only works on socket filehandles, but not on pipes, so IPC is a pain in the A** unless you use sockets or shared mem for the IPC. There are work arounds, just groups.google for them. ActiveState, (I'm just going on memory here), uses Microsoft's latest Visual C, to build itself, and it's modules. So the problem comes in that if you try to use a precompiled ppm that wasn't made with the exact same compiler and settings, it won't work. The Cygwin build tries to use gcc, but then your binaries are incompatible with ActiveState. The aforementioned Strawberry and Vanilla Perl, tries to fix this, by make a standardized setup. I totally avoid win32, so I may be off slightly in my observations, but other monks can straighten you out. So Tk on win32, does use the win32 subsystem, the problem is in how you compile them..... either with Microsoft tools, or opensource tools.....it's all too complicated and expensive to deal with, considering Perl and Tk compile and run perfectly for free on linux.

      why does your code execute fine when activestate executes it, but not when cygwin's perl executes it

      It sounds like your Cygwin installation is broken. It is pretty hard to get it setup right, so most people don't bother with it. Is there a Cygwin maillist you can ask this on?


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