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

Hi monks!;)
I need help with this:

I've got ExecuteCommand widget into which I write results of other script I execute.

But I need to have there also a Button which will stop/start scrolling in the ExecuteCommand window (the text will be still added and the commands running, but it'll not scroll = I'll see only the part of there results where I stopped it - it won't run up) the ExecuteCommand code looks like this:
$executecommand = $top->ExecuteCommand(-height => 10, -scrollbars => 'ose', bg => 'white' )->pack(-expand => 'yes', -fill =>'both'); $executecommand->terse_gui; $executecommand->bell; $executecommand->update;
Thanks a lot!
dzon

Replies are listed 'Best First'.
Re: Tk::ExecuteCommand stop scrolling
by thundergnat (Deacon) on Jul 05, 2005 at 16:17 UTC
    But I need to have there also a Button which will stop/start scrolling in the ExecuteCommand window

    You can't. At least you can't without rewriting/overriding a private method of Tk::ExecuteCommand.

    The _read_stdout sub is the problem.

    sub _read_stdout { # Called when input is available for the output window. Also chec +ks # to see if the user has clicked Cancel. my($self) = @_; if ($self->{-finish}) { $self->kill_command; } else { my $h = $self->{-handle}; if ( sysread $h, $_, 4096 ) { my $t = $self->Subwidget('text'); $t->insert('end', $_); $t->yview('end'); } else { $self->{-finish} = 1; } } } # end _read_stdout

    That line: $t->yview('end'); is the problem. Every time it reads anything from the handle, it is going to scroll to the end of the text widget. It would be fairly trivial to modify the sub to scroll unless a "no scroll" flag is set, and you could easily modify it locally. It may be worth emailing the module author and asking to have that functionality added. I have found Steve to be relatively receptive to comments and requests.

Re: Tk::ExecuteCommand stop scrolling
by zentara (Cardinal) on Jul 05, 2005 at 17:12 UTC
    I have to go somwhere right now, but the ExecuteCommand widget has "subwidget" accessibility. So you can get to the text widget with
    my $dtext = $executecommand->Subwidget('text'); $dtext->configure( -background => 'black', -foreground => 'green', );
    So you probably could work out some way to hold your scroll position. You can get to the widget, so now your question is how to controll your scroll in a text widget. Off hand I would say when you press your button, get the lastline of the textbox at that moment, and run some timer, to hold you there. Over on comp.lang.perl.tk there is a fellow named Jack D., he is the textbox wizard. Maybe ask there, if no luck here.

    I'm not really a human, but I play one on earth. flash japh
Re: Tk::ExecuteCommand stop scrolling
by zentara (Cardinal) on Jul 05, 2005 at 19:59 UTC
    On further thought, trying to force the text scroll view to a line number, while something else is sending it to the 'end', is asking for "jitter". I think your intent is to be able to "freeze and read" something of interest in the output. What your best option would be, is to have a button which makes a copy of the the text, at the instant, and opens it as a copy in a second text box in another toplevel window. That way you can take your time to read it, and not interfere with the output. If you need help on how to open a toplevel, with a copy of the text, let us know.

    I'm not really a human, but I play one on earth. flash japh
      Really thanks for your comments!
      I'm a beginner with Perl/Tk so what you mean by "asking for "jitter""?
      If it's not possible to make it in the same window without changing the ExecuteCommand module or in some other difficult way, I like also that idea with that another toplevel widget.
      So please can you help me how to open a toplevel, with a copy of the text?
      Thanks!
        By "jitter" I mean the visual effect of 2 different subs trying to move the scrollbar to different points. If you watch it, the scrollbar handle will look like a little Mexican Jumping bean. :-) Here is an example. First the test script, followed by the Tk code.
        ### test script #!/usr/bin/perl use warnings; use strict; $|++; for (1..10000){ print "$_\n"; select(undef,undef,undef,.1); } __END__ ######################################## #!/usr/bin/perl -w use Tk; use Tk::ExecuteCommand; use strict; my $mw = MainWindow->new; #create and hide toplevel############ my $tl = $mw->Toplevel(); $tl->withdraw; my $snaptext = $tl->Scrolled('Text', -background=>'lightsteelblue', -foreground=>'black', )->pack(); $tl->Button(-text =>'Close', -command => sub{$tl->withdraw })->pack(); ####################################### my $ec = $mw->ExecuteCommand( -command => '', -entryWidth => 50, -height => 10, -label => '', -text => 'Execute', )->pack; my $dtext = $ec->Subwidget('text'); $dtext->configure( -background => 'black', -foreground => 'yellow', ); $mw->Button(-text => "Snap Shot", -command => sub{ my $time = localtime; my $gettext = $dtext->get('end -10 lines', 'end'); $snaptext->insert('end',"\n##$time\n$gettext\n###end time +\n"); $snaptext->see('end'); $tl->deiconify; })->pack(); $ec->configure(-command => './test'); $ec->execute_command; MainLoop;

        I'm not really a human, but I play one on earth. flash japh