#!/usr/bin/perl -w
use strict;
use Wx;
package MyFrame;
use Wx qw[:everything];
use base 'Wx::Frame';
my $abbruch;
sub new {
my $class = shift;
my $frame = $class->SUPER::new( undef, -1, 'StopLoop', [-1, -1], [175, 150] );
$frame->{panel} = Wx::Panel->new( $frame, -1, );
$frame->{bt_start} = Wx::Button->new( $frame->{panel}, -1, 'starten', [-1, -1], [150, -1] );
$frame->{txt_status} = Wx::TextCtrl->new( $frame->{panel}, -1, "", [-1, -1], [150, -1] );
$frame->{bt_stop} = Wx::Button->new( $frame->{panel}, -1, 'abbrechen', [-1, -1], [150, -1] );
$frame->{sizer_1} = Wx::BoxSizer->new(wxVERTICAL);
$frame->{sizer_2} = Wx::BoxSizer->new(wxVERTICAL);
$frame->{sizer_1}->Add($frame->{panel}, 1, wxEXPAND, 0);
$frame->{sizer_2}->Add($frame->{bt_start}, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 10);
$frame->{sizer_2}->Add($frame->{txt_status}, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 10);
$frame->{sizer_2}->Add($frame->{bt_stop}, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 10);
$frame->SetSizer($frame->{sizer_1});
$frame->{panel}->SetSizer($frame->{sizer_2});
Wx::Event::EVT_BUTTON($frame, $frame->{bt_start}->GetId, \&starte_schleife);
Wx::Event::EVT_BUTTON($frame, $frame->{bt_stop}->GetId, \&abbrechen_schleife);
return $frame;
}
sub starte_schleife{
my $frm = shift;
for(my $i=1; $i<=10; $i++){
$frm->{txt_status}->SetValue("$i. Schleifendurchlauf");
$frm->{txt_status}->Update;
sleep(1);
last if($abbruch);
}
}
sub abbrechen_schleife{
$abbruch = 1;
}
1;
package MyApp;
use base 'Wx::App';
sub OnInit {
my $frame = MyFrame->new;
$frame->Show(1);
}
1;
package main;
my $wxapp = MyApp->new;
$wxapp->MainLoop;