471,052 Members | 1,261 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,052 software developers and data experts.

wxPython layout problem

py
I have the following code:
Expand|Select|Wrap|Line Numbers
  1. class MainFrame(wx.Frame):
  2. def __init__(self, parent, id, title):
  3. wx.Frame.__init__(self, parent, wx.ID_ANY, title,
  4. style=wx.DEFAULT_FRAME_STYLE |wx.NO_FULL_REPAINT_ON_RESIZE)
  5. # build top area
  6. topSizer = self.buildTopPanel()
  7. # build input area
  8. inputSizer = self.buildInputPanel()
  9.  
  10. mainSizer = wx.BoxSizer(wx.VERTICAL)
  11. mainSizer.Add(topSizer, 1, wx.EXPAND | wx.ALL, 5)
  12. mainSizer.Add(inputSizer, 1, wx.EXPAND | wx.ALL, 5)
  13.  
  14. p = wx.Panel(self, wx.ID_ANY)
  15. p.SetSizer(mainSizer)
  16.  
  17. s = wx.BoxSizer(wx.VERTICAL)
  18. s.Add(p, 1, wx.EXPAND)
  19.  
  20. self.SetAutoLayout(True)
  21. self.SetSizer(s)
  22. self.Layout()
  23.  
  24. def buildTopPanel(self):
  25. p = wx.Panel(self, wx.ID_ANY)
  26. self.text = wx.TextCtrl(p, wx.ID_ANY, style=wx.TE_MULTILINE |
  27. wx.SUNKEN_BORDER)
  28. sizer = wx.BoxSizer(wx.HORIZONTAL)
  29. sizer.Add(self.text, 1, wx.EXPAND)
  30. return sizer
  31.  
  32. def buildInputPanel(self):
  33. # the area to enter text
  34. self.text2 = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_MULTILINE
  35. | wx.SUNKEN_BORDER)
  36.  
  37. # panel to add button to
  38. p = wx.Panel(self, wx.ID_ANY)
  39. self.buttonClick = wx.Button(p, wx.ID_ANY, "Click")
  40. hsizer = wx.BoxSizer(wx.HORIZONTAL)
  41. hsizer.Add(self.buttonClick, 0, wx.ALIGN_CENTER)
  42. p.SetSizer(hsizer)
  43.  
  44. # add the text control and button panel
  45. box = wx.BoxSizer(wx.HORIZONTAL)
  46. box.Add(self.text2, 1, wx.EXPAND)
  47. box.Add(p, 0, wx.EXPAND)
  48. return box
  49.  
  50. if __name__ == "__main__":
  51. app = wx.PySimpleApp()
  52. frame = MainFrame(None, wx.ID_ANY, "Test")
  53. frame.Show()
  54. app.MainLoop()
  55.  
.....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

Jan 23 '06 #1
1 1782
"py" <co*******@gmail.com> 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, ti**@probo.com
Providenza & Boekelheide, Inc.
Jan 24 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Grant Edwards | last post: by
22 posts views Thread by dcrespo | last post: by
3 posts views Thread by Young H. Rhiu | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.