PerlingTheUK has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
Perplexity hardly only comes once, so please excuse me posting two questions within so short a time.
I have a new Tk widget, created as a custom widget as described in Mastering Perl Tk. All similar widgets work fine. This one (derived from a dialog) does not show and the application hangs when it is called. A print statement at the end of the Populate method prints fine. I am not sure where to look for reasons why it hangs next.
The script is running Perl 5.8.6 on xp home SP2. One thing I have never noticed before is that usually when perl hangs it takes most of the CPU usage. In this case it troddles at less than 25% while csrss.exe get most of the remaining cpu load. What can cause this?
Thank you for all help.

Cheers,
PerlingTheUK
  • Comment on Custom TK Widget Endless Loop - but where?

Replies are listed 'Best First'.
Re: Custom TK Widget Endless Loop - but where?
by graff (Chancellor) on May 30, 2005 at 20:33 UTC
    Since you aren't showing us any code, the best I can suggest is that you compare the failing widget code with code for one of the "similar widgets" that "work fine". If you have the unix-style "diff" command available, use that. Look for things in the working code that might be missing from the failing code, and vice-versa.

    Apart from that, check for any looping constructs in the failing code to see if there might be conditions where it can't get out of the loop.

      Basically all code is just a change of the elements defined in the Populate method.
      $Gui::DlgProcessDelay::VERSION = 0.1; package Gui::DlgProcessDelay; use Tk::widgets qw/Label Button Entry/; use base qw/Gui::DlgBasic/; use strict; use warnings; use Carp qw/carp cluck/; use Data::Dumper; Construct Tk::Widget 'DlgProcessDelay'; # Initialising the object # sub ClassInit{ my ( $class, $mw ) = @_; $class->SUPER::ClassInit( $mw ); } # END: ClassInit # Populating the widget sub Populate{ my ( $self, $args ) = @_; $self->SUPER::Populate( $args ); $self->ConfigSpecs( -xlssource => [qw/METHOD xlssource XlsSource/], -xlstarget => [qw/METHOD xlstarget XlsTarget/], ); $self->{ _frmDelay } = $self->Frame( -label => "Delay Data" ) ->grid( -row => 0, -column => 0, -sticky => 'w' ); $self->{ _frmDelay }->Label( -text => "Delay Source:" ) ->grid( -row => 0, -column => 0, -sticky => 'w' ); $self->{ _frmDelay }->Label( -text => "Import Delay Data:" ) ->grid( -row => 0, -column => 1, -sticky => 'w' ); $self->{ _entDelayData } = $self->{ _frmDelay }->Entry( -textvariable => \$self->{ _sXlsSourc +e }, -borderwidth => 2, -width => 60, -relief => 'groove' ) ->grid( -row => 1, -column => 1, -columnspan => 3, -sticky => 'w' ); $self->{ _frmDelay }->Button( -text => "...", -command => sub { $self->_getXlsSource(); } ) ->grid( -row => 2, -column => 2, -sticky => 'w' ); $self->{ _frmDelay }->Button( -text => "Import File", -command => sub { $self->_importXlsFile(); } ) ->grid( -row => 2, -column => 3, -sticky => 'w' ); } # end Populate # Configure the delay import sourcefile name # sub xlssource{ my $self = shift; if ( @_ > 0 ) { my $file = shift; if ( -e $file ) { $self->{ _sXlsSource } = $file; } # END: if ( -e $file ) else { cluck "You tried to load a file non-existing file."; } # END: else ( -e $file ) } # END: if ( @_ > 0 ) else { # cluck "Monitored a cget on option -ciffile.\n"; return $self->{ _sXlsSource }; # cget( ) requests here } # END: else ( @_ > 0 } } # Configure the xls target name # sub xlstarget{ my $self = shift; if ( @_ > 0 ) { my $file = shift; $self->{ _sXlsTarget } = $file; } # END: if ( @_ > 0 ) else { # cluck "Monitored a cget on option -ciffile.\n"; return $self->{ _sXlsTarget }; # cget( ) requests here } # END: else ( @_ > 0 } } sub _getXlsSource{ my ( $self ) = @_; my $file = Gui::Misc::open_file( $self, "xls" ); $self->configure( -xlssource => $file ); } sub _importXlsSource{ print "Not yet implemented.\n"; } sub _getXlsTarget{ my ( $self ) = @_; my $file = Gui::Misc::save_file( $self, "xls" ); $self->configure( -xlstarget => $file ); } 1;
      It seems to run fine through Populate. But hangs somewhere afterwards.

      Cheers,
      PerlingTheUK
        perhaps it is an issue with the xls path <-- guess, I have to change the perl /'s into \\'s when I work with .xls paths everywhere else
        It appears that your program needs a MainLoop(); statement after the Construct line. (Voice of experience. :-) Also, I don't think you need this but another recent post mentioned the update method that also seemed to be a tonic for situations like this.