Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Per/Tk - problem browsing for a directory

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Joined
Feb 6, 2002
Messages
1,851
Location
IL
Hi,

Trying ro get a user to browse for the target dir.
Have taken this code form a widget demo,but it does not seem to work well for me.
I know that "WidgetDemo" is should not be there - but what should ?

my $mw = new MainWindow; #define the main window
$mw->configure(-title=>"rehost.exe Ver $VERSION on $computer" # Main Window
$mw->geometry('+380+10');

use vars qw/$TOP/;
$TOP = $mw->WidgetDemo
(
-name => 'Choose dir',
-text => "Enter a directory name in the entry box or click on the \"Browse\" buttons to select a directory name using the directory selection dialog.",
-title => 'Choose Directory Demonstration',
-iconname => 'choosedir',
);
$f = $TOP->Frame;
$lab = $f->Label(-text => "Select a directory to open: ",
-anchor => 'e');
$ent = $f->Entry(-width => 20);
$but = $f->Button(-text => "Browse ...",
-command => sub { dirDialog($TOP, $ent)});
$lab->pack(-side => 'left');
$ent->pack(-side => 'left',-expand => 'yes', -fill => 'x');
$but->pack(-side => 'left');
$f->pack(-fill => 'x', -padx => '1c', -pady => 3);

sub dirDialog {
my $w = shift;
my $ent = shift;
my $dir;
$dir = $w->chooseDirectory;
if (defined $dir and $dir ne '') {
$ent->delete(0, 'end');
$ent->insert(0, $dir);
$ent->xview('end');
}
}

MainLoop;

Long live king Moshiach !
 
It probably isn't a good idea to use

Code:
$TOP = $mw->WidgetDemo

WidgetDemo is for the "widget" program you run from command line, it's to demonstrate stuff... serious programs shouldn't be using it.

What does $mw->chooseDirectory do? Try just using that instead of making it more complicated than it needs to be.

Code:
     $but = $f->Button(-text => "Browse ...",
          -command => sub {
               my $d = $mw->chooseDirectory;
               $ent->configure (-text => $d);
          },
     );
 
Hello MoshiachNow and Kirsle,
This thread may be most fortunate for me.

I am new to Perl (just this weekend, starting chapter 4 of O'Reilly's Learing Perl) and am working towards modifying a perl program to allow the user to select files via a bowser rather than tediously entering them in a batch file that then calls perl.

I am not sure at all of what everything does here. Would you please post a minimum amount of code that would allow a directory search and leave the pathname of a file in a list. I am hoping for something like:

Code:
use utils::stat;
use TK;

my @file_list;

#  what goes here?
foreach $file_list (@file_list)
   {
   print $file_list . "\n";
   };

In my mind, the user would select several files and the output of this snippet would be the full pathname of each file. If I get that far, then I think I will be able to call a parsing program that someone else wrote. It pulls data from a rather convoluted log file and builds a comma separated file that I import into Excel and chart the data.

Thanks for your time,
Bkelly
 
use Tk::DirSelect;

my $mw = new MainWindow; #define the main window
$mw->configure(-title=>"rehost.exe Ver $VERSION on $computer"); # Main Window

my $ds = $mw->DirSelect();#DIR selection window

MainLoop; #This function will be executed when the button is pushed

#User selects the target drive :
$VOLUME = $ds->Show();



Long live king Moshiach !
 
Hello MoshiachNow,
I don't know what is going on in the code you gave me. I edited into my fragments and came up with the below code. When I run it, it just pops up another Notepad window of the same source code. The prints at the end of the code produce no output that I can find.

If this is something that is way beyond my knowledge, say so and I will wait until I understand more about Perl.

Code:
use utils::stat;
use TK;
use Tk::DirSelect;

my @file_list;
my $mw = new MainWindow;  #define the main window
$mw->configure(-title=>"rehost.exe Ver $VERSION on $computer");          # Main Window 

my $ds  = $mw->DirSelect();#DIR selection window

MainLoop; #This function will be executed when the button is pushed 

#User selects the target drive :
$VOLUME = $ds->Show();

print "program done, results follow\n";
print $ds;
print "\nend of results\n";
 
print $VOLUME;

This one will hold your selected directory,not files.

For files selection you need Tk::FileDialog from CPAN.


Long live king Moshiach !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top