
wickedxter
User
Oct 2, 2011, 7:59 PM
Post #2 of 2
(1039 views)
|
|
Re: [uskidsknow] Perl Tk: Parsing flatfile and inputing into a text widget
[In reply to]
|
Can't Post
|
|
one way i can think of is to tie the text area to a variable and update the variable as it will print out the contents of the variable in the text area.. theirs a book im sure its online " Perl TK " which is great and explains a lot in detail. i wrote this a while back
#Start Main Window my $MW = MainWindow->new(); #MainWindow Options $MW->title('File Counter 1.0.8a GUI'); $MW->geometry("300x310"); # save data my $data = { dir_content => [], count => '0', base_dir => '', }; my $precent = 0; my $msgarea = $MW->Label(-borderwidth => 2, -relief => 'groove') ->pack(-side => 'bottom', -fill => 'x'); my $balloon = $MW->Balloon(-statusbar => $msgarea, -initwait => 150); #Button Frame my $LabelFrame = $MW->Frame()->pack(-side => 'left', -fill => 'both'); #Find Folder Button my $Button1 = $LabelFrame->Button(-text => 'Find Folder', -command => \&opendirr)->pack(); $balloon->attach($Button1, -balloonmsg => "Find current folder", -statusmsg => "Press the Button to locate a file in the folder you scaned to"); # Process Button my $Button2 = $LabelFrame->Button(-text => 'Start Processing', -command => \&startcounting)->pack(); $balloon->attach($Button2, -balloonmsg => "Start Processing files", -statusmsg => "Press the Button to Start processing."); # Clear Button my $clearl = $LabelFrame->Button(-text => 'Reset/Clear', -command => \&clear)->pack(); $balloon->attach($clearl, -balloonmsg => "Clear/Reset folder data", -statusmsg => "Press the Button to clear the loaded folder data."); #### Listbox my $ProFrame = $MW->Frame()->pack(-fill => 'both'); my $list = $ProFrame->Scrolled('Listbox', -selectmode => 'single', -scrollbars => 'e')->pack(-fill => 'both'); $list->waitVariable(\$data->{count}); my $label_t1 = $ProFrame->Label(-text => "Found a total of ",)->pack(-side => 'left', -fill => 'x'); my $label_t = $ProFrame->Label(-textvariable => \$data->{count})->pack(-side => 'left', -fill => 'x'); my $label_t3 = $ProFrame->Label(-text => " File(s)",)->pack(-side => 'left', -fill => 'x'); #MainLoop MainLoop(); sub clear { delete $data->{dir_contents}; $data->{count} = 0; $data->{base_dir} = ''; $list->delete(0,'end'); #$data->{dir_contents}; $label_t->update; } sub startcounting { my ($dir) = @_; my @TEMP; my $count = 0; open(CFILE,">$data->{base_dir}/MASTERFILE.txt"); foreach (@{$data->{dir_contents}}){ print CFILE "Total Files: ".$data->{count}."\n" if $count eq 0; print CFILE "Location: ".$data->{base_dir}."\n\n" if $count eq 0; $count++; print CFILE "$_\n"; } close CFILE; my $response = $MW->messageBox(-message=>"File MASTERFILE.txt has been created and put in the folder you selected.",-type=>'ok'); open TEMP, "$data->{base_dir}/MASTERFILE.txt"; @TEMP = <TEMP>; close TEMP; my $response2 = $MW->messageBox(-message=>"Data Sent to printer....",-type=>'ok'); } sub load_dir { my ($dir) = $_[0]; #$data->{count}=0; $dir =~ /(\w\:\/.+\/)/; my $new_d = lc($1); $data->{base_dir} = $new_d; #my $counter = 0; opendir(DIR,"$new_d") || die("cant readdir $new_d\n"); while ((my $file = readdir(DIR))){ next if $file eq "." || $file eq ".."; if ($file){ $data->{count}++; push @{$data->{dir_contents}}, $file; $list->insert('end',"$file"); }else { next; } } } sub opendirr { #this returns a file path but easy striped off file name my $file = $MW->getOpenFile( ); &load_dir($file) if defined $file; }
(This post was edited by wickedxter on Oct 2, 2011, 8:01 PM)
|