Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / debian / libwx-perl / usr / share / doc / libwx-perl / examples / minimal / minimal.pl
1 #!/usr/bin/perl -w
2 #############################################################################
3 ## Name:        samples/minimal/minimal.pl
4 ## Purpose:     Minimal wxPerl sample
5 ## Author:      Mattia Barbon
6 ## Modified by:
7 ## Created:     29/10/2000
8 ## RCS-ID:      $Id: minimal.pl 2455 2008-08-31 11:16:05Z mbarbon $
9 ## Copyright:   (c) 2000, 2004-2006, 2008 Mattia Barbon
10 ## Licence:     This program is free software; you can redistribute it and/or
11 ##              modify it under the same terms as Perl itself
12 #############################################################################
13
14 use Wx;
15
16 package MyFrame;
17
18 use strict;
19 use base qw(Wx::Frame);
20
21 use Wx::Event qw(EVT_MENU);
22
23 # Parameters: title, position, size
24 sub new {
25   my( $class, $label ) = @_;
26   my $this = $class->SUPER::new( undef, -1, $label );
27
28   # load an icon and set it as frame icon
29   $this->SetIcon( Wx::GetWxPerlIcon() );
30
31   # create the menus
32   my $mfile = Wx::Menu->new;
33   my $mhelp = Wx::Menu->new;
34
35   my( $ID_ABOUT, $ID_EXIT ) = ( 1, 2 );
36   $mhelp->Append( $ID_ABOUT, "&About...\tCtrl-A", "Show about dialog" );
37   $mfile->Append( $ID_EXIT, "E&xit\tAlt-X", "Quit this program" );
38
39   my $mbar = Wx::MenuBar->new;
40
41   $mbar->Append( $mfile, "&File" );
42   $mbar->Append( $mhelp, "&Help" );
43
44   $this->SetMenuBar( $mbar );
45
46   # declare that events coming from menu items with the given
47   # id will be handled by these routines
48   EVT_MENU( $this, $ID_EXIT, 'OnQuit' );
49   EVT_MENU( $this, $ID_ABOUT, 'OnAbout' );
50
51   $this;
52 }
53
54 # called when the user selects the 'Exit' menu item
55 sub OnQuit {
56     my( $this, $event ) = @_;
57
58     # closes the frame
59     $this->Close( 1 );
60 }
61
62 use Wx qw(wxOK wxICON_INFORMATION wxVERSION_STRING);
63
64 # called when the user selects the 'About' menu item
65 sub OnAbout {
66     my( $this, $event ) = @_;
67
68     # display a simple about box
69     my $message = sprintf <<EOT, $Wx::VERSION, wxVERSION_STRING;
70 This is the about dialog of minimal sample.
71 Welcome to wxPerl %.02f
72 %s
73 EOT
74     Wx::MessageBox( $message, "About minimal", wxOK | wxICON_INFORMATION,
75                     $this );
76 }
77
78 package main;
79
80 # create an instance of the Wx::App-derived class
81 my $app = Wx::SimpleApp->new;
82 my $frame = MyFrame->new( "Minimal wxPerl app" );
83 $frame->Show;
84 $app->MainLoop;