RE: [gtk-list] warning/crash removing widgets from box



Would it not be easier to just add all the possible widgets that the box
could ever hold when it is initialized,
and then hide them with gtk_widget_hide (ptr_to_toggle_btn_widget);

Then in the application, when things change, make calls to a function
that works out which should be visible and which should be hidden, then
just call gtk_widget_show() & gtk_widget_hide() on the widgets.

This is more efficient than creating and destroying widgets repeatedly,
as there is an X-windows overhead in realizing a widget, and it also
saves you going through the process of building the widget all over
again assigning signal handlers, etc.

Also, to speed things up even more, declare static pointers that are
global to the module that contains all of your callbacks and widget
definitions for this form, so you dont have to constantly ask GTK to
fetch a pointer for a widget based on the widget name.

hope that helps.
SteveOC
> -----Original Message-----
> From:	Stephen Tell [SMTP:tell@cs.unc.edu]
> Sent:	Tuesday, September 01, 1998 7:21 AM
> To:	GTK Mailing List
> Subject:	[gtk-list] warning/crash removing widgets from box
> 
> 
> In an application I'm writing using Gtk+ (Gtk+ 1.0.4, currently)
> I have a GtkVBox that is to contain zero or more GtkToggleButtons,
> which are added and removed from the box according to other
> user-interface
> operations.
> 
> To remove a button, I have tried either or both of these statements
> (in
> this order, if both are present):
> 	gtk_container_remove(GTK_CONTAINER(wp->lvbox), vw->button);
> 	gtk_widget_destroy(vw->button);
> 
> I thought the above was right, based on a real old posting to the
> gtk-list.
> 
> Whatever I try, when running on HP-UX, I get a lot of runtime warnings
> messages of this form but the button does disappear:
> ** WARNING **: invalid cast from `GtkButton' to `GtkToggleButton'
> ** WARNING **: invalid cast from `(unknown)' to `GtkToggleButton'
> ** WARNING **: invalid cast from `(unknown)' to `GtkToggleButton'
> ** WARNING **: invalid cast from `(unknown)' to `GtkToggleButton'
> ** WARNING **: invalid cast from `(unknown)' to `GtkToggleButton'
> ** WARNING **: invalid cast from `(unknown)' to `GtkToggleButton'
> 
> 
> On Linux I usually get a SIGSEGV, after one or two runtime warnings:
> ** WARNING **: invalid cast from `GtkButton' to `GtkToggleButton'
> ** WARNING **: file gtkcontainer.c: line 359 (gtk_container_remove):
> "widget->parent == GTK_WIDGET (container)"
> ** ERROR **: sigsegv caught
> 
> 
> Adding buttons I do like this, which seems to work fine.  I'm
> explicitly
> creating the label for the button so I can keep a pointer to it for
> use in
> changing the label's text.
> 
> 	vw->label = gtk_label_new(lbuf);
> 	vw->button = gtk_toggle_button_new();
> 	gtk_container_add(GTK_CONTAINER(vw->button), vw->label);
> 	gtk_box_pack_start(GTK_BOX(wp->lvbox), vw->button,
> 			   FALSE, FALSE, 0);
> 	sprintf(lbuf, "wavecolor%d", vw->colorn);
> 	gtk_widget_set_name(vw->label, lbuf);
> 	gtk_widget_show(vw->label);
> 	gtk_widget_show(vw->button);
> 
> elsewhere in the code, the box is set up like this:
> 
> 		wp->lvbox = gtk_vbox_new(FALSE, 0);
> 		gtk_widget_show(wp->lvbox);
> 		gtk_table_attach(GTK_TABLE(wtable->table), wp->lvbox, 
> 			 0, 1, i, i+1, 
> 			 GTK_FILL, GTK_EXPAND|GTK_FILL, 4, 0);
> 
> 
> Thanks!
> Steve
> 
> 
> The application is a waveform viewer for analog data, say from spice
> simulation.  I've thrown a copy into
> http://www.cs.unc.edu/~tell/dist/gwave.tar.gz in case anyone wants to
> look
> at the whole thing. 
> 
> 
> 
> -- 
> Steve Tell | tell@cs.unc.edu | http://www.cs.unc.edu/~tell | KF4ZPF
> Research Associate, Microelectronic Systems Laboratory
> Computer Science Department, UNC@Chapel Hill.   W:919-962-1845
> 
> -- 
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com <
> /dev/null



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]