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

I've started down the mildly ambitious road of writing my own GUI ftp client. So far it's four boxes and a file select dialog. eventually I plan to set up two windows one to browse my pc and another to browse the remote. As well as config files to store site info. My question relates to file browsing on tk.

Are their any widgets or code examples of embeddable file navigators written in Tk. I've taken a look at Tk::DirTree and Tk::DirList, but neither works well as a file navigator as each requires a root directory to be set and can only(apparently) browse downward from that root, and lists dont collapse, etc etc, and they are not that attractive anyhow. Am i missing a better option?

#!/usr/bin/perl use Net::Ftp; use Tk; my $top = new MainWindow; my $l_ftpsite = $top->Label(-text=>"Site")->pack; my $entry_ftpsite = $top->Entry(-textvariable=>\$ftpsite)->pack; my $l_username = $top->Label(-text=>"Username")->pack; my $entry_username = $top->Entry(-textvariable=>\$username)->pack; my $l_password = $top->Label(-text=>"Password")->pack; my $entry_password = $top->Entry(-textvariable=>\$password)->pack; my $l_directory = $top->Label(-text=>"Directory")->pack; my $entry_directory = $top->Entry(-textvariable=>\$directory)->pack; my $browse = $top->Button ( -text=>"Browse..", -command=> sub{ my $filename = $top->getOpenFile( +); ftp_me($username,$password,$ftpsit +e,$directory,$filename); } )->pack(); MainLoop; sub ftp_me{ my ($username,$password,$ftpsite,$directory,$filename) = @_; $ftp = Net::FTP->new($ftpsite, Debug => 0); $ftp->login($username,$password); if (defined $directory) { $ftp->cwd(q|$directory|); } $ftp->put($filename); $ftp->quit; }

BTW, I'm aware of the lack of error checking and am working on that :) this was just a test case.

Replies are listed 'Best First'.
Re: need advice on my Tk ftp client
by rbc (Curate) on Apr 26, 2002 at 20:16 UTC
    You might want to check this out then
      I did actually, I should have mentioned that. DirSelect is a top level window. it cant be packed onto another widget, as far as i know. But maybe I can adapt it to my needs. Considering that I'm planning on making a remote browser as well i'll probably have to roll my own in the end...

        You can reparent toplevels into other toplevels or Frames using the -container and -use options to toplevels. See this thread for a little more info.

        You would almost definately end up having to patch DirSelect to accept a widget as a container, but that should be very easy (and you can send the patch back to the author :-)

        Basically, you would just create a frame or toplevel in your program, in which you set the -container option to true. Then you would have to make DirSelect's constructor accept a widget that it would pass to it's toplevel via -use. And that's it. Easy, yes? :-)

        bbfu
        Black flowers blossum
        Fearless on my breath
        Teardrop on the fire
        Fearless on my breath