免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1637 | 回复: 0
打印 上一主题 下一主题

请教一个POE+ Gtk2的例子 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-12-14 19:50 |只看该作者 |倒序浏览
POE: Cookbook - Gtk2 Counter Glade
源程序链接 http://poe.perl.org/?POE_Cookbook/Gtk2_Counter_glade
glade文件 http://tipi.sf.net/cookbook.glade
  1. #!/usr/bin/perl
  2. # http://poe.perl.org/?POE_Cookbook/Gtk_Interfaces
  3. #
  4. # This sample program creates a very simple Gtk counter.  Its
  5. # interface consists of three widgets: A label, a rapidly increasing
  6. # counter, and a button to reset that counter.
  7. # the 1 - 4 here corresponds to the points in the cookbook entry without
  8. # glade
  9. # 4. Because with POE::Session::GladeXML2, you create the gui through glade
  10. # instead of code, and because it expects all the gtk signal handlers to
  11. # be in a seperate package, it becomes even easier to seperate the GUI
  12. # specific code from the non-gui-dependant code.
  13. package Foo;
  14. use warnings;
  15. use strict;

  16. # POE::Loop::Glib doesn't initialize Gtk2 (for obvious reasons), so we
  17. # do it here
  18. use Gtk2-init;
  19. use POE;
  20. use POE::Session::GladeXML2;

  21. sub new {
  22.   my ($class) = @_;
  23.   my $self = bless {}, $class;
  24.   my $session = POE::Session::GladeXML2->create(
  25.     glade_object => $self,
  26.     glade_file   => 'cookbook.glade',

  27. # 1. You can use the glade_mainwin parameter to create() to tell which
  28. # widget should be considered the main window.
  29.     glade_mainwin => 'window1',
  30.     inline_states => {
  31.       _start   => \&ui_start,
  32.       ev_count => \&ui_count,
  33.     }
  34.   );
  35.   return $self;
  36. }

  37. sub ui_start {
  38.   my ($kernel, $heap) = @_[KERNEL, HEAP];
  39.   $heap->{counter} = 0;
  40.   $kernel->yield("ev_count");
  41. }

  42. # Handle the "ev_count" event by increasing a counter and displaying
  43. # its new value.
  44. sub ui_count {
  45.   my ($session, $kernel, $heap) = @_[SESSION, KERNEL, HEAP];

  46. # 2. When using Gtk2::GladeXML, you can get any widget by name. Thus
  47. # there is no more need to store them yourself.
  48.   my $label = $session->gladexml->get_widget('counter_label');
  49.   $label->set_text(++$heap->{counter});
  50.   $kernel->yield("ev_count");
  51. }

  52. # 3. Instead of having to manually connect gtk signals with poe event
  53. # handlers, POE::Session::GladeXML2 automatically connects the handler
  54. # name you set in glade with the corresponding method in the object you
  55. # pass as glade_object.
  56. sub ui_clear {
  57.   $_[HEAP]->{counter} = 0;
  58. }

  59. package main;
  60. use POE;

  61. # Run the program until it is exited.
  62. my $foo = Foo->new;
  63. $poe_kernel->run();
  64. exit 0;
复制代码
运行之后 没报错 界面上只有一个白块

拉伸后

时间稍长一点 终止时 会显示 "Out of memory!"
不知道原因
麻烦 帮我看看 谢谢
Win 7 32 bit, Active Perl 5.10

small.JPG (10.1 KB, 下载次数: 17)

small.JPG
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP