Leser: 2
|< 1 2 >| | 14 Einträge, 2 Seiten |
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
57
58
59
60
61
62
63
64
65
66
#!/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;
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
#!/usr/bin/perl -w
use strict;
use Wx;
MyApp->new->MainLoop;
package MyFrame;
use Wx qw[:everything];
use base 'Wx::Frame';
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;
for my $i(1..1000) {
$frm->{txt_status}->SetValue("$i. Schleifendurchlauf");
$frm->{txt_status}->Update;
}
}
sub abbrechen_schleife{
my $frm = shift;
$frm->Close(1);
}
package MyApp;
use base 'Wx::App';
sub OnInit { MyFrame->new->Show(1) }
Quote$frm->Close(1);
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
#!/usr/bin/perl -w
use Tk;
use strict;
my ($status, $abbruch);
my $Form2 = MainWindow->new;
$Form2->title("StoppLoop");
$Form2->geometry("200x140+8+8");
my $bt_start = $Form2->Button( -text => "starten", -command => \&starte_schleife )->pack(-pady=>10, -padx=>10);
my $txt_status = $Form2->Entry( -textvariable => \$status, -width => '150')->pack(-pady=>10, -padx=>10);
my $bt_stop = $Form2->Button( -text => "stoppen", -command => \sub{$abbruch=1} )->pack(-pady=>10, -padx=>10);
MainLoop;
sub starte_schleife{
undef($abbruch);
for my $i(1..10000){
$status = ($abbruch)?"Abbruch durch Benutzer" : "$i. Schleifendurchgang";
$Form2->update;
$i=10000 if defined $abbruch;
}
}
|< 1 2 >| | 14 Einträge, 2 Seiten |