On 12/31/05, muppet <[EMAIL PROTECTED]> wrote:
>
> On Dec 31, 2005, at 8:59 AM, Dave M wrote:
>
> > Ok, here's what I have:
> > my $toolbar = Gtk2::Toolbar->new;
> > (...several Gtk2::ToolButton->new_from_stock('gtk-stuff') here...)
> > my $new_button = Gtk2::ToolButton->new_from_stock('gtk-foo') # to
> > be added later
> >
> > later in code:
> > if($blah) {
> > $toolbar->insert($new_button, -1); # <- this part seems to work
> > } elsif($foo) {
> > $toolbar->remove($new_button);
> > }
> >
> > These are the errors that are showing during this process:
> > Gtk-CRITICAL **: gtk_toolbar_remove: assertion `content_to_remove !=
> > NULL' failed at ./stuff line 1064.
>
> This assertion comes from inside the GtkToolbar virtual handler for
> GtkContainer::remove; it means that you're trying to remove a widget
> that wasn't in the toolbar. You're probably getting into the -
> >remove branch on $new_button before $new_button has been added to
> the toolbar.
>
> > Gtk-WARNING **: Can't set a parent on widget which has a parent
> > Gtk-ERROR **: file gtkcontainer.c: line 2447
>
> Here you've tried to add to a container a widget that is already in a
> different container. You have to either remove first or reparent it.
>
> > (gtk_container_propagate_expose): assertion failed: (child->parent ==
> > GTK_WIDGET (container)) at ./stuff line 289.
> > Aborted
>
> This is probably just the result of broken invariants in the rest of
> the code.
>
> > Any hints?
>
> It would probably be easier just to add all of the buttons to the
> toolbar up front, then show and hide them as needed, and thus avoid
> all this reparenting stuff.
>
> (The meticulous and error-prone bookkeeping here is why i suggested
> UIManager. ;-)
>
Ok, I'm finally starting to listen... :)
I switched my menubar over to Gtk2::UIManager, and although unrelated,
it solved a different problem.
I figured out the quick-n-dirty method for the toolbar problem,
though. Basically I just count the number of "children" the toolbar
has with $toolbar->get_children.
If it has the original number of ToolButtons (say, 7) then the toolbar
"knows" to create and insert $new_item. But if it has, say, 8 children
and I want it removed, I just hide it with $new_item->hide(); bringing
it back is easy with $new_item->show().
Took me awhile. Should've just listened in the first place. ;) Thanks again.
_______________________________________________
gtk-perl-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list