Re: Splash screen & cookbook



On 02/09/01 pat eyler wrote:
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.)

Well, I'm not a splash screen fan myself, but here are some comments
on the code to make it look more tailored for the cookbook:

sub splash {
   my ($splash);
   $splash = new Gtk::Window("toplevel");

"toplevel" is not needed, you get a toplevel window by default.

   $splash->realize();

We need to realize the window to access $splash->window: add a comment 
to that effect.

   $splash->set_title("Splash Page");

Since we request the window manager to not add the title bar, for the
sake of simplicity I would not set the title...

   $splash->set_position('center');
   $splash->window->set_decorations(0);
   $splash->{'vbox'} = new Gtk::VBox(0,0);

Use my $vbox, it's easier on the eyes:-)

   my ($p,$m) = 

Use more informative names for the vars and group all the my declarations
at the beginning of the function.

Gtk::Gdk::Pixmap->create_from_xpm($splash->window,$splash->style->bg('normal'),$libpath."/pixmaps/splash.xpm");

Use "splash.xpm" instead of $libpath."/pixmaps/splash.xpm", the reader should be able
to figure out he needs the path to his own image:-)

   my $pixmap = new Gtk::Pixmap($p,$m);
   $pixmap->show();

show() not needed here, we do show_all later anyway.

   $splash->add($splash->{'vbox'});
   $splash->{'vbox'}->pack_start($pixmap,0,0,0);
   show_all $splash;

I would like to encourage the use of $object->method() method invocation in the docs
and leave the indirect object syntax to constructors and things like "init Gtk;".
See the warnings in perlobj for more details.

   while (Gtk->events_pending) {
       Gtk->main_iteration
   }
   return $splash;
}

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

Oooops, we didn't create a $splash->{'statusbar'} in splash()!

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

    &do_something;

Uhm, what is the point here to pass the current @_ to the called sub?
All the sub calls should be just do_something(); in the sample code.

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

Move this after the following line, it should work better.

    $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();
}

On 02/09/01 Maher Awamy wrote:
     $splash->window->raise();

I raise the splash window because the main window comes up and covers it, 
whats the right thing to do so that the splash window will be a top of the 
other main window that comes up while the splash is informing user about stuff?

At this point I think the correct behaviour is to just destroy the splash
window and be done with it in the sample code. If you need to keep it visible
in your app when the main window is up, you should let the window manager
handle it:

        $splash->set_transient_for($main_window);

BTW, this should be done for all the dialog boxes so that a smart
window manager can maintain the z order and group them...

Hope this helps.

lupus

-- 
-----------------------------------------------------------------
lupus debian org                                     debian/rules
lupus ximian com                             Monkeys do it better




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