in reply to Re: How to perform a subroutine run in cpan Tk::ExecuteCommand module
in thread How to perform a subroutine run in cpan Tk::ExecuteCommand module

Hi Zentara, I tried to apply your hint of can use the configure command every where finally enable my output result shown on the text widget. Thank you! Though there's seem to have the extra entry and button in the form, but it at least solve my problem on showing test in the widget. However is there a way to print plain font to the text widget in Tk::ExecuteCommand say if I don't want to set a couple of mini scripts for simple info message? I tried to print this to the text widget, but it execute like treating it as a script, complaining missing file or directory but it is in fact it is just a pure info text to user.

My code as below

my $first_line = "Start running project 1...please wait"; $ec_pc->configure(-command=> $first_line); $ec_pc->execute_command; $ec_pc->update;

And, below is what is shown within the test widget:

'Start running project 1...please wait' : No such file or directory

Replies are listed 'Best First'.
Re^3: How to perform a subroutine run in cpan Tk::ExecuteCommand module
by zentara (Cardinal) on Jun 26, 2014 at 11:00 UTC
    is there a way to print plain font to the text widget in Tk::ExecuteCommand say if I don't want to set a couple of mini scripts for simple info message? ....
    'Start running project 1...please wait' : No such file or directory

    You have a serious misunderstanding of what is going on. Tk::ExecuteCommand is designed to do just that .... execute a command , which means sending a valid command to a shell to be run. What you want to do is just plainly run some perl code and have it's output in the Text widget.

    For the question of killing a running command, make another button labeled 'Stop', and use Tk::ExecuteCommand's $exec->kill_command;

    my $kill_button = $mw->Button( -text => 'Stop', -command=> sub{ $exec->kill_command; } )->pack();

    As to your other problem of sending plain text messages to the Text Widget, instead of a command, you will need to figure out a way in your subroutine of determining if you have a valid command, or just an informational message. If it's an information message, you can write it directly into the ROText subwidget like the following:

    #!/usr/bin/perl use Tk; use Tk::ExecuteCommand; my $mw = MainWindow->new; $ec = $mw->ExecuteCommand( -command => '', -entryWidth => 50, -height => 10, -label => '', -text => 'Execute', )->pack; $ec->configure( -command => 'dir' ); $ec->execute_command; $ec->bell; $ec->update; # read perldoc Tk::ExecuteCommand for the Advertised Widget section my $ROText = $ec->Subwidget('text'); print "$ROText\n"; $ROText->configure(-bg=>'white'); $ROText->insert('end', "\n\nHi, this is a message\n\n"); $ROText->see('end'); #execute some perl code and output it to the text widget &do_something; MainLoop; sub do_something{ # the Tk::ExecuteCommand kill button won't stop this for (1..5){ $ROText->insert('end', "$_\n"); $ROText->see('end'); } }

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

      Hi Zentara, I couldn't help to express my thankfulness to you, your explanation and sample codes did help me to clear my doubts and misunderstanding on all those that I found by googling, which bothering me since the past weeks. Now I'm much clearer on the usage and how to apply both the ROText and ExecuteCommand in my codes. Yeah.. the explanation with sample codes means a lot! ALso, not forget to thanks all those who take the trouble on replying to me- Corion and RonW. I'm so excited to implement that in my real code now! Thanks a bunch!

      Hi Zentara, I have one extra question regarding the text widget gui, is that possible to change the vertical scrollbar to the right hand side instead of current position on the left sided.

        You probably will have to dig into the "advertised widgets" of Tk::ExecuteCommand, find the scrolled frame, then issue a configure command to it. -scrollbars => 'osoe'

        This code change does it:

        # read perldoc Tk::ExecuteCommand for the Adverised Widget section my $ROText = $ec->Subwidget('text'); print "$ROText\n"; $ROText->configure(-scrollbars => 'osoe');

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