Re: Displaying a popup before the main window



Nicolas Courtel wrote:
Hello,

As my program needs a few seconds to start, I would like to display a
popup to tell the user that it's working.
Looks pretty simple, but for some reason the popup shows up empty, and I
can't figure out what I've done wrong.

I would be grateful for any clue, here's a short example which shows the
problem.

There are various possible ways. The main problem with your version is
that you didn't process the events that occur when you try to show the
splash screen. The version below is one way to do it:

#!/usr/bin/perl -w

use strict;
use Gtk2 -init;

my $window = Gtk2::Window->new;
$window->set_title ("My window");

# my $popup = Gtk2::MessageDialog->new ($window, 'destroy-with-parent',
# 'info',
#                                      'none', "Please wait for 10
# seconds...");

my $splash = Gtk2::Label->new("Please wait for 10 seconds...");
$window->add($splash);
$window->show;
$popup->show;

# Process the events so the show actually does something

Gtk2->main_iteration while Gtk2->events_pending;

# The sleep is only here because this is an example, right?
# You wouldn't do this in real-life

sleep 10;

# The splash needs to be destroyed before you add the real content.
# Build real content in a main container widget then destroy the
# splash, then add the container to the window

my $label = Gtk2::Label->new ("Hello, world!");

$splash->destroy;

$window->add ($label);

# $popup->destroy;

$window->show_all;
Gtk2->main;





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]