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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tk second window pops to late

Status
Not open for further replies.

goBoating

Programmer
Feb 8, 2000
1,606
US
I'm writing a gui front end to a command line text indexing tool and am having trouble getting a status window to open. I would like to open a second main window before a pipe is opened to run the index command. The second window does open, but, only after the pipe has closed and the sub has completed, returning the app back to the MainLoop. The piped process can take 10 to 15 minutes and I need to pop the second window to let the user know the app is still do something.

This is a concise version of the code,
Code:
#!/usr/local/bin/perl -w
use Tk;

# Create main interface window
my $mw1 = MainWindow->new;
$mw1->configure(-title=>"Isite Admin");
$mw1->geometry('750x600+50+0');

# Create new frame for mode buttons
my $fr1 = $mw1->Frame(-relief=>'groove',
                      -borderwidth=>1)
    ->pack(-side=>'top', -fill=>'both');

# create menuButtons 
my $IindexMenu = $fr1->Menubutton(-text=>"DB Admin.", 
                                  -tearoff=>0,
                                  -relief=>'raised',
                                  -menuitems=>[
    ['command'=>"Erase Index", -command=> [\&confirm, 'Erase']],
    ['command'=>"Create an Index", -command=> \&createIndex ],
    ['command'=>"Edit File List", -command=> \&findList ]])	
    ->pack(-side=>'left');

MainLoop;
--------------------------------
sub createIndex
{
&clearFrames;
# get some input and call sub buildIndex on button press
# frame7 has been created and the button works to call buildIndex.
$frame7->Button(-text=>'Create Index', 
                          -command=> \&buildIndex)
    ->pack(-side=>'left');

}
--------------------------------
# The PROBLEM SUB IS HERE
sub buildIndex
{
$message = "Building $dbName on $dbPath";

# I want this window to pop open before the CMD below runs
my $mw2 = MainWindow->new;
$mw2->configure(-title=>"Isite Admin", -background=>'white');
$mw2->geometry('400x50+140+20');
my $mw2fr1 = $mw2->Frame(-relief=>'groove', 
                                             -background=>'white', 
                                             -borderwidth=>1)	
	->pack(-expand=>'1', -side=>'top', -fill=>'both');

$mw2fr1->Label(-text=>"Building $newDBName on path $dbPath.")	
	->pack(-side=>'top');


open(CMD,"$cmd2 |") or die "Failed to open CMD pipe";
while (defined($line = <CMD>)) 	{ $text->insert(&quot;end&quot;,$line);}
close CMD;
$message = &quot;Index Build Complete&quot;;
}

Is it the case that the pack requests in the sub all happen as the sub closes? Is it the return to the MainLoop that triggers the refresh on the display? Any ideas would be appreciated.


Thanks,




keep the rudder amid ship and beware the odd typo
 
Hi goBoating,

My guess would be that you are caught by some buffering that your command line indexing tool is doing -- which is a pain as it's unlikely to be possible to tell that tool to unbuffer its output, you're probably stuck with this behaviour.

Would it be possible to start the indexing tool off in the background?

You could then trap SIGCHLD and let the user know when the indexing process is complete. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top