Trouble figuring out box sizers

I'm looking into wxPython as a new GUI toolkit to port an application I
have written in Perl/Tk. I'm pretty comfortable with the Perl/Tk way of
doing things, which I think is causing me some mental blocks as I attempt
to use wxPython.

One of the things that's giving me the most grief are the box sizers. I'm
attaching a reduced testcase, which in my mind should lay things out as is
drawn up in the comments of the code. However, everything is placed at
the 0,0 coordinate (top-left corner of the frame). I think I'm still
stuck in the Tk "Pack" mode of thinking, expecting the wxBoxSizer to do
stuff that it's not set up to do.

I'm sure that this is a pretty simple conceptual thing that I'm just not
getting, so I'll be very grateful to the person who can explain to me what
I'm doing wrong.

Thanks,
Wade

##### CODE SAMPLE ####
#!/usr/bin/env python
import sys, os, string
from wxPython.wx import *

class main_window(wxFrame):
  def __init__(self, parent, id, title):
    wxFrame.__init__(self, parent, -1, title, size = (-1, -1), style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)

    # Build the search area
    # This should eventually look like

    # +---------------------------------+
    # | Label [wxChoice] |
    # | |
    # | +---------------------------+ |
    # | | | |
    # | | wxListBox | |
    # | | | |
    # | +---------------------------+ |
    # | |
    # +---------------------------------+

    self.box = wxBoxSizer(wxVERTICAL)

    self.searchareabox = wxBoxSizer(wxVERTICAL)

    self.categorybox = wxBoxSizer(wxHORIZONTAL)
    self.categorybox.Add(wxStaticText(self, -1, "Choose your category"),1,wxEXPAND)
    self.categorybutton = wxChoice(self, 40, choices = [])
    self.categorybox.Add(self.categorybutton,1,wxEXPAND)
    self.searchareabox.Add(self.categorybox,1,wxEXPAND)
    self.box.Add(self.searchareabox,1,wxEXPAND)
    self.categorybutton.Append("Any Category","Any")
    self.categorybutton.Append("Other Category","Other")
    self.categorybutton.SetSelection(0)

    self.mainbox = wxListBox(self, 60, (-1,-1), (-1,-1), [], wxLB_SINGLE)
    self.searchareabox.Add(self.mainbox,1,wxEXPAND)
    self.mainbox.Append("Test Data","Item 1")
    self.mainbox.Append("Test Data 2","Item 2")

    self.Show(true)

class App(wxApp):
  def OnInit(self):
    frame = main_window(None, -1, "Reduced Testcase")
    self.SetTopWindow(frame)
    return true

app = App(0)
app.MainLoop()

H. Wade Minter wrote:
...

One of the things that's giving me the most grief are the box sizers....

Wade,

It looks like you're missing at least a call to SetSizer(). Try reading the code in the WxPy demo, and consult the WxWindows helpfile. You should also be able to find lots of previous "how do I use sizers" threads in the list archives.

hth,
Shi.

try putting in a

    self.SetAutoLayout(true)
    self.SetSizer(self.box)

just above your call to self.Show(true)
The "SetSizer" is the important one - it will connect your widgets and sizers
to the surrounding frame. Make sure you use the outermost sizer as argument
(in your case the self.box)

···

On Thursday 21 November 2002 07:52 am, H. Wade Minter wrote:

I'm looking into wxPython as a new GUI toolkit to port an application I
have written in Perl/Tk. I'm pretty comfortable with the Perl/Tk way of
doing things, which I think is causing me some mental blocks as I attempt
to use wxPython.

One of the things that's giving me the most grief are the box sizers. I'm
attaching a reduced testcase, which in my mind should lay things out as is
drawn up in the comments of the code. However, everything is placed at
the 0,0 coordinate (top-left corner of the frame). I think I'm still
stuck in the Tk "Pack" mode of thinking, expecting the wxBoxSizer to do
stuff that it's not set up to do.

I'm sure that this is a pretty simple conceptual thing that I'm just not
getting, so I'll be very grateful to the person who can explain to me what
I'm doing wrong.

Thanks,
Wade

##### CODE SAMPLE ####
#!/usr/bin/env python
import sys, os, string
from wxPython.wx import *

class main_window(wxFrame):
  def __init__(self, parent, id, title):
    wxFrame.__init__(self, parent, -1, title, size = (-1, -1),
style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)

    # Build the search area
    # This should eventually look like

    # +---------------------------------+
    # | Label [wxChoice] |
    # | |
    # | +---------------------------+ |
    # | | | |
    # | | wxListBox | |
    # | | | |
    # | +---------------------------+ |
    # | |
    # +---------------------------------+

    self.box = wxBoxSizer(wxVERTICAL)

    self.searchareabox = wxBoxSizer(wxVERTICAL)

    self.categorybox = wxBoxSizer(wxHORIZONTAL)
    self.categorybox.Add(wxStaticText(self, -1, "Choose your
category"),1,wxEXPAND) self.categorybutton = wxChoice(self, 40, choices =
)
    self.categorybox.Add(self.categorybutton,1,wxEXPAND)
    self.searchareabox.Add(self.categorybox,1,wxEXPAND)
    self.box.Add(self.searchareabox,1,wxEXPAND)
    self.categorybutton.Append("Any Category","Any")
    self.categorybutton.Append("Other Category","Other")
    self.categorybutton.SetSelection(0)

    self.mainbox = wxListBox(self, 60, (-1,-1), (-1,-1), , wxLB_SINGLE)
    self.searchareabox.Add(self.mainbox,1,wxEXPAND)
    self.mainbox.Append("Test Data","Item 1")
    self.mainbox.Append("Test Data 2","Item 2")

    self.Show(true)

class App(wxApp):
  def OnInit(self):
    frame = main_window(None, -1, "Reduced Testcase")
    self.SetTopWindow(frame)
    return true

app = App(0)
app.MainLoop()

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

--
  UC

--
Open Source Solutions 4U, LLC 2570 Fleetwood Drive
Phone: +1 650 872 2425 San Bruno, CA 94066
Cell: +1 650 302 2405 United States
Fax: +1 650 872 2417

I had a similar such problem, along with many others, when first
starting with wxPython. This wiki page was created to address that
issue. Check this out and hope it helps:

  http://wiki.wxpython.org/index.cgi/UsingSizers

                   -- Mike

···

On Thu, Nov 21 @ 10:52, H. Wade Minter wrote:

I'm looking into wxPython as a new GUI toolkit to port an application I
have written in Perl/Tk. I'm pretty comfortable with the Perl/Tk way of
doing things, which I think is causing me some mental blocks as I attempt
to use wxPython.

One of the things that's giving me the most grief are the box sizers. I'm
attaching a reduced testcase, which in my mind should lay things out as is
drawn up in the comments of the code. However, everything is placed at
the 0,0 coordinate (top-left corner of the frame). I think I'm still
stuck in the Tk "Pack" mode of thinking, expecting the wxBoxSizer to do
stuff that it's not set up to do.

I'm sure that this is a pretty simple conceptual thing that I'm just not
getting, so I'll be very grateful to the person who can explain to me what
I'm doing wrong.

--
Michael Gilfix
mgilfix@eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html

Hi Wade,

Unless I have misunderstood what you are trying to do, you actually
only need two sizers. Try the following code. Then try uncommenting
the code under MyFrame.__init__ to see how to initialize it to a
minimal size. Also try commenting and uncommenting various lines to
see what they do.

#!/usr/bin/env python
from wxPython.wx import *

class MyPanel(wxPanel):
    def __init__(self, parent):
        # create panel
        wxPanel.__init__(self, parent, id=-1)
        # create the controls
        text1 = wxStaticText(self, -1, "Choose your category")
        choice1 = wxChoice(self, 40, choices = )
        choice1.Append("Any Category","Any")
        choice1.Append("Other Category","Other")
        choice1.SetSelection(0)
        list1 = wxListBox(self, 60, (-1,-1), (-1,-1), ,
                          wxLB_SINGLE)
        list1.Append("Test Data","Item 1")
        list1.Append("Test Data 2","Item 2")

        # create the sizers
        sizer1 = wxBoxSizer(wxVERTICAL)
        sizer2 = wxBoxSizer(wxHORIZONTAL)

        # add controls to sizers
        sizer2.Add(text1, 1, wxEXPAND)
        sizer2.Add(choice1, 1, wxEXPAND)
        sizer1.Add(sizer2, 0, wxEXPAND|wxALL, border=10)
        sizer1.Add(list1, 1, wxEXPAND|wxALL, border=10)

        # enable sizers
        self.SetSizer(sizer1)
        self.SetAutoLayout(1)
        sizer1.Fit(self)
        sizer1.SetSizeHints(self)

class MyFrame(wxFrame):
    def __init__(self):
        wxFrame.__init__(self, None, -1, 'Sizer Demo')
        panel1 = MyPanel(self)
## sizer = wxBoxSizer()
## sizer.Add(panel1, 1, wxEXPAND)
## self.SetSizer(sizer)
## self.SetAutoLayout(1)
## sizer.Fit(self)
## sizer.SetSizeHints(self)

class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame()
        frame.Show(1)
        return 1

app = MyApp(0)
app.MainLoop()

···

--- "H. Wade Minter" <minter@lunenburg.org> wrote:

One of the things that's giving me the most grief are the box
sizers. I'm attaching a reduced testcase, which in my mind
should lay things out as is drawn up in the comments of the
code. However, everything is placed at the 0,0 coordinate
(top-left corner of the frame).

=====
Donnal Walter
Arkansas Children's Hospital

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus � Powerful. Affordable. Sign up now.