Re: remove a toolbar icon

On 12/30/05, muppet <scott asofyet org> wrote:

On Dec 30, 2005, at 9:16 AM, Dave M wrote:

It's easy enough to add additional icons/elements to a toolbar using
the $toolbar->insert_stock(...). But is there a way to remove an
element? I have a toolbar which adds an element to the toolbar given a
certain action. I'd like to be able to remove it later as well. I
noticed there's a $toolbar->remove_space($position), but this won't
affect non-spaces.

A Gtk2::Toolbar isa Gtk2::Container, so Gtk2::Container's remove()
method should do the trick.

If it's a common need for your toolbar contents to change based on
program actions, you may actually be wanting to use the
Gtk2::UIManager, instead.  This widget allows you to define sets of
actions, and merge these into and out of the UI dynamically.  And the
action-based menus and toolbars are nicer to use, anyway.  ;-)

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) {

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.
Gtk-WARNING **: Can't set a parent on widget which has a parent
Gtk-ERROR **: file gtkcontainer.c: line 2447
(gtk_container_propagate_expose): assertion failed: (child->parent ==
GTK_WIDGET (container)) at ./stuff line 289.

Any hints?
I haven't attempted Gtk2::UIManager yet - what I'm attempting here
seems simple and I'm trying not to have to rewrite lots of code... :)

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