Hi,
I am new to wxPython, and I have difficulties to understand how Sizer/Layout works.
When all controls in the main frame are set in the __init__ method, all controls
are laid out in a method __do_layout(self) (as in wxGlade for example) where sizers arrange perfectly all what is needed.
But after that (at run-time) if I want to dynamically add a new control, the behaviour is (for me) totally un-understable.
How to repaint the main frame?
Here is am example where I've got a button on the Left and a Button on the right at the beginning. By clicking on the left button,
I would like to create a new button on the right below the one already there (all packed in a MultiSplitterWindow), and this as
many time as I want.
Actually the new buttons do not appear in my frame. I have to resize the frame. What I am doing wrong ?
I'm looking for corrections/advices; it would be great if a brave soul also could explain to me (and others for sure) the "philosophy" of the whole.
Many Thanks in advance
xm
for wxPython 2.6.3 with MultiSplitter
import wx
from wx.lib.splitter import MultiSplitterWindow
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.window_1 = wx.SplitterWindow(self, -1, style=wx.SP_3D|wx.SP_BORDER)
self.window_1_pane_1 = wx.Panel(self.window_1, -1)
self.button_1 = wx.Button(self.window_1_pane_1, -1, "Click to Split")
#self.window_1_pane_2 = wx.Panel(self.window_1, -1)
self.window_1_pane_2 = wx.ScrolledWindow(self.window_1, -1)
splitter = MultiSplitterWindow(self.window_1_pane_2, style=wx.SP_LIVE_UPDATE)
self.splitter = splitter
self.splitter.SetOrientation(wx.VERTICAL) # horizontal sashes
self.splitter.SetAutoLayout(1) # horizontal sashes
# a panel into the splitter
self.pane = wx.Panel(self.splitter, -1)
self.button = wx.Button(self.pane, -1, " Split me", wx.DefaultPosition, wx.DefaultSize)
# here
self.splitter.AppendWindow(self.pane, 50)
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_BUTTON, self.OnSplit, self.button_1)
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("frame_1")
self.SetSize((400, 300))
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.button, 1, wx.EXPAND)
self.pane.SetAutoLayout(True)
self.pane.SetSizer(sizer)
sizer_3 = wx.BoxSizer(wx.VERTICAL)
sizer_3.Add(self.splitter, 1, wx.EXPAND)
#self.window_1_pane_2.SetAutoLayout(True)
self.window_1_pane_2.SetSizer(sizer_3)
sizer_2 = wx.BoxSizer(wx.VERTICAL)
sizer_2.Add(self.button_1, 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
self.window_1_pane_1.SetAutoLayout(True)
self.window_1_pane_1.SetSizer(sizer_2)
sizer_2.Fit(self.window_1_pane_1)
sizer_2.SetSizeHints(self.window_1_pane_1)
self.window_1.SplitVertically(self.window_1_pane_1, self.window_1_pane_2)
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_1.Add(self.window_1, 1, wx.EXPAND, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
self.Layout()
# end wxGlade
def OnSplit(self, event):
pane = wx.Panel(self.splitter, -1)
button = wx.Button(pane, -1, " Split me", wx.DefaultPosition, wx.DefaultSize)
···
_______________________________________________________________
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192