Without code, I cannot speak to your recursion problems, but below is code for a progress bar I created for another application.
The progress bar is in another window, but could be adapted to you main canvas. Here is the main constructor sub:
# shows progress of classification
sub progress_ui {
my($top_root) = @_;
$progress_main->destroy
if Exists($progress_main);
$progress_main = $top_root->Toplevel;
my($root) = $progress_main->Frame()->pack(
-fill=>'both',
-expand=>1
);
$progress_main->title('SpikeSort Progress');
$progress_main->iconname('SpikeSortProgress');
# widget creation
my($label_2) = $root->Label (
-text => 'Percentage of trace classified:',
);
# this is global
$progress_canvas = $root->Canvas (
-height => '0',
-highlightthickness => '0',
-width => '0',
);
my($label_1) = $root->Label (
-textvariable => \$spikes_found,
);
# Geometry management
$label_2->grid(
-in => $root,
-column => '1',
-row => '1'
);
$progress_canvas->grid(
-in => $root,
-column => '1',
-row => '2',
-sticky => 'nesw'
);
$label_1->grid(
-in => $root,
-column => '1',
-row => '3'
);
# Resize behavior management
# container $root (rows)
$root->gridRowconfigure(1, -weight => 0, -minsize => 30);
$root->gridRowconfigure(2, -weight => 0, -minsize => 80);
$root->gridRowconfigure(3, -weight => 0, -minsize => 30);
# container $root (columns)
$root->gridColumnconfigure(1, -weight => 0, -minsize => 420);
# additional interface code
# draw the thermometer of progress..
$progress_canvas->create(
'line', '25', '40', '395', '40',
-width => '40',
-fill => 'black',
-cap => 'butt',
);
}
The bar is just a thick line and to update the progress bar, just draw a line a little longer each time:
...
elsif ( $added_text =~ /^sample index: (\d+)/ ) {
$progress_width = 25 + 370 * $1 / $total_samples;
$progress_canvas->create(
'line', '25', '40', $progress_width, '4
+0',
-width => '40',
-fill => 'blue',
-cap => 'butt',
)
if $progress_canvas;
}
...
IIRC, the process of creating the line updates the canvas directly.
-Mark |