Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / debian / libwx-perl / usr / share / doc / libwx-perl / examples / dialog / dialog.pl
1 #!/usr/bin/perl -w
2 #############################################################################
3 ## Name:        samples/dialog/dialog.pl
4 ## Purpose:     Dialog wxPerl sample
5 ## Author:      Mattia Barbon
6 ## Modified by:
7 ## Created:     12/11/2000
8 ## RCS-ID:      $Id: dialog.pl 2057 2007-06-18 23:03:00Z mbarbon $
9 ## Copyright:   (c) 2000, 2004, 2006 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 MyDialog;
17
18 use strict;
19 use base qw(Wx::Dialog);
20
21 use Wx::Event qw(EVT_CLOSE EVT_BUTTON);
22 use Wx qw(wxDefaultSize wxDefaultValidator);
23
24 sub new {
25     my( $class, $label ) = @_;
26     my $this = $class->SUPER::new( undef, -1, $label, [-1, -1], [250, 110] );
27
28     $this->SetIcon( Wx::GetWxPerlIcon() );
29
30     # absolute positioning is bad
31     my $ct = $this->{celsius} =
32       Wx::TextCtrl->new( $this, -1, '0', [20, 20], [100, -1] );
33     my $cb = Wx::Button->new( $this, -1, 'To Fahrenheit', [130, 20] );
34     my $ft = $this->{fahrenheit} =
35       Wx::TextCtrl->new( $this, -1, '32', [20, 50], [100, -1] );
36     my $fb = Wx::Button->new( $this, -1, 'To Celsius', [130, 50] );
37
38     EVT_BUTTON( $this, $cb, \&CelsiusToFahrenheit );
39     EVT_BUTTON( $this, $fb, \&FahrenheitToCelsius );
40     EVT_CLOSE( $this, \&OnClose );
41
42     return $this;
43 }
44
45 sub CelsiusToFahrenheit {
46     my( $this, $event ) = @_;
47
48     $this->fahrenheit->SetValue( ( $this->celsius->GetValue /
49                                    100.0 ) * 180 + 32 );
50 }
51
52 sub FahrenheitToCelsius {
53     my( $this, $event ) = @_;
54
55     $this->celsius->SetValue( ( ( $this->fahrenheit->GetValue - 32 ) /
56                                 180.0 ) * 100 );
57 }
58
59 sub OnClose {
60     my( $this, $event ) = @_;
61
62     $this->Destroy;
63 }
64
65 sub fahrenheit { $_[0]->{fahrenheit} }
66 sub celsius    { $_[0]->{celsius} }
67
68 package main;
69
70 my $app = Wx::SimpleApp->new;
71 my $dialog = MyDialog->new( "wxPerl dialog sample" );
72 $dialog->Show;
73 $app->MainLoop;