wxPython layout problem

Discussion in 'Python' started by py, Jan 23, 2006.

  1. py

    py Guest

    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
     
    py, Jan 23, 2006
    #1
    1. Advertising

  2. py

    Tim Roberts Guest

    "py" <> wrote:
    >
    >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.
    --
    - Tim Roberts,
    Providenza & Boekelheide, Inc.
     
    Tim Roberts, Jan 24, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick Spiewak
    Replies:
    3
    Views:
    3,179
    Rick Spiewak
    Aug 26, 2003
  2. RobertH
    Replies:
    1
    Views:
    738
    Steve C. Orr [MVP, MCSD]
    Nov 4, 2003
  3. NWx
    Replies:
    4
    Views:
    2,984
    Kevin Spencer
    Feb 19, 2004
  4. Replies:
    1
    Views:
    604
    John Timney \(MVP\)
    Jun 19, 2006
  5. Jolley
    Replies:
    1
    Views:
    1,210
    Jolley
    Nov 23, 2006
Loading...

Share This Page