Forum: wxRuby Dynamicaly loading panels

Posted by Łukasz Korecki (plugawy)
on 2010-07-27 22:05
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?
Posted by Alex Fenton (Guest)
on 2010-07-28 08:22
(Received via mailing list)
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
Posted by Łukasz Korecki (plugawy)
on 2010-07-28 10:30
>> 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!
Posted by Alex Fenton (Guest)
on 2010-07-28 11:18
(Received via mailing list)
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
Posted by Łukasz Korecki (plugawy)
on 2010-07-29 22:39
Alex Fenton 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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.