CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
how to display a message box without halting the program

 



kwatts59
Novice

Jul 8, 2015, 1:15 PM

Post #1 of 5 (1877 views)
how to display a message box without halting the program Can't Post

Hi everyone,
I am trying to display a message box without halting my PERL script. My program takes a long time to load so I want to display a message while the data is loading and delete the message when it is done. I have tried all sorts of things but they always halt the program and wait for user input.
Below is the pseudo code of what I want to do. $mw is the main window.


Code
$mb  = $mw->messageBox(-message=>"Please wait while data loads."); 
$mb->show;
open(INFILE,$filenme);
while (<INFILE>)
{
...
}
close(INFILE);
$mb->delete;


Any help would be appreciated.
Thanks in advance.


FishMonger
Veteran / Moderator

Jul 8, 2015, 2:16 PM

Post #2 of 5 (1869 views)
Re: [kwatts59] how to display a message box without halting the program [In reply to] Can't Post

I have not done any testing but, have you tried using one of the other message box widgets to see if one of them is non-blocking?

If they all block, then you may need to create a second top level widget/window to display the message. Or, you could have a "status frame" that displays these types of status messages.


kwatts59
Novice

Jul 8, 2015, 6:06 PM

Post #3 of 5 (1860 views)
Re: [FishMonger] how to display a message box without halting the program [In reply to] Can't Post

I think I got it working.
Unfortunately, I had to have the user click a "Load Data" button to display the message, load the data and remove the message.
I tried putting the code into the mainloop and have the data automatically load at startup but it did not work.
Also, there is a bug in PERL and I could not get the text to appear inside the box so I had to put the message in the title.
Anyway, here is the code for others to look at.



Code
sub load_data 
{
# Make a message window
$top1 = $mw->Toplevel;
$top1->title("Message: Loading data, please wait...");
$top1->Label(-text => "Loading data, please wait...")->pack(-side => 'left'); # Bug in PERL, message does not get displayed
$top1->geometry('400x50+500+300');
$top1->raise($mw); # Display window

open(INFILE,$filenme);
while (<INFILE>)
{
...
}
close(INFILE);

$top1->withdraw; # Hide window
}



FishMonger
Veteran / Moderator

Jul 9, 2015, 7:10 AM

Post #4 of 5 (1833 views)
Re: [kwatts59] how to display a message box without halting the program [In reply to] Can't Post

The problem you're having is not due to a bug in perl...it's due to the way you're coding it. It's been awhile since I've done any Tk scripts, but I could work up a short example if you wish.

After rereading your posts, I see that I may have misunderstood your intent. If you're needing to load data as part of the initial phase of executing the script and want to display a message to the user during that time, then what you're looking for is called a Splashscreen.

Tk::Splashscreen - display a Splashscreen during program initialization.
http://search.cpan.org/dist/Tk-Splashscreen/Splashscreen.pm


kwatts59
Novice

Jul 9, 2015, 10:45 AM

Post #5 of 5 (1818 views)
Re: [FishMonger] how to display a message box without halting the program [In reply to] Can't Post

I figured out why the message does not appear in the box.
I need to add the command "$top1->update;" before the "$top1->raise($mw);"

Splashscreen also appears to work but when the window appears, there is no title or border around it. I will stick with the Toplevel since it works.
Thank you for your response.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives