# Dynamicaly loading panels

**URL:** <https://www.ruby-forum.com/t/dynamicaly-loading-panels/192296>\
**Category:** wxRuby\
**Created:** [July 27, 2010, 10:05pm UTC](https://www.ruby-forum.com/t/dynamicaly-loading-panels/192296 "2010-07-27T22:05:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![plugawy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e495f1/32.png) [@plugawy](https://www.ruby-forum.com/u/plugawy)\
**Post date:** [July 27, 2010, 10:05pm UTC](https://www.ruby-forum.com/t/dynamicaly-loading-panels/192296/1 "2010-07-27T22:05:40Z")

</div>

Hi

I have created my GUI using wxFormBuilder.

One of elements I’ve created is a panel which contains two labels and a  
button - this whole “widget” can be loaded through XRC into a standalone  
class (generated using Xrcise).

Now - adding one one is quite easy:

```
    # create a new instance of the template, @content_panel is a

```

panel on the main window (and has one vertical box sizer)  
status = StatusTemplate.new(@content\_panel)  
status.data= item # my custom method for loading data to the  
widget  
status.show # show it

However when I try to add it few times (in a loop or just by duplicating  
this code) it doesn’t work. Only the most recently added panel can be  
seen.

Any thoughts?

---

<div class="post-metadata">

**Author:** ![plugawy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e495f1/32.png) [@plugawy](https://www.ruby-forum.com/u/plugawy)\
**Post date:** [July 28, 2010, 8:22am UTC](https://www.ruby-forum.com/t/dynamicaly-loading-panels/192296/2 "2010-07-28T08:22:22Z")

</div>

On 27/07/2010 21:05, Åukasz Korecki wrote:

> widget  
> status.show # show it

(This probably isn’t needed - apart from Frames/Dialogs everything else  
starts off shown)

> However when I try to add it few times (in a loop or just by duplicating  
> this code) it doesn’t work. Only the most recently added panel can be  
> seen.

You don’t show the code where you add it to the sizer - you have got  
that? Check the sizer.add parameters, and see what happens if you run  
the same code twice immediately. You may then need to use sizer.layout()  
to update the space given to each.

cheers  
alex

---

<div class="post-metadata">

**Author:** ![plugawy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e495f1/32.png) [@plugawy](https://www.ruby-forum.com/u/plugawy)\
**Post date:** [July 28, 2010, 10:30am UTC](https://www.ruby-forum.com/t/dynamicaly-loading-panels/192296/3 "2010-07-28T10:30:01Z")

</div>

> > widget  
> > status.show # show it
> 
> (This probably isn’t needed - apart from Frames/Dialogs everything else  
> starts off shown)

ah, good to know. wx widgets docs are quite hard to follow because I  
forgot everything I knew about c++

> You don’t show the code where you add it to the sizer - you have got  
> that? Check the sizer.add parameters, and see what happens if you run  
> the same code twice immediately. You may then need to use sizer.layout()  
> to update the space given to each.

I’ve added a sizer to the parent panel in the wxFormBuilder, but when I  
try to find it using Windows.find\_by\_window\_id I get nil. Is there a way  
to get to a sizer contained in the panel?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![plugawy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e495f1/32.png) [@plugawy](https://www.ruby-forum.com/u/plugawy)\
**Post date:** [July 28, 2010, 11:18am UTC](https://www.ruby-forum.com/t/dynamicaly-loading-panels/192296/4 "2010-07-28T11:18:35Z")

</div>

On 28/07/2010 09:30, Åukasz Korecki wrote:

> > You don’t show the code where you add it to the sizer - you have got  
> > that? Check the sizer.add parameters, and see what happens if you run  
> > the same code twice immediately. You may then need to use sizer.layout()  
> > to update the space given to each.
> 
> I’ve added a sizer to the parent panel in the wxFormBuilder, but when I  
> try to find it using Windows.find\_by\_window\_id I get nil. Is there a way  
> to get to a sizer contained in the panel?

A Sizer isn’t a Window, so you will get nil back. All Windows are shown  
on screen and have an id.

There are several methods to get hold of an existing sizer: panel.sizer  
will return the Sizer managing panel’s children, panel.containing\_sizer  
will return the sizer which manages panel.

Alternately, you can hold onto a reference of the sizer you want with an  
instance variable (since you’re loading from XRC, you might navigate the  
sizers once at startup, then stuff it into a var for later use).

alex

---

<div class="post-metadata">

**Author:** ![plugawy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e495f1/32.png) [@plugawy](https://www.ruby-forum.com/u/plugawy)\
**Post date:** [July 29, 2010, 10:39pm UTC](https://www.ruby-forum.com/t/dynamicaly-loading-panels/192296/5 "2010-07-29T22:39:56Z")

</div>

Alex F. wrote:

> A Sizer isn’t a Window, so you will get nil back. All Windows are shown  
> on screen and have an id.

Ah - that explains it all then.

btw. naming widgets “windows” is only more confusing - odd choice I have  
to say.

> There are several methods to get hold of an existing sizer: panel.sizer  
> will return the Sizer managing panel’s children, panel.containing\_sizer  
> will return the sizer which manages panel.

…and that did the trick:

```
    status = StatusTemplate.new(@content_panel)
    status.data= item # my custom method for loading data to the

```

widget  
@content\_panel.sizer.add status

Now I can elements to the list dynamically.

(Now I have to work out how to work with scrollbars ;-))

Thank you very much for your help Alex!

Åukasz
