Query re grid sizer and positioning controls

From: Peter Milliken [mailto:PeterM@resmed.com.au]
Sent: Tuesday, July 08, 2003 9:17 PM
To: 'wxPython List'
Subject: [wxPython-users] Query re grid sizer and positioning controls

Is there any way to define which row and column a control is
to be placed
when adding a control to a GridSizer?

A GridSizer is derived from wxSizer, so all you get is an Add method. When
you add controls the grid is filled in from left to right. I usually tell
it I want 'x' columns and start .Add()ing widgets to the sizer.

I would like to define a grid sizer of multiple columns and
multiple rows. I
would then like to add buttons to the sizer in column 0 and for those
additions to continue into column 0 until all the rows are
filled and then
to start adding into column 1 and so on.

The GridSizer doesn't work like that... You have to add widgets from left to
right. You basically start adding widgets to the "top left" portion of the
grid and they work their way to the right and down. That is, once the
columns have been exhausted for a row (col count declared in ctor), the
sizer begins adding widgets on the next row.

At the moment, just repeated calls to the Add for a GridSizer
seems to be
ordering the controls by row rather than column i.e. row 0 is
filled then
the next added button is row 1, column 0 etc.

See the code below.

In other GUI systems when using a grid layout, you can define
which row and
column the item will occupy - is this behaviour possible with
wxPython?

Sizers are different. They are hard to wrap your mind around at first, but
once you experiment with them, you'll really take a liking to them (sorry,
southern dialect).

I recommend trying a gui builder and experimenting with sizers there.

from wxPython.wx import *

class MyFrame( wxFrame ):
    def __init__( self ):
        wxFrame.__init__( self, None, -1, "Test" )

        # Grid sizer with 2 columns
        szr = wxGridSizer( cols=2 )

        # Create 6 colored panels
        for color in [ wxBLACK, wxWHITE, wxRED, wxBLUE, wxGREEN, wxCYAN ]:
            pnl = wxPanel( self, -1 )
            pnl.SetBackgroundColour( color )
            pnl.SetSize( wxSize( 80, 80 ) )
            szr.Add( pnl )

        self.SetSizer( szr )
        self.SetSize( wxSize( 240, 240 ) )
        self.SetAutoLayout( true )
        self.Layout()
    
class MyApp( wxApp ):
    def OnInit( self ):
        frame = MyFrame()
        frame.Show( true )
        return true

def main():
    app = MyApp(0)
    app.MainLoop()

if __name__ == "__main__":
    main()

HTH,
jw

ยทยทยท

-----Original Message-----