2 #############################################################################
3 ## Name: samples/dialog/dialog.pl
4 ## Purpose: Dialog wxPerl sample
5 ## Author: Mattia Barbon
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 #############################################################################
19 use base qw(Wx::Dialog);
21 use Wx::Event qw(EVT_CLOSE EVT_BUTTON);
22 use Wx qw(wxDefaultSize wxDefaultValidator);
25 my( $class, $label ) = @_;
26 my $this = $class->SUPER::new( undef, -1, $label, [-1, -1], [250, 110] );
28 $this->SetIcon( Wx::GetWxPerlIcon() );
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] );
38 EVT_BUTTON( $this, $cb, \&CelsiusToFahrenheit );
39 EVT_BUTTON( $this, $fb, \&FahrenheitToCelsius );
40 EVT_CLOSE( $this, \&OnClose );
45 sub CelsiusToFahrenheit {
46 my( $this, $event ) = @_;
48 $this->fahrenheit->SetValue( ( $this->celsius->GetValue /
52 sub FahrenheitToCelsius {
53 my( $this, $event ) = @_;
55 $this->celsius->SetValue( ( ( $this->fahrenheit->GetValue - 32 ) /
60 my( $this, $event ) = @_;
65 sub fahrenheit { $_[0]->{fahrenheit} }
66 sub celsius { $_[0]->{celsius} }
70 my $app = Wx::SimpleApp->new;
71 my $dialog = MyDialog->new( "wxPerl dialog sample" );