[opendemo-cvs] CVS: opendemo/tools/odcut odcutgui.pm,1.42,1.43
Status: Beta
Brought to you by:
girlich
From: Uwe G. <gi...@us...> - 2004-10-25 17:07:46
|
Update of /cvsroot/opendemo/opendemo/tools/odcut In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5277 Modified Files: odcutgui.pm Log Message: Add a new process class, which can call my own function but nor with EVT_END_PROCESS. Don't allow double start of sub-process (not complete). Remember the pid of the started process to make a later kill easier. Add a function to explicitely kill the sub-process. Index: odcutgui.pm =================================================================== RCS file: /cvsroot/opendemo/opendemo/tools/odcut/odcutgui.pm,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** odcutgui.pm 24 Oct 2004 19:28:55 -0000 1.42 --- odcutgui.pm 25 Oct 2004 17:07:35 -0000 1.43 *************** *** 30,33 **** --- 30,34 ---- use Wx::Event qw(EVT_MENU EVT_SLIDER EVT_BUTTON EVT_TIMER EVT_CHECKBOX EVT_SPINCTRL EVT_NOTEBOOK_PAGE_CHANGED EVT_IDLE EVT_END_PROCESS); use Wx qw(:filedialog); + use Wx qw(wxSIGTERM); use Wx::Html; *************** *** 222,226 **** # end of sub process ! EVT_END_PROCESS( $self, -1, \&OnEndProcess ); $self; --- 223,227 ---- # end of sub process ! # EVT_END_PROCESS( $self, -1, \&OnEndProcess ); $self; *************** *** 597,611 **** - sub OnEndProcess($) - { - my ($self) = @_; - - print "process terminated\n"; - Wx::LogMessage( "Process terminated" ); - $self->{"odgame"}->Destroy; - undef $self->{"odgame"}; - } - - sub OnGameStart($) { --- 598,601 ---- *************** *** 622,626 **** # Clean up. if (exists $self->{"odgame"}) { ! OnEndProcess($self); } --- 612,618 ---- # Clean up. if (exists $self->{"odgame"}) { ! EndGame($self); ! Wx::LogMessage( "First Terminate Sub Process. Try again." ); ! return; } *************** *** 640,646 **** ]; ! $self->{"odgame"} = Wx::Process->new($self); $self->{"odgame"}->Redirect(); ! Wx::ExecuteArgs( @command, 0, $self->{"odgame"} ); # Timer --- 632,638 ---- ]; ! $self->{"odgame"} = odprocess->new($self); $self->{"odgame"}->Redirect(); ! $self->{"odgame_pid"} = Wx::ExecuteArgs( @command, 0, $self->{"odgame"} ); # Timer *************** *** 649,652 **** --- 641,668 ---- + sub EndGame($) + { + my ($self) = @_; + + if (exists $self->{"odgame_pid"}) { + if (Wx::Process->Exists($self->{"odgame_pid"})) { + Wx::Process->Kill($self->{"odgame_pid"}, wxSIGTERM); + delete $self->{"odgame_pid"}; + } + } + } + + + sub OnProcessEnd($) + { + my ($self) = @_; + + print "process terminated\n"; + Wx::LogMessage( "Sub Process terminated" ); + $self->{"odgame"}->Destroy; + undef $self->{"odgame"}; + } + + sub StartGameTimer($) { *************** *** 915,919 **** $waitsec = 0.01; } ! printf STDERR "Start timer in %fsec ... ", $waitsec; if (!exists $self->{TIMER}) { $self->{TIMER} = odinteractivetimer->new($self); --- 931,935 ---- $waitsec = 0.01; } ! # printf STDERR "Start timer in %fsec ... ", $waitsec; if (!exists $self->{TIMER}) { $self->{TIMER} = odinteractivetimer->new($self); *************** *** 932,936 **** { my ($self, $event) = @_; ! print STDERR "Handling a timer event.\n"; my $output = $self->{"output"}; $self->UpdateMoving(); --- 948,952 ---- { my ($self, $event) = @_; ! # print STDERR "Handling a timer event.\n"; my $output = $self->{"output"}; $self->UpdateMoving(); *************** *** 943,946 **** --- 959,993 ---- + package odprocess; + + use strict; + use vars qw(@ISA); + @ISA = qw(Wx::Process); + + sub new($$) + { + # Get the class name + my $class = shift; + # Init the super class Wx::Process. + my $self = $class->SUPER::new(); + # Remember the object itself. + $self->{"object"} = shift; + + return $self; + } + + + sub OnTerminate($$$) + { + my( $process, $pid, $status) = @_; + my $self = $process->{"object"}; + $self->OnProcessEnd(); + sprintf STDERR "Process '$pid' terminated with status $status"; + } + + + ###################################################################### + + package odinteractivetimer; *************** *** 949,953 **** ! sub new { # Get the class name. my $class = shift; --- 996,1001 ---- ! sub new($$) ! { # Get the class name. my $class = shift; *************** *** 965,969 **** my ($self) = @_; my $object = $self->{"object"}; ! printf STDERR "Overriding Notify works"; $object->OnTimer(1); } --- 1013,1017 ---- my ($self) = @_; my $object = $self->{"object"}; ! # printf STDERR "Overriding Notify works"; $object->OnTimer(1); } |