sizer problem

Hi,
I'm using xrc to subclass a custom panel. Almost all gui stuff is built through
xrc, however I need to add some buttons by hand. Therefor I've added a wx.panel
(which sits inside a wx.boxsizer) to the xrc tree to which I add more
sizers,labels and buttons later. The problem is, that the size of that panel
containing all the manually added controls is not caculated to fit around all
its children. I guess this is due to the fact that at creation time the panel is
empty, right? How can I achieve that the panel size is updated? I tried
panel.Fit() but that didn't help. Of course, if necessary I will post some
sample code.
Regards, Christian

Christian Kristukat wrote:

Hi,
I'm using xrc to subclass a custom panel. Almost all gui stuff is built through
xrc, however I need to add some buttons by hand. Therefor I've added a wx.panel
(which sits inside a wx.boxsizer) to the xrc tree to which I add more
sizers,labels and buttons later. The problem is, that the size of that panel
containing all the manually added controls is not caculated to fit around all
its children. I guess this is due to the fact that at creation time the panel is
empty, right? How can I achieve that the panel size is updated? I tried
panel.Fit() but that didn't help. Of course, if necessary I will post some
sample code.

Try calling Layout on the panel's parent, or on the sizer that the panel belongs to.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Christian Kristukat wrote:

Hi,
I'm using xrc to subclass a custom panel. Almost all gui stuff is
built through
xrc, however I need to add some buttons by hand. Therefor I've added a
wx.panel
(which sits inside a wx.boxsizer) to the xrc tree to which I add more
sizers,labels and buttons later. The problem is, that the size of that
panel
containing all the manually added controls is not caculated to fit
around all
its children. I guess this is due to the fact that at creation time
the panel is
empty, right? How can I achieve that the panel size is updated? I tried
panel.Fit() but that didn't help. Of course, if necessary I will post
some
sample code.

Try calling Layout on the panel's parent, or on the sizer that the panel
belongs to.

I noticed that I'm already calling parent.Fit() and Fit is calling Layout,
right? It looks like the problem is a FlexGridSizer which is part of the
manually added elements. E.g. labels seem to count for the size calculation, the
contents of the flexgridsizer don't. I'm about to boil down a small example.

Btw, I'm really glad I found xrc+xrced. Like this, building GUIs using wxpython
is more than a pleasure. One little thing that popped into my eye which is a
little anoying when using xrced a lot: after having made a change to some
elements properties, the 'save' button is still disabled until the focus is of
the property panel is lost.

Christian

Christian Kristukat wrote:

Robin Dunn wrote:

Christian Kristukat wrote:

Hi,
I'm using xrc to subclass a custom panel. Almost all gui stuff is
built through
xrc, however I need to add some buttons by hand. Therefor I've added a
wx.panel
(which sits inside a wx.boxsizer) to the xrc tree to which I add more
sizers,labels and buttons later. The problem is, that the size of that
panel
containing all the manually added controls is not caculated to fit
around all
its children. I guess this is due to the fact that at creation time
the panel is
empty, right? How can I achieve that the panel size is updated? I tried
panel.Fit() but that didn't help. Of course, if necessary I will post
some
sample code.

Try calling Layout on the panel's parent, or on the sizer that the panel
belongs to.

I noticed that I'm already calling parent.Fit() and Fit is calling Layout,
right? It looks like the problem is a FlexGridSizer which is part of the
manually added elements. E.g. labels seem to count for the size calculation, the
contents of the flexgridsizer don't. I'm about to boil down a small example.

Attached is the code.

Christian

bla.py (1.52 KB)

bla.xrc (1.94 KB)

blaapp.py (263 Bytes)

Christian Kristukat wrote:

Christian Kristukat wrote:
> I noticed that I'm already calling parent.Fit() and Fit is calling
> Layout, right? It looks like the problem is a FlexGridSizer which
> is part of the manually added elements. E.g. labels seem to count
> for the size calculation, the contents of the flexgridsizer don't.
> I'm about to boil down a small example.

Attached is the code.

I found a solution by calling SetSizeHints method on sizer that contains
buttons and also calling the same method on the panel's sizer. Hope this
helps.

class Bla(wx.Panel):
    ...
    def _PostInit(self):
        ...
        self.drawModelButtons(btnpanel)
        frame = self.GetParent()
        self.GetSizer().SetSizeHints(frame)
  # or self.GetSizer().Fit(frame)
        #self.Fit()
        
    def drawModelButtons(self, panel):

        hor = wx.BoxSizer(wx.HORIZONTAL)
  ...
        panel.SetSizer(hor)
        hor.SetSizeHints(panel)

bla2.py (1.66 KB)

···

--
Benjamin

Thank`s a lot! That works. I`ll have a look in the docs what that
method actually does.

Regards, Christian

···

On Wed, 12 Apr 2006, Benjamin Longuet wrote:

Christian Kristukat wrote:

> Christian Kristukat wrote:
> > I noticed that I'm already calling parent.Fit() and Fit is calling
> > Layout, right? It looks like the problem is a FlexGridSizer which
> > is part of the manually added elements. E.g. labels seem to count
> > for the size calculation, the contents of the flexgridsizer don't.
> > I'm about to boil down a small example.
>
> Attached is the code.

I found a solution by calling SetSizeHints method on sizer that contains
buttons and also calling the same method on the panel's sizer. Hope this
helps.

class Bla(wx.Panel):
    ...
    def _PostInit(self):
        ...
        self.drawModelButtons(btnpanel)
        frame = self.GetParent()
        self.GetSizer().SetSizeHints(frame)
  # or self.GetSizer().Fit(frame)
        #self.Fit()
        
    def drawModelButtons(self, panel):

        hor = wx.BoxSizer(wx.HORIZONTAL)
  ...
        panel.SetSizer(hor)
        hor.SetSizeHints(panel)

Benjamin Longuet wrote:

Christian Kristukat wrote:

Christian Kristukat wrote:

I noticed that I'm already calling parent.Fit() and Fit is calling
Layout, right? It looks like the problem is a FlexGridSizer which
is part of the manually added elements. E.g. labels seem to count
for the size calculation, the contents of the flexgridsizer don't.
I'm about to boil down a small example.

Attached is the code.

I found a solution by calling SetSizeHints method on sizer that contains
buttons and also calling the same method on the panel's sizer. Hope this
helps.

class Bla(wx.Panel):
    ...
    def _PostInit(self):
        ...
        self.drawModelButtons(btnpanel)
        frame = self.GetParent()
        self.GetSizer().SetSizeHints(frame)
  # or self.GetSizer().Fit(frame)
        #self.Fit()
        
    def drawModelButtons(self, panel):

        hor = wx.BoxSizer(wx.HORIZONTAL)
  ...
        panel.SetSizer(hor)
        hor.SetSizeHints(panel)

Now I've got a new problem. The minsize is calculated correctly but the buttons
in their default size are far to wide for the frame even with
style=wx.BU_EXACTFIT (there are many of them). I guess it's not possible to set
the SizerHints only for the vertical direction? I tried to reduce the buttons'
size via the size keyword arg, but the FlexGridSizer cells keep their old value
thus resulting in large spacing between tiny buttons.

Cheers, Christian

Christian Kristukat wrote:

Now I've got a new problem. The minsize is calculated correctly but the buttons
in their default size are far to wide for the frame even with
style=wx.BU_EXACTFIT (there are many of them). I guess it's not possible to set
the SizerHints only for the vertical direction? I tried to reduce the buttons'
size via the size keyword arg, but the FlexGridSizer cells keep their old value
thus resulting in large spacing between tiny buttons.

I've been dealing with this by calling sizer.SetItemMinSize(button,
width, height) after adding each button to the sizer - that way, the
sizer won't override the value you give. I'm a little annoyed that I
can't set a preferred size this way, only a min size, though.

(Actually, if it's in a FlexGrid where everything in the column stays
the same size, you just have to do SetItemMinSize on one item in the
column and everything else will follow suit.)

Joe

Christian Kristukat wrote:

Btw, I'm really glad I found xrc+xrced. Like this, building GUIs using wxpython
is more than a pleasure. One little thing that popped into my eye which is a
little anoying when using xrced a lot: after having made a change to some
elements properties, the 'save' button is still disabled until the focus is of
the property panel is lost.

Yeah, that bugs me too. It doesn't check for changes until the user appears to be done editing the items on the panel, and the undo/redo granularity is the same. It was probably done that way to simplify the implementation, but it would definitely be nice to make the changed state sensitive to any micro change on the panel...

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Christian Kristukat wrote:

Now I've got a new problem. The minsize is calculated correctly but the buttons
in their default size are far to wide for the frame even with
style=wx.BU_EXACTFIT (there are many of them). I guess it's not possible to set
the SizerHints only for the vertical direction? I tried to reduce the buttons'
size via the size keyword arg, but the FlexGridSizer cells keep their old value
thus resulting in large spacing between tiny buttons.

I'm not seeing that here. With the size=(10,-1) that you had in your sample the buttons in the initial layout are 10 pixels wide and default height and with no space between them. Setting the size in the constructor is the same as setting the min size (which is also what SetSizeHints does.)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Christian Kristukat wrote:

Now I've got a new problem. The minsize is calculated correctly but
the buttons
in their default size are far to wide for the frame even with
style=wx.BU_EXACTFIT (there are many of them). I guess it's not
possible to set
the SizerHints only for the vertical direction? I tried to reduce the
buttons'
size via the size keyword arg, but the FlexGridSizer cells keep their
old value
thus resulting in large spacing between tiny buttons.

I'm not seeing that here. With the size=(10,-1) that you had in your
sample the buttons in the initial layout are 10 pixels wide and default
height and with no space between them. Setting the size in the
constructor is the same as setting the min size (which is also what
SetSizeHints does.)

I take that back, I can't reproduce it, it's gone. In my real app however the
panel is a notbook page and the outmost sizer (caller 'hor' in the sample code)
is still not calculated correctly. See the image attched. What can I do against
that behaviour?

Reagrds, Christian

Christian Kristukat wrote:

Robin Dunn wrote:

Christian Kristukat wrote:

Now I've got a new problem. The minsize is calculated correctly but
the buttons
in their default size are far to wide for the frame even with
style=wx.BU_EXACTFIT (there are many of them). I guess it's not
possible to set
the SizerHints only for the vertical direction? I tried to reduce the
buttons'
size via the size keyword arg, but the FlexGridSizer cells keep their
old value
thus resulting in large spacing between tiny buttons.

I'm not seeing that here. With the size=(10,-1) that you had in your
sample the buttons in the initial layout are 10 pixels wide and default
height and with no space between them. Setting the size in the
constructor is the same as setting the min size (which is also what
SetSizeHints does.)

I take that back, I can't reproduce it, it's gone. In my real app however the
panel is a notbook page and the outmost sizer (caller 'hor' in the sample code)
is still not calculated correctly. See the image attched. What can I do against
that behaviour?

Are there spacers there, or does it appear to be a size miscalculation of the nested sizers? If you can't figure it out then please try to reproduce it again in the sample app.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Christian Kristukat wrote:

Robin Dunn wrote:

Christian Kristukat wrote:

Now I've got a new problem. The minsize is calculated correctly but
the buttons
in their default size are far to wide for the frame even with
style=wx.BU_EXACTFIT (there are many of them). I guess it's not
possible to set
the SizerHints only for the vertical direction? I tried to reduce the
buttons'
size via the size keyword arg, but the FlexGridSizer cells keep their
old value
thus resulting in large spacing between tiny buttons.

I'm not seeing that here. With the size=(10,-1) that you had in your
sample the buttons in the initial layout are 10 pixels wide and default
height and with no space between them. Setting the size in the
constructor is the same as setting the min size (which is also what
SetSizeHints does.)

I take that back, I can't reproduce it, it's gone. In my real app
however the
panel is a notbook page and the outmost sizer (caller 'hor' in the
sample code)
is still not calculated correctly. See the image attched. What can I
do against
that behaviour?

Are there spacers there, or does it appear to be a size miscalculation
of the nested sizers? If you can't figure it out then please try to
reproduce it again in the sample app.

No, there weren't spacers in there, but again, I can't reproduce it :slight_smile: - at
least not the space between the buttons like in the picture. But I found out
what was the problem here.
It's best illustrated with a modified sample app. If the initial button size is
(50,-1), the manually added sizers are larger than the available space. If you
set it to e.g. (5,-1) they grow to a size which exactly fits.

Regards, Christian

bla.py (1.35 KB)

bla.xrc (16.8 KB)

blaapp.py (352 Bytes)

Christian Kristukat wrote:

Robin Dunn wrote:

Christian Kristukat wrote:

Robin Dunn wrote:

Christian Kristukat wrote:

Now I've got a new problem. The minsize is calculated correctly but
the buttons
in their default size are far to wide for the frame even with
style=wx.BU_EXACTFIT (there are many of them). I guess it's not
possible to set
the SizerHints only for the vertical direction? I tried to reduce the
buttons'
size via the size keyword arg, but the FlexGridSizer cells keep their
old value
thus resulting in large spacing between tiny buttons.

I'm not seeing that here. With the size=(10,-1) that you had in your
sample the buttons in the initial layout are 10 pixels wide and default
height and with no space between them. Setting the size in the
constructor is the same as setting the min size (which is also what
SetSizeHints does.)

I take that back, I can't reproduce it, it's gone. In my real app
however the
panel is a notbook page and the outmost sizer (caller 'hor' in the
sample code)
is still not calculated correctly. See the image attched. What can I
do against
that behaviour?

Are there spacers there, or does it appear to be a size miscalculation
of the nested sizers? If you can't figure it out then please try to
reproduce it again in the sample app.

No, there weren't spacers in there, but again, I can't reproduce it :slight_smile: - at
least not the space between the buttons like in the picture. But I found out
what was the problem here.
It's best illustrated with a modified sample app. If the initial button size is
(50,-1), the manually added sizers are larger than the available space. If you
set it to e.g. (5,-1) they grow to a size which exactly fits.

When you pass a size to the constructor for most widgets it sets the widget's min size and the sizer pays attention to that.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!