in reply to Re^2: how to display output of a process in text widget in real time
in thread how to display output of a process in text widget in real time

Great to hear that you've made progress! I don't have much to go on here as you haven't shown your button code. My button "works" so you will have to figure out what is different between what you are doing and what I did.

Try to boil the problem down to the simplest set of code possible that still illustrates the problem. Sometimes that process itself results in some enlightenment. If it doesn't, post the code here and we'll look at it. Without seeing the code, it would just be guessing on my part.

  • Comment on Re^3: how to display output of a process in text widget in real time

Replies are listed 'Best First'.
Re^4: how to display output of a process in text widget in real time
by perlnu (Initiate) on Jul 12, 2011 at 22:20 UTC
    Thanks again Marshall - the piece of the code is included below. In the meantime I am trying to figure this out as well...
    sub copy_project { # first check for null for Project Name # bail out if Project Name is null if ( !defined $open_source_project_file ) { print "Select Source Project file (.cpm)\n"; exit(); } # check to ensure that project location # is selected by user if ( !defined $destination_project_loc ) { print "Destination project location not specified!\n"; exit(); } # check to ensure that destination project # folder is specified by user if ( !defined $destination_proj_folder ) { print "Destination Project Folder not specified!\n"; exit(); } else { # check for spaces in project name &check_destination_folder_for_spaces; # check to ensure underscore in project name &check_destination_for_underscores; } # check to ensure that directory by the # name of Project Name does not already # exist at Project Location # Following three cases to be considered: # 1. Directory exists but is empty # 2. Directory exists, and not empty, bail out, and ask user for new p +roject name # 3. Directory does not exist if ( -d $destination_project_loc . "/" . $destination_proj_folder +) { # check to ensure this dir. is empty opendir( DIRH, $destination_project_loc . "/" . $destination_proj_folder +); my @dest_proj_folder_files = grep { $_ ne '.' and $_ ne '..' } readdir(DIRH); closedir(DIRH); if (@dest_proj_folder_files) { my $project_dir_exists_error = $mw->messageBox( -title => "Error in Project Name", -message => 'Project Name directory exists, and is non + empty!', -type => 'RetryCancel', -icon => 'error', ); if ( $project_dir_exists_error eq "Retry" ) { &initialize_all_variables; } else { exit(); } } else { # Project Name directory exists but is empty my $final_copy_project_command = &create_copy_project_comm +and; # get rid of top_frame $top_frame->packForget(); # create and display text widget my $tw = $second_frame->Text()->pack(); my $first_line = "Copying project...please wait"; $tw->insert( 'end', $first_line ); my @read_copy_project_command_output = `$final_copy_project_command`; foreach my $output_line (@read_copy_project_command_output +) { $tw->insert( 'end', $output_line ); } } } else { # Project Name directory does not exist # get rid of top_frame $top_frame->packForget(); # create and display text widget #my $tw = $second_frame->Text()->pack(); my $tw = $second_frame->Scrolled("Text")->pack(); my $first_line = "Copying project...please wait\n"; $tw->insert( 'end', $first_line ); my $final_copy_project_command = &create_copy_project_command; #open(COPY_PROJ, "$final_copy_project_command|"); open( COPY_PROJ, '-|', "$final_copy_project_command" ); my $copy_proj_line; while ( defined( $copy_proj_line = <COPY_PROJ> ) ) { $tw->insert( 'end', $copy_proj_line ); $tw->update(); $tw->see('end'); } } } # This sub is called by copy_project sub create_copy_project_command { # prepare copy_project_command # location of destination project depends on # whether same name project dir exists or not my $location_destination_proj; if ( -d $destination_project_loc . "/" . $destination_proj_folder +) { $location_destination_proj = $destination_project_loc; } elsif ( !-d $destination_project_loc . "/" . $destination_proj_fol +der ) { $location_destination_proj = $destination_project_loc . "/" . $destination_proj_folder; } # new project name is derived from what # the user types in Project Name text box my $new_project_name = $destination_proj_folder; my $new_project_file_name = $new_project_name . "\.cpm"; my $new_design_library_name = $new_project_name . "_lib"; # Design name is same as project name my $new_design_name = $new_project_name; my $license = "Concept_HDL_expert"; my $copy_project_command = "copyproject -proj " . "\"" . $open_source_project_file . "\"" . " \-copytopath " . "\"" . $location_destination_proj . "\"" . " \-newprojname " . "\"" . $new_project_file_name . "\"" . " \-newlib " . "\"" . $new_design_library_name . "\"" . " \-newdesign " . "\"" . $new_design_name . "\"" . " \-product " . "\"" . $license . "\""; return $copy_project_command; }
      I see lots of code, but I don't see any Button code. This might be helpful: I know what I mean. Why don't you?.

      This bit of code looks ominous. Use of a recursive function call is not appropriate for doing retries. Among other things it can chew up a lot of stack space. You don't show what initialize_all_variables() does, but I see no other retry loop going on.

      if ( $project_dir_exists_error eq "Retry" ) { &initialize_all_variables; }
      If the button is "not quickly response" to your letting go of the mouse button, you may have some code that is chewing an incredible amount of CPU time. Again simplify the code down to an example similar in size to the one that I posted.

      Oh this ampersand in front of a subroutine name is an older style. Nowadays, initialize_all_variables(); would be considered better.