another recipe



Here's a shot at another recipe. (This one may be too basic for inclusion, but I needed to dig around a bit to figure out how to
do it -- I think that I'm pretty representative of the novice user
(I'm still writing my first gnome-perl app), so if it takes me some
time to find all the info then it's worth writing up for other
newbies.)

I think the discussion section is weak, so I'd be interested in
hearing ideas for better content there.  Also, any notes on botched
style, etc. would be appreciated.

thanks,
-pate

----------------the recipe (in pod)---------------


=head2 A Panel Applet

B<Problem:>

You want to give the user access to an application from the Gnome
Panel to save real estate on the screen.

B<Solution>

Use the Gnome::Applet module.

   #!/usr/bin/perl

   use Gnome::Applet;

   init Gnome::AppletWidget 'myapplet.pl';

   my $applet = new Gnome::AppletWidget 'myapplet.pl';
   realize $applet;

   my $hbox = new Gtk::HBox( 0, 0);
   $applet->add( $hbox);
   show $hbox;

   my $entry = new Gtk::Entry;
   $entry->show();

   my $send_button = new Gtk::Button "send";
   $send_button->signal_connect( "clicked",
                              \&pop_message
                              );
   $send_button->show();

   my $quit_button = new Gtk::Button "quit";
   $quit_button->signal_connect( "clicked",
                              \&delete_applet);
   $quit_button->show();

   $hbox->pack_start( $entry , 0, 0, 0 );
   $hbox->pack_start( $send_button, 0, 0, 0 );
   $hbox->pack_start( $quit_button, 0, 0, 0 );
   $applet->show();

   gtk_main Gnome::AppletWidget;



   sub pop_message {
   my $message_text = $entry->get_text();

   my $popwin = new Gtk::Window('toplevel');
   $popwin->signal_connect( 'destroy', sub { $popwin->destroy(); } );
   $popwin->set_title( "Urgent Message from Applet" );

   my $text = new Gtk::Text;
   $text->set_editable( $true );
   $text->show();
   $text->insert( undef, undef, undef, "$message_text" );
   $text->show;

   $popwin->add($text);

   $popwin->show;

   return 0;
   }

   sub delete_applet {
   Gtk->main_quit;
   }

B<Discussion:>

The Gnome::Applet module lets you create and manipulate a panel applet
(or a control center capplet if you'd rather).  This can be used to
provide access to an application, while keeping a small footprint when
it is not in use.

_________________________________________________________________
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]