solved 2.: GtkVBox: How to delete widgets?
| From: | Sebastian G. | Date: | Tue, 26 Feb 2002 11:47:58 +0000 |
| Subject: | solved 2.: GtkVBox: How to delete widgets? | ||
| References: | 1 2 3 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-1341@lists.php.net to get a copy of this message | ||
> Sebastian G. wrote:
> > > I have a GtkVBox with a number of labels in it. I need to change the
> > > number of the labels in that box depending on what data I am collecting.
> > > -> How can I delete all the labels in that GtkVBox like I do reset a
> > > GtkCTree with
> > > | $ctree -> clear();
>
> Christoph Muehlmann wrote:
> > I think there is no function like that, but you can make your own:
> >
> > create an new Class like myGtkVBox which extends GtkVBox with a function
> > clear(). In this function you can use the Array containing the childs of
> > the GtkVBox ($gtkvbox->children) and the remove()-function of the
> > parent-parent-class of GtkVBox (GtkContainer is parent of GtkBox is p. of
> > GtkVBox)
>
> Alan Knowles wrote:
> > have a look at the container::children()
> > | $array = $vbox->children()
> > | for ($i=0;$i<count($array);$i++) {
> > | $vbox->remove($array[$i]);
> > | $array[$i]->destroy();
> > | }
> > then you can just add back to the vbox
>
Sebastian G. wrote:
> Here is what I did:
> [...] (The code posted here was wrong)
Hi,
I'm sorry, but I did a mistake. We actually _want_ to delete (destroy)
$box, cause we now create a new widget each time. As follows the new
code:
| $vbox_status_collector = &new GtkVBox();
|
| function init_status() {
| global $vbox_status_collector;
|
| foreach ($vbox_status_collector -> children() as $box) {
| $vbox_status_collector -> remove($box);
| $box -> destroy();
| }
|
| // Labels
| $status_label = &new GtkLabel();
| $status_label -> set_text("Status goes here...");
| // Boxes
| $hbox_status = &new GtkHBox();
| $hbox_status -> pack_end($status_label);
| $vbox_status_collector -> pack_start($hbox_status);
| $status_label -> show();
| $hbox_status -> show();
|
| return true;
| }
and this actually works fine. Thanks to all of you. You should get paid
;)
-- MfG, Sebastian G. <: mailseppel@gmx.de : germany-HH :>