get sizer for StaticBox

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

get sizer for StaticBox

John Lane
I'm using a static box and static box sizer. I think I'm using the
correct pattern:

    box = wx.StaticBox(self.content, id, name = name)
    sizer =  wx.StaticBoxSizer(box, orient = wx.VERTICAL)
    self.content_sizer.Add(sizer, flag=wx.EXPAND)

I can then proceed to populate the box, for example:

    sizer.Add(wx.StaticText(box, wx.ID_ANY, name='foo'))

Everything to this point works just fine.

Now, at some point later in the program, I need to add some more stuff
inside the static box. I can find the box:

    box = next((b for b in self.content.GetChildren() if b.GetName() ==
some_name), None)

But I cannot get the sizer. I tried

    sizer = box.GetSizer()

but it returns None.

How, given a StaticBox, can I get its sizer ?

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: get sizer for StaticBox

oneeyeman
Hi,

On Fri, Apr 21, 2017 at 3:30 PM, John Lane <[hidden email]> wrote:

> I'm using a static box and static box sizer. I think I'm using the
> correct pattern:
>
>     box = wx.StaticBox(self.content, id, name = name)
>     sizer =  wx.StaticBoxSizer(box, orient = wx.VERTICAL)
>     self.content_sizer.Add(sizer, flag=wx.EXPAND)
>
> I can then proceed to populate the box, for example:
>
>     sizer.Add(wx.StaticText(box, wx.ID_ANY, name='foo'))
>
> Everything to this point works just fine.
>
> Now, at some point later in the program, I need to add some more stuff
> inside the static box. I can find the box:
>
>     box = next((b for b in self.content.GetChildren() if b.GetName() ==
> some_name), None)
>
> But I cannot get the sizer. I tried
>
>     sizer = box.GetSizer()
>
> but it returns None.
>
> How, given a StaticBox, can I get its sizer ?

Which version of wxPython?

Thank you.

>
> --
> Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
>
> To unsubscribe, send email to [hidden email]
> or visit http://groups.google.com/group/wx-users

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: get sizer for StaticBox

Vadim Zeitlin-4
In reply to this post by John Lane
On Fri, 21 Apr 2017 20:30:17 +0100 John Lane wrote:

JL> I'm using a static box and static box sizer.
...
JL> But I cannot get the sizer. I tried
JL>
JL>     sizer = box.GetSizer()
JL>
JL> but it returns None.
JL>
JL> How, given a StaticBox, can I get its sizer ?

 You need to use GetContainingSizer() because this sizer actually contains
both the static box and the other windows appearing inside it (but which
are actually box's siblings, not children).

 Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/

attachment0 (203 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: get sizer for StaticBox

John Lane
On 26/04/17 13:29, Vadim Zeitlin wrote:

> JL> How, given a StaticBox, can I get its sizer ?
>
>  You need to use GetContainingSizer() because this sizer actually contains
> both the static box and the other windows appearing inside it (but which
> are actually box's siblings, not children).
>
>  Regards,
> VZ
>

Thanks, I worked that out myself a few hours after posing the question.
I do find the relationship between widgets and sizers confusing at times!

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users