技术开发 频道

用Perl进行GNOME编程

  完整程序清单

  下面是读完这个教程,一步步按照我们说的做所应该生成的程序清单:

  #!/usr/bin/perl -w   use strict;   use Gnome;   my $NAME = 'Hello World';   init Gnome $NAME;   my $app = new Gnome::App $NAME, $NAME;   signal_connect $app 'delete_event', sub { Gtk->main_quit; return 0 };   $app->create_menus(   {type => 'subtree',   label => '_File',   subtree => [   {type => 'item',   label => 'E_xit',   pixmap_type => 'stock',   pixmap_info => 'Menu_Quit',   callback => sub { Gtk->main_quit; return 0 }   }   ]   },   {type => 'subtree',   label => '_Help',   subtree => [   {type => 'item',   label => '_About...',   pixmap_type => 'stock',   pixmap_info => 'Menu_About',   callback => chunk73189196chunk#38;about_box   }   ]   }   );   $app->create_toolbar(   {   type => 'item',   label => 'Exit',   pixmap_type => 'stock',   pixmap_info => 'Quit',   hint => "Click here to quit",   callback => sub { Gtk->main_quit },   }, {   type => 'item',   label => 'About...',   pixmap_type => 'stock',   pixmap_info => 'About',   hint => "More information about this app",   callback => chunk73189196chunk#38;about_box   }   );   my $label = new Gtk::Label "Hello, world";   $app->set_contents($label);   my $bar = new Gnome::AppBar 0,1,"user" ;   $bar->set_status(" Welcome ");   $app->set_statusbar( $bar );   show_all $app;   main Gtk;   sub about_box {   my $about = new Gnome::About $NAME, "v1.0",   "(C) Simon Cozens, 2000", ["Simon Cozens"],   "This program is released under the same terms as Perl itself";   show $about;   }   =head1 Summary

  这样,我们用 GNOME/Perl 创建了我们的第一个应用程序。它拥有标准的 GNOME 界面,有标准的菜单栏,工具栏,状态栏,弹出窗口。它无论是看起来,还是真正运行起来都像一个真正的 GNOME 应用程序。总共只有大约 70 行 Perl 代码。

  下一次,我们会创建一个更有用的应用程序,一个食谱管理器。在里面我们将会用到一些稍微复杂一些的控件,比如容器,文本输入域,滚动条和列表框。

0
相关文章