I tried your script and got the same errors. It piqued my interest because the error seem to occur even when all calls to update meter are removed. If I put a die in the update_meter routine, it was never reached and yet commenting out the $needle->set and $text->set made the errors go away. Very odd. I was testing on Debian Sarge and a colleague tested on Debian unstable. He did not get the errors. I'm assuming that the libraries are different versions. Anyway, I was able to make the errors go away by making these 3 changes: -$window->signal_connect( 'destroy' => \&delete_event ); +$window->signal_connect( 'delete-event' => \&delete_event ); ... sub delete_event { $watch->Unwatch; - $canvas->destroy; Gtk2->main_quit; - return 0; + return 1; } Was there any particular need to destroy the canvas object rather than leaving it to be cleaned up? I've attached a tweaked version of the script that uses a Bezier curve to create a half circle rather than using an ellipse object. Cheers Grant On Mon, 2005-07-11 at 12:58 -0400, zentara wrote:
Hi, I'm trying to make a simple gauge with the Gnome2::Canvas. It all works well, except when I destroy the meter. I get an error nomeCanvas-CRITICAL **: file gnome-canvas.c: line 3698 (gnome_canvas_request_redraw): assertion `GNOME_IS_CANVAS (canvas)' failed during global destruction. I have found through trial and error, that I get this repeated twice, but have found that I can reduce it to 1 by putting a "$canvas->destroy;" in my delete_event subroutine. Additionally, I can stop the error by NOT updating the $text->set(text => $value); in the update_meter sub. So that is my main question, how do I stop this annoying error message, when I update the Canvas Text widget? As a bonus question :-), how do I prevent the $gauge circle from being seen at the bottom, when you drag the main window to a bigger size? I only want an "ARC" , but Ellipse dosn't seem to have limit points available to set. I tried to limit the size of the $canvas, but the circle will still show. Am I forced to mask it with something? Thanks. #Simple Meter ################################################################ #!/usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; use Gnome2::Canvas; use constant PI => 3.1415926; use Tie::Watch; my $width = 200; my $height = 100; my $value = 0; my $max = 100; my $min = 0; my $watch = Tie::Watch->new( -variable => \$value, -shadow => 0, -store => \&update_meter, ); my $window = Gtk2::Window->new; $window->signal_connect( 'destroy' => \&delete_event ); $window->set_default_size( $width, $height ); my $canvas = Gnome2::Canvas->new_aa(); $canvas->set_scroll_region( 0, 0, $width, $height ); #to get upper left corner $canvas->set_size_request( $width, $height ); #useless? $window->add($canvas); $window->show_all; my $root = $canvas->root(); my $text = Gnome2::Canvas::Item->new( $root, 'Gnome2::Canvas::Text', x => $width / 2, y => $height * .50, fill_color => 'yellow', font => 'Sans 14', anchor => 'GTK_ANCHOR_CENTER', text => $value ); my $box = Gnome2::Canvas::Item->new( $root, 'Gnome2::Canvas::Rect', x1 => 0, y1 => 0, x2 => $width, y2 => $height, fill_color => 'black', outline_color => 'black' ); my $hub = Gnome2::Canvas::Item->new( $root, "Gnome2::Canvas::Ellipse", x1 => $width / 2 - 8, y1 => ( $height * .80 ) - 8, x2 => $width / 2 + 8, y2 => ( $height * .80 ) + 8, fill_color => 'white', outline_color => 'black' ); my $gauge = Gnome2::Canvas::Item->new( $root, "Gnome2::Canvas::Ellipse", x1 => $width / 2 - 80, y1 => ( $height * .80 ) - 80, x2 => $width / 2 + 80, y2 => ( $height * .80 ) + 80, outline_color => 'white', fill_color => 'steelblue' ); my $floor = Gnome2::Canvas::Item->new( $root, 'Gnome2::Canvas::Rect', x1 => 0, y1 => $height * .80, x2 => $width, y2 => $height, fill_color => 'black', ); my $needle = Gnome2::Canvas::Item->new( $root, "Gnome2::Canvas::Line", points => [ $width / 2, ( $height * .80 ), $width / 2, 10 ], width_units => 5, fill_color => 'hotpink', last_arrowhead => 1, arrow_shape_b => 20 ); $box->lower_to_bottom; $needle->raise_to_top; $hub->raise_to_top; $text->raise($gauge); my $toggle = 1; my $count = 0; Glib::Timeout->add (50, sub { $count += $toggle; $value = $count; return TRUE; } ); Gtk2->main; ###########################################################3 sub delete_event { $watch->Unwatch; $canvas->destroy; Gtk2->main_quit; return 0; } ###########################################################3 sub update_meter { if ( $value <= $min ) { $toggle = 1 } if ( $value >= $max ) { $toggle = -1 } my $pos = $value * PI/$max; my $x = $width/2 - $height * .80 * ( cos( $pos ) ); my $y = $height * .80 - $height * .80 * ( sin( $pos ) ) ; $needle->set( points => [ $width / 2, ( $height * .80 ), $x, $y ], ); $text->set(text => $value); #causes error message on exit return $value; } ############################################################ __END__
Attachment:
gauge-new.pl
Description: Perl program