[wxPython] RowColSizer in wxBoxSizer -- incorrect layout

The following simplest code demonstrates the arrangement of nested
sizers I need. The text control from the RowColSizer should appear under
that in the wxFlexGridSizer. Insted of that it is shifted up and right
(to the area of the title) on my system (WindowsNT, Python-2.2.1,
wxPython-2.3.3pre3).

Is that a bug or did I misused something?

from wxPython.wx import *
from wxPython.lib import rcsizer

class myframe(wxFrame):
    def __init__(self):
        wxFrame.__init__(self, None, -1, 'test')
        panel = wxPanel(self, -1)
        panel.SetAutoLayout(true)
        left = wxPanel(panel, -1)
        left.SetAutoLayout(true)
        ctrl1 = wxTextCtrl(left, -1, 'in wxFlexGridSizer')
        grid1 = wxFlexGridSizer()
        grid1.Add(ctrl1)
        ctrl2 = wxTextCtrl(left, -1, 'in RowColSizer')
        grid2 = rcsizer.RowColSizer()
        grid2.Add(ctrl2, pos=(0,0))

        border = wxBoxSizer(wxVERTICAL)
        border.Add(wxStaticText(left, -1, 'Title'), 0,
wxALL>wxALIGN_CENTER, 10)
        border.Add(grid1, 0, wxLEFT|wxRIGHT, 10)
        border.Add(grid2, 0, wxLEFT|wxRIGHT, 10)
        left.SetSizer(border)
        border.Fit(left)

        right = wxPanel(panel, -1)
        right.SetBackgroundColour(wxGREEN)
        main_sizer = wxBoxSizer(wxHORIZONTAL)
        main_sizer.Add(left, 0, wxEXPAND)
        main_sizer.Add(right, 1, wxEXPAND)
        panel.SetSizer(main_sizer)

        self.Show(true)

class App(wxApp):

    def OnInit(self):
        frame = myframe()
        self.SetTopWindow(frame)
        return true

app = App()
app.MainLoop()

···

--
Géza Groma
Institute of Biophysics,
Biological Research Center of Hungarian Academy of Sciences
Temesvári krt.62.
6726 Szeged
Hungary
phone: +36 62 432 232
fax: +36 62 433 133

The following simplest code demonstrates the arrangement of nested
sizers I need. The text control from the RowColSizer should appear under
that in the wxFlexGridSizer. Insted of that it is shifted up and right
(to the area of the title) on my system (WindowsNT, Python-2.2.1,
wxPython-2.3.3pre3).

Is that a bug or did I misused something?

It's a bug. Here's a patch that fixes it:

Index: wxPython/wxPython/lib/rcsizer.py

···

===================================================================
RCS file: /home/wxcvs/wxWindows/wxPython/wxPython/lib/rcsizer.py,v
retrieving revision 1.2
diff -u -4 -r1.2 rcsizer.py
--- wxPython/wxPython/lib/rcsizer.py 8 Mar 2002 23:06:21 -0000 1.2
+++ wxPython/wxPython/lib/rcsizer.py 22 May 2002 17:02:43 -0000
@@ -155,22 +155,21 @@
         cpos = [0] * len(self.colWidths)

         for i in range(len(self.rowHeights)):
             height = self.rowHeights[i]
- rpos[i] = px
- px += height
+ rpos[i] = py
+ py += height

         for i in range(len(self.colWidths)):
             width = self.colWidths[i]
- cpos[i] = py
- py += width
+ cpos[i] = px
+ px += width

         # iterate children and set dimensions...
         for item in self.GetChildren():
             r, c, r2, c2 = item.GetUserData()
             width = reduce( operator.add, self.colWidths[c:c2] )
             height = reduce( operator.add, self.rowHeights[r:r2] )
- #item.SetDimension( (cpos[c], rpos[r]), (width, height))
             self.SetItemBounds( item, cpos[c], rpos[r], width, height )

     #--------------------------------------------------

[snip]

Thanks for the patch. The only minor issue remained is that if I put an
empty RowColSizer to the wxBoxSizer I get the following error:

Traceback (most recent call last):
  File "C:\Python22\lib\site-packages\wxPython\lib\rcsizer.py", line 154, in
RecalcSizes
    rpos = [0] * len(self.rowHeights)
AttributeError: RowColSizer instance has no attribute 'rowHeights'

I suggest it to shift the

        self.rowHeights =
        self.colWidths =

statements to the beginning of the CalcMin() procedure.

Regards,
Geza Groma

···

----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Wednesday, May 22, 2002 7:04 PM
Subject: Re: [wxPython] RowColSizer in wxBoxSizer -- incorrect layout

> The following simplest code demonstrates the arrangement of nested
> sizers I need. The text control from the RowColSizer should appear under
> that in the wxFlexGridSizer. Insted of that it is shifted up and right
> (to the area of the title) on my system (WindowsNT, Python-2.2.1,
> wxPython-2.3.3pre3).
>
> Is that a bug or did I misused something?

It's a bug. Here's a patch that fixes it:

I suggest it to shift the

        self.rowHeights =
        self.colWidths =

statements to the beginning of the CalcMin() procedure.

Thanks.

···

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