+ -
当前位置:首页 → 问答吧 → Perl 语言实现一个窗体

Perl 语言实现一个窗体

时间:2011-01-20

来源:互联网

  1. Myapp.pm
  2. #!/usr/bin/perl -w

  3. use strict;

  4. # load wxPerl main module
  5. use Wx;

  6. # every application must create an application object
  7. package MyApp;
  8. use base qw(Wx::Frame Class::Accessor::Fast);

  9. use Wx qw(:textctrl :sizer :window :id);
  10. use Wx qw(wxDefaultPosition wxDefaultSize wxTheClipboard
  11.           wxDEFAULT_FRAME_STYLE wxNO_FULL_REPAINT_ON_RESIZE wxCLIP_CHILDREN);
  12. use Wx::Event qw(EVT_TREE_SEL_CHANGED EVT_MENU EVT_CLOSE);
  13. use File::Slurp;
  14. use File::Basename qw();
  15. use File::Spec;
  16. use UNIVERSAL::require;


  17. sub new{
  18.        
  19.          my( $class ) = @_;
  20.      my $self = $class->SUPER::new
  21.       ( undef, -1, 'wxPerl demo', wxDefaultPosition, [ 800, 600 ],
  22.         wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN );
  23.         
  24.         Wx::InitAllImageHandlers();
  25.         my $bar  = Wx::MenuBar->new;
  26.     my $file = Wx::Menu->new;
  27.     my $help = Wx::Menu->new;
  28.     my $edit = Wx::Menu->new;
  29.   
  30.     $file->Append( wxID_EXIT, '' );
  31.     $help->Append( wxID_ABOUT, '' );

  32.     $edit->Append( wxID_COPY,  '' );
  33.     $edit->Append( wxID_FIND,  '' );
  34.     my $find_again = $edit->Append( -1, "Find Again\tF3" );

  35.     $bar->Append( $file, "&File" );
  36.     $bar->Append( $edit, "&Edit" );
  37.     $bar->Append( $help, "&Help" );
  38.    
  39.     $self->SetMenuBar( $bar );
  40.     $self->{menu_count} = $self->GetMenuBar->GetMenuCount;
  41.     $self->SetIcon( Wx::GetWxPerlIcon() );
  42.     $self->Show;
  43.    
  44. }


  45. 1;
  46. ui.pl

  47. #!perl -w
  48. use MyApp;
  49. use Getopt::Long;

  50. GetOptions( 'show=s'   => \( my $module ),
  51.             'help'     => \( my $help ),
  52.             'list'     => \( my $list ),
  53.             ) or usage();
  54. usage() if $help;


  55. my $app    = Wx::SimpleApp->new;
  56. my $locale = Wx::Locale->new( Wx::Locale::GetSystemLanguage );
  57. my $ui = MyApp->new;

  58. $ui->activate_module( $module ) if $module;

  59. if ($list) {
  60.     print join "\n",
  61.           sort
  62.           map $_->title,
  63.           grep $_->can( 'title' ),
  64.           $ui->plugins;

  65.    exit 0;
  66. }
  67. $app->MainLoop;
  68. exit 0;
复制代码

作者: 阳光boyer   发布时间: 2011-01-20

不错,wx还是比较成熟的。

作者: 兰花仙子:   发布时间: 2011-01-20