Re: Splash screen & cookbook



I really like the cookbook idea that was posted here recently by
Paolo.  As it stands now it looks like good documentation, but it's
missing the recipe kind of entries that made 'The Perl Cookbook' so
useful.  Here's a cut at answering the splash screen question in the
'Recipe Style'.  (The basic code here is from Pronto.  I chopped
some things out, but it should still work.  *CAVEAT* I didn't know how
to do this before writing this and reading through Pronto -- someone
with a better handle on things should look this over, verify that it
makes sense, and probably write a better discussion blurb.)


Problem:
You want to create a splash page for your Gtk-Perl application.

Solution:
Create a toplevel window, and use it as your splash page.

sub splash {
  my ($splash);
  $splash = new Gtk::Window("toplevel");
  $splash->realize();
  $splash->set_title("Splash Page");
  $splash->set_position('center');
  $splash->window->set_decorations(0);
  $splash->{'vbox'} = new Gtk::VBox(0,0);
my ($p,$m) = Gtk::Gdk::Pixmap->create_from_xpm($splash->window,$splash->style->bg('normal'),$libpath."/pixmaps/splash.xpm");
  my $pixmap = new Gtk::Pixmap($p,$m);
  $pixmap->show();
  $splash->add($splash->{'vbox'});
  $splash->{'vbox'}->pack_start($pixmap,0,0,0);
  show_all $splash;
  while (Gtk->events_pending) {
      Gtk->main_iteration
  }
  return $splash;
}

sub app_init {
   my $splash = splash();
   $splash->{'statusbar'}->push(1,"Doing Something ...");

   while (Gtk->events_pending) {
        Gtk->main_iteration
   }

   &do_something;

   while (Gtk->events_pending) {
        Gtk->main_iteration
   }

   $splash->{'statusbar'}->push(1,"Doing Something Else ...");

   &do_something_else;

   while (Gtk->events_pending) {
        Gtk->main_iteration
   }

   $splash->{'statusbar'}->push(1,"Creating main window ...");
   &init_main_window;
   $splash->window->raise();
   while (Gtk->events_pending) {
        Gtk->main_iteration
   }

   $splash->destroy();
}


Discussion:
By creating a top level window, and loading it with a pixmap (the
splash image) and a status bar, you've created a splash page.  You can
then write updates to the status bar as you do things.

When you're done initializing, you can create the main window then
delete the splash page.




-pate

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com





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