Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Tk:Columns & Execution of Perl scripts

by El Greco (Initiate)
on Aug 21, 2003 at 13:41 UTC ( [id://285459]=perlquestion: print w/replies, xml ) Need Help??

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

Hello monks,

    I will try to be brief with a problem that I have, even though I am not good in being brief. Thanks to all of you who bothered reading it.
I am using perl 5.8 and Tk on a Powerbook, for the past 2 weeks. My experience is minimal but I am tryingl. So while experiencing with Perl and TK I found a module called Tk:Columns so I build a notebook with 3 tabs, and in the 3rd tab, I have a browse button, which selects though a widget only perl files. Once a perl file is selected the insert button put it in the 1st row

$Columns->insert( '0', 1, $base,  $time,  'Running', 'Start', 'Not ready' );

The problems start here :

1) I have done something wrong, and when I select the next perl file to be inserted it doesn't. Somehow my lame programming points at the previous entry.

2) Each column is responsible to do one thing. I need to implement the following but currently I can not.

    1st column should have a number as a reference and increase each time a new line is inserted. So something like $myref = $Row++; which i can't get it to work.How can I refer to the current row ?

    2nd column should show the file. I figured out how to trim the long path and return only the filename, but I have the problem with the pointer mentioned above.

    3rd Column the date, i think is it ok.

    4th Column should have 3 possible dynamic entries, Running, Finished, Failed. How can I check, if a perl program is still running, if there is an error or if it is done. I know how I can execute a perl script and grab its outpt on a text widget.

    5th Column should have a button. Start to start executing the script and stop to stop it. I can do a start button not in the Column widget but how do I assosicate the file name in the 2 column so it can be executed. how can I stop it as well ?

    6th Column , I Think this is the most tricky part. Once the perl scripts, which are not mine are done they generate the output which is vital to me. so filename1.pl should generate in the same folder filename1.log The log is not generated in once, the perl files open and close this filename.log continuously until they finish. How can I understand they have finished and make a button that can open the generated log file in another text widget.


Perhaps my implemention is wrong, so if u suggest alternatives I am glad to follow, in addiion i have read all the newsgroup but apparently there is no way to configure notebook tabs on the right or vertical ?

Thank you ever so much for your time

The code follows ....
use Tk; use English; use File::Basename; use Cwd; require Tk::FileSelect; require Tk::Dialog; require Tk::HList; use diagnostics -verbose; use Tk::Columns; use Tk::DialogBox; use Tk::NoteBook; use Tk::ROText; # and Read-only text box for output panes ######################################################### ## MAIN WINDOW + # ######################################################### my $main = MainWindow->new(); $main->title('My TK_app '); $main->geometry('800x600'); ### A notebook consisted of 3 pages ######## my $notebook = $main->NoteBook( -dynamicgeometry => 'true', -ipadx => 20, -ipady => 6 ); $notebook->pack( -expand => "yes", -fill => "both", -padx => 3, -pady => 3, -side => "top" ); # Divide the working area into my $Config_p = $notebook->add( "config", -label => "Config", -underlin +e => 0 ); my $Tc_p = $notebook->add( "Tc", -label => "Test cases", -underline => + 0 ); my $Viewlog_p = $notebook->add( "Viewlog", -label => "Logs", -underlin +e => 0 ); ## 1ST TAB ################## $input_text_area = $Config_p->Scrolled( 'Text', -wrap => "none", -scrollbars => "se", -width => 40, -height => 25, -background => 'WhiteSmoke' ); $input_text_area->pack( -side => "top", -expand => 1, -fill => 'both' +); $input_text_area->focus(); # gets focus on startup ## 2ST TAB ################## my $l_Window = $Tc_p->TableEdit( '-file' => 'test.dat', ); $l_Window->Item( 'Entry', '-name' => 'Date', '-default' => sub { localtime(); }, ); $l_Window->Item( 'Entry', '-bg' => 'white', '-relief' => 'sunken', '-name' => 'Internet Address', '-expression' => [ '^[0-9]{1,3}?$', '^[0-9]{1,3}?\.$', '^[0-9]{1,3}?\.[0-9]{1,3}?$', '^[0-9]{1,3}?\.[0-9]{1,3}?\.$', '^[0-9]{1,3}?\.[0-9]{1,3}?\.[0-9]{1,3}?$', '^[0-9]{1,3}?\.[0-9]{1,3}?\.[0-9]{1,3}?\.$', '^[0-9]{1,3}?\.[0-9]{1,3}?\.[0-9]{1,3}?\.[0-9]{1,3}?$', ], ); $l_Window->pack( '-expand' => 'true', '-fill' => 'both' ); $l_Window->GeometryRequest( 400, 200 ); ################## 3RD TAB ################## $inputfr = $Viewlog_p->Frame( -relief => 'groove', -label => 'Test cases panel', -borderwidth => 3, )->pack( -side => 'top', -anchor => 'nw', -fill => 'both', ); $incol1fr = $inputfr->Frame( -borderwidth => 2, )->pack( -side => 'left', -anchor => 'nw', -fill => 'both', ); $incol2fr = $inputfr->Frame( -borderwidth => 2, )->pack( -side => 'left', -anchor => 'nw', -fill => 'both', ); $incol3fr = $inputfr->Frame( -borderwidth => 2, )->pack( -side => 'left', -anchor => 'nw', -fill => 'both', ); # Annotation File # $incol1fr->Label( -text => 'Please select your testcase file (*.pl)', +)->pack( -side => 'top', -anchor => 'ne', -pady => 3, ); $testfile_e = $incol2fr->Entry( -text =>'No file selected', -state => 'normal', -textvariable => \$testfile_e, -width => 60, )->pack( -side => 'top', -anchor => 'nw', -pady => 3, ); $incol3fr->Button( -text => 'Browse', -command => [ \&selectsinglefile, \$testfile_e, \$main ], -borderwidth => 1, -padx => 0, -pady => 0, )->pack( -side => 'top', -anchor => 'nw', ); ######## Insert Delete buttons ############## my $but_frame = $Viewlog_p->Frame(); $but_frame->pack( -side => 'bottom', -anchor => "sw", -expand => 0, -fill => 'x', -padx => 0 ); $but_frame->Button( -text => 'Insert', -command => [ \&add_lines ], -borderwidth => 1, -padx => 0, -pady => 0, )->pack( -side => 'left', -anchor => 'nw', ); $but_frame->Button( -text => 'Delete all', -command => [ \&del_lines ], -borderwidth => 2, -padx => 0, -pady => 0, )->pack( -side => 'left', -anchor => 'nw', ); ###################### Columns *****************################# +## my $Columns = $Viewlog_p->Columns ( '-columnlabels' => [qw (No File Date Status Action log )], '-width' => '20', '-height' => '60', '-sortcommand' => '$a cmp $b', '-listforeground' => 'blue4', '-listbackground' => 'beige', '-buttonbackground' => 'gray', '-buttonforeground' => 'black', '-selectmode' => 'extended', '-trimcount' => '2', '-sort' => 'true', ); $Columns->pack( '-anchor' => 'sw', '-expand' => 'false', '-side' => 'top', '-fill' => 'both', ); MainLoop; sub selectsinglefile { my $entryblankref = shift; my $entryblank = $$entryblankref; my $mwref = shift; my $mw = $$mwref; my $filetypes = [ [ 'Perl test cases ', ['.pl'] ], [ 'All files', +['*'] ] ]; my $file = $mw->getOpenFile( -title => "Please choose a configuration file", -filetypes => $filetypes, -defaultextension => ".pl" ); if ( defined $file and $file ne '' ) { $entryblank->delete( 0, 'end' ); $entryblank->insert( 0, $file ); $entryblank->xview('end'); } } sub add_lines { $time=localtime(); ($base,$path,$type) = fileparse($testfile_e); $Columns->insert( '0', 1, $base, $time, 'Running', 'Start', 'Not +ready' ); } sub del_lines { $Columns->delete( 0, 'end' ); }

The perl/tk code
Screenshot 1
Screenshot 2

Replies are listed 'Best First'.
Re: Tk:Columns & Execution of Perl scripts
by RMGir (Prior) on Aug 21, 2003 at 14:20 UTC
    This isn't really going to help, probably.

    But the first thing I thought of when I saw your code was my perlmonks t-shirt:

    "So, you didn't use strict?"

    "And no warnings?"

    "Expect the Inquisitors!!!"

    :)
    --
    Mike

Re: Tk:Columns & Execution of Perl scripts
by converter (Priest) on Aug 21, 2003 at 17:21 UTC

    As RMGir already mentioned, you ought to enable warnings and use strict, this will probably save you some time chasing silly mistakes.

    One problem I noticed is that you're passing a reference to $testfile_e as the -textvariable parameter, then assigning the reference to the Tk::Entry widget returned by the constructor to the same variable. This is not good. The -textvariable parameter should be a reference to a variable that is to contain the content of the Tk::Entry, only. I noticed in your screenshot that the filename Entry shows the widget path (.notebook.viewlog.frame.frame1.entry).

    # line 134 $testfile_e = $incol2fr->Entry( -text =>'No file selected', -state => 'normal', -textvariable => \$testfile_e, -width => 60, )->pack( -side => 'top', -anchor => 'nw', -pady => 3, );

    Try changing the code to something like this:

    # line 134 my $testfile_var; my $testfile_e = $incol2fr->Entry( -text =>'No file selected', -state => 'normal', -textvariable => \$testfile_var, -width => 60, )->pack( -side => 'top', -anchor => 'nw', -pady => 3, );

    That's all I have time for at the moment, I hope that helps.

    converter

      Thank you to both of you that replied.
      I am updating the posted version so it will include the changes that you suggested.
      Regards,
      Vassili

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://285459]
Approved by ybiC
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-04-24 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found