Dynamicaly loading panels

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?

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

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!

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs