Chinaunix首页 | 论坛 | 博客
  • 博客访问: 226543
  • 博文数量: 36
  • 博客积分: 1188
  • 博客等级: 军士长
  • 技术积分: 802
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-08 21:45
文章分类

全部博文(36)

文章存档

2020年(1)

2017年(2)

2015年(1)

2014年(1)

2013年(1)

2012年(3)

2011年(27)

分类: WINDOWS

2012-09-03 22:43:07


  1. #use Acme::PerlTidy;
  2. use Wx;
  3. use Wx::Html;
  4. use Wx::Help;
  5. package MyFrame;
  6. use base qw(Wx::Frame);
  7. use Wx qw(:textctrl :sizer :window);
  8. use Wx qw(wxDefaultPosition wxDefaultSize
  9.   wxDEFAULT_FRAME_STYLE wxNO_FULL_REPAINT_ON_RESIZE wxCLIP_CHILDREN wxID_EXIT);
  10. use Wx::Event qw(EVT_TREE_SEL_CHANGED EVT_CLOSE EVT_IDLE EVT_MENU EVT_BUTTON);
  11. our @id = ( 0 .. 100 ); # IDs array
  12. my @demos = qw( Simple Grid Editors Renderers);
  13. my @items = (
  14.     [ '核算科室', [ [ '医生护士', 'a' ], [ '科主任护士长', 'b' ], ], ],
  15.     [ '业务非核算单元', [ [ '药剂员', 'c' ], [ '收费员', 'd' ], ], ],
  16.     [ '行政后勤科室', [ [ '中层高层领导', 'e' ], [ '行政后勤员工', 'f' ], ], ],
  17. );
  18. sub new {
  19.     my $ref = shift;
  20.     my $self = $ref->SUPER::new(
  21.         undef, # parent window
  22.         -1, # ID -1 means any
  23.         '医院绩效分配系统', # title
  24.         wxDefaultPosition, # default position
  25.         [ 600, 500 ],
  26.         wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE | wxCLIP_CHILDREN
  27.     );
  28. ########## example <<CODE ###########
  29.     my $firstmenu = Wx::Menu->new();
  30.     $firstmenu->Append( wxID_EXIT, "&Exit\tCtrl+X" );
  31.     my $secmenu = Wx::Menu->new();
  32.     $secmenu->Append( $id[0], "&About" );
  33.     # Create menu bar
  34.     my $menubar = Wx::MenuBar->new();
  35.     $menubar->Append( $firstmenu, "&File" );
  36.     $menubar->Append( $secmenu, "&Help" );
  37.     # Attach menubar to the window
  38.     $self->SetMenuBar($menubar);
  39.     # create splitters
  40.     my $split1 =
  41.       Wx::SplitterWindow->new( $self, -1, wxDefaultPosition, wxDefaultSize,
  42.         wxNO_FULL_REPAINT_ON_RESIZE | wxCLIP_CHILDREN );
  43.     my $split2 =
  44.       Wx::SplitterWindow->new( $split1, -1, wxDefaultPosition, wxDefaultSize,
  45.         wxNO_FULL_REPAINT_ON_RESIZE | wxCLIP_CHILDREN );
  46.     my $tree = Wx::TreeCtrl->new( $split1, -1 );
  47.     my $text = Wx::TextCtrl->new( $split2, -1, "Welcome to wxPerl\n",
  48.         wxDefaultPosition, wxDefaultSize,
  49.         wxTE_READONLY | wxTE_MULTILINE | wxNO_FULL_REPAINT_ON_RESIZE );
  50.     $self->{OLDLOG} = Wx::Log::SetActiveTarget( Wx::LogTextCtrl->new($text) );
  51.     # create main notebook
  52.     my $nb =
  53.       Wx::Notebook->new( $split2, -1, wxDefaultPosition, wxDefaultSize,
  54.         wxNO_FULL_REPAINT_ON_RESIZE | wxCLIP_CHILDREN );
  55.     my $html =
  56.       Wx::HtmlWindow->new( $nb, -1, wxDefaultPosition, wxDefaultSize,
  57.         wxNO_FULL_REPAINT_ON_RESIZE | wxCLIP_CHILDREN );
  58.     my $code =
  59.       Wx::TextCtrl->new( $nb, -1, '', wxDefaultPosition, wxDefaultSize,
  60.         wxTE_READONLY | wxTE_MULTILINE | wxNO_FULL_REPAINT_ON_RESIZE );
  61.     $nb->AddPage( $code, "Source", 0 );
  62.     $nb->AddPage( $html, "Description", 0 );
  63.     my $root_id = $tree->AddRoot("绩效工资院级一次分配");
  64.     populate_tree_list( $tree, $root_id, \@items );
  65.     $tree->Expand($root_id);
  66.     $self->{'tree'} = $tree;
  67.     $split1->SplitVertically( $tree, $split2, 150 );
  68.     $split2->SplitHorizontally( $nb, $text, 300 );
  69.     # Handle events only for Exit and help About
  70.     EVT_MENU( $self, $id[0], \&ShowDialog );
  71.     EVT_MENU( $self, wxID_EXIT, sub { $_[0]->Close(1) } );
  72.     EVT_TREE_SEL_CHANGED( $self, $tree, \&OnSelChanged );
  73. ########## 001CODE ###########
  74.     return $self;
  75. }
  76. ### PUT SUBROUTINES HERE ###
  77. sub d { Wx::TreeItemData->new( $_[0] ) }
  78. sub populate_tree_list {
  79.     my $tree = shift;
  80.     my $parent_id = shift;
  81.     my $id;
  82.     foreach my $i ( @{ $_[0] } ) {
  83.         next if ( defined $i->[2] && $i->[2] >= Wx::wxVERSION() );
  84.         if ( ref( $i->[1] ) eq 'ARRAY' ) {
  85.             $id = $tree->AppendItem( $parent_id, $i->[0], -1, -1, d(undef) );
  86.             populate_tree_list( $tree, $id, $i->[1] );
  87.         }
  88.         else {
  89.             $tree->AppendItem( $parent_id, $i->[0], -1, -1, d( $i->[1] ) );
  90.         }
  91.     }
  92. }
  93. sub OnSelChanged {
  94.     my ( $self, $event ) = @_;
  95.     my $id = $event->GetItem;
  96.     my $ptype = $self->{'tree'}->GetPlData($id);

  97.     return unless ref($ptype);
  98. }
  99. sub ShowDialog {
  100.     my ( $self, $event ) = @_;
  101.     Wx::MessageBox(
  102.         "This is a dialog",
  103.         "Wx::MessageBox example",
  104.         wxOK | wxCENTRE, $self
  105.     );
  106. }
  107. package MyApp;
  108. use base 'Wx::App';
  109. sub OnInit {
  110.     my $self = shift;
  111.     my $frame = MyFrame->new;
  112.     my $config = Wx::ConfigBase::Get;
  113.     my $x = $config->ReadInt( "X", 50 );
  114.     my $y = $config->ReadInt( "Y", 50 );
  115.     my $w = $config->ReadInt( "Width", 800 );
  116.     my $h = $config->ReadInt( "height", 600 );
  117.     $frame->SetSize( $x, $y, $w, $h );
  118.     $frame->Show(1);
  119.     $self->SetTopWindow($frame);
  120.     return 1;
  121. }
  122. package main;
  123. my $app = MyApp->new;
  124. $app->MainLoop;
附图:

阅读(2861) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~