Thread "Abbruch" Funktion in wxPerl-Programm: Button "abbrechen" wird ignoriert (13 answers)
Opened by Christian at 2006-05-11 22:16

Gast Gast
 2006-05-15 10:30
#45424 #45424
Heureka!

Die Lösung heißt: Wx::Yield()

und in dann vollständiger Form im obigen Beispielscript:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl -w

use strict;
use Wx;

MyApp->new->MainLoop;

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_2} = Wx::BoxSizer->new(wxVERTICAL);
$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->{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;
undef($abbruch);

for my $i(1..10000) {
$frm->{txt_status}->SetValue("$i. Schleifendurchlauf");
$frm->{txt_status}->Update;

Wx::Yield();
last if $abbruch;
}
}


sub abbrechen_schleife{
my $frm = shift;
$abbruch = 1;
}


package MyApp;
use base 'Wx::App';
sub OnInit { MyFrame->new->Show(1) }

View full thread "Abbruch" Funktion in wxPerl-Programm: Button "abbrechen" wird ignoriert