wxPython layout problem

P

py

I have the following code:
Code:
class MainFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title,
style=wx.DEFAULT_FRAME_STYLE |wx.NO_FULL_REPAINT_ON_RESIZE)
        # build top area
        topSizer = self.buildTopPanel()
        # build input area
        inputSizer = self.buildInputPanel()

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(topSizer, 1, wx.EXPAND | wx.ALL, 5)
        mainSizer.Add(inputSizer, 1, wx.EXPAND | wx.ALL, 5)

        p = wx.Panel(self, wx.ID_ANY)
        p.SetSizer(mainSizer)

        s = wx.BoxSizer(wx.VERTICAL)
        s.Add(p, 1, wx.EXPAND)

        self.SetAutoLayout(True)
        self.SetSizer(s)
        self.Layout()

    def buildTopPanel(self):
        p = wx.Panel(self, wx.ID_ANY)
        self.text = wx.TextCtrl(p, wx.ID_ANY, style=wx.TE_MULTILINE |
wx.SUNKEN_BORDER)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.text, 1, wx.EXPAND)
        return sizer

    def buildInputPanel(self):
        # the area to enter text
        self.text2 = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_MULTILINE
| wx.SUNKEN_BORDER)

        # panel to add button to
        p = wx.Panel(self, wx.ID_ANY)
        self.buttonClick = wx.Button(p, wx.ID_ANY, "Click")
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.Add(self.buttonClick, 0, wx.ALIGN_CENTER)
        p.SetSizer(hsizer)

        # add the text control and button panel
        box = wx.BoxSizer(wx.HORIZONTAL)
        box.Add(self.text2, 1, wx.EXPAND)
        box.Add(p, 0, wx.EXPAND)
        return box

if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MainFrame(None, wx.ID_ANY, "Test")
    frame.Show()
    app.MainLoop()

.....there are two problems.
1) i want the sizer (that is returned from buildTopPanel()) to fill the
screen wide/tall. now the text control in it is very small in the
upper-left corner.

2) the scroll bars and borders on the text controls dont appear until i
mouse over them, any ideas?

thanks
 
T

Tim Roberts

py said:
I have the following code:
...
....there are two problems.
1) i want the sizer (that is returned from buildTopPanel()) to fill the
screen wide/tall. now the text control in it is very small in the
upper-left corner.

2) the scroll bars and borders on the text controls dont appear until i
mouse over them, any ideas?

The panel you create in buildTopPanel has not been added to any sizer. So,
you have the odd condition that the self.text control is controlled by a
sizer, but its parent panel is not. The layout is confused.

You need to build this up bit by bit. The frame gets a panel. The panel
is controlled by a sizer. The panel will contain other panels, added to
the parent panel's sizer. The inner panels may need their own sizers. The
controls owned by the inner panels need to be added to the inner sizers.

The borders don't appear because parts of the panels are overlapping them
in strange ways.

Several folks have suggested that you create the controls from the outside
in, making sure that the control ownership is correct, and then as a
separate step, add those controls to sizers from the inside out. That
works for me, but some kind of structure is needed to make sure that
ownership and sizership are handled completely.

You might try posting on the wxPython mailing list,
http://www.wxpython.org/maillist.php.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,696
Latest member
BarbraOLog

Latest Threads

Top