0

So I have three splitter windows that I am trying to use sizers for so that they act normal when getting resized and such. Here's the code I have right now. It is not working.

class SplitterFrame (wx.Frame):
def __init__(self):
 #Create a master window
 self.mainframe = wx.Frame.__init__(self,None,title = 'some frame')
 self.splitter = wx.SplitterWindow(self,-1, style = wx.SP_LIVE_UPDATE)
 self.splitter2 = wx.SplitterWindow(self.splitter,-1, style = wx.SP_LIVE_UPDATE)
 self.splitter.SetMinimumPaneSize(330)
 self.splitter2.SetMinimumPaneSize(160)
 self.panel1 = wx.Panel(self.splitter,-1)
 self.panel1.SetBackgroundColour(wx.WHITE)
 self.panel2 = wx.Panel(self.splitter2,-1)
 self.panel2.SetBackgroundColour(wx.WHITE)
 self.panel3 = wx.Panel(self.splitter2, -1)
 self.panel3.SetBackgroundColour(wx.WHITE)
 #Splitter window attributes
 self.splitter2.SplitVertically(self.panel2,self.panel3, 100)
 self.splitter.SplitVertically(self.panel1,self.splitter2, 200)
 self.splitter.SetSashGravity(0)
 self.splitter2.SetSashGravity(1)
 self.splitter.SetSashPosition(1,redraw = True)
 self.splitter2.SetSashPosition(10000,redraw = True)
 self.Centre()
 self.Layout()
 self.Maximize(True)
 self.Bind(wx.EVT_CLOSE,self.OnClose)
 #Set Sizers
 sizer = wx.BoxSizer(wx.VERTICAL)
 sizer.Add(self.splitter,1,wx.ALL|wx.EXPAND)
 sizer.Add(self.splitter2,1,wx.ALL|wx.EXPAND)
 self.SetSizer(sizer)

Can someone show me how to apply the right sizers to this? I'm not good at all with sizers so I just used the ones above as I found them here [wxPython Splitter windows and Panels .

asked Aug 3, 2015 at 1:38

1 Answer 1

4

You cannot add both splitters into the sizer, because they are not siblings in the hierarchy of the windows. So you have the splitter, then another splitter in one of the panels. Sizers won't help you, because sizers directly with the windows inside the sizer, but you have only one window in the sizer (self.splitter), another one (self.splitter2) is inside the self.splitter. So the sizing must happen within the splitters themselves. You will have to handle the Frame's OnSize event, and resize the inner splitters there.

Edit: Added the code.

class SplitterFrame (wx.Frame):
 def __init__(self):
 #Create a master window
 wx.Frame.__init__(self,None,title = 'some frame')
 self.splitter = wx.SplitterWindow(self,-1, style = wx.SP_LIVE_UPDATE)
 self.splitter2 = wx.SplitterWindow(self.splitter,-1, style = wx.SP_LIVE_UPDATE)
 self.splitter.SetMinimumPaneSize(20)
 self.splitter2.SetMinimumPaneSize(20)
 self.panel1 = wx.Panel(self.splitter,-1)
 self.panel1.SetBackgroundColour(wx.WHITE)
 self.panel2 = wx.Panel(self.splitter2,-1)
 self.panel2.SetBackgroundColour(wx.WHITE)
 self.panel3 = wx.Panel(self.splitter2, -1)
 self.panel3.SetBackgroundColour(wx.WHITE)
 #Splitter window attributes
 self.splitter2.SplitVertically(self.panel2,self.panel3, 100)
 self.splitter.SplitVertically(self.panel1,self.splitter2, 100)
 self.splitter.SetSashGravity(0)
 self.splitter2.SetSashGravity(1)
 self.Centre()
 self.Layout()
 self.Maximize(True)
 self.Bind(wx.EVT_SIZE, self.OnSize)
 sizer = wx.BoxSizer(wx.VERTICAL)
 sizer.Add(self.splitter,2,wx.ALL|wx.EXPAND)
 self.SetSizer(sizer)
 def OnSize(self, evt):
 evt.Skip()
 # here you will change the sash positions to your liking
 self.splitter.SetSashPosition(100,redraw = True)
 self.splitter2.SetSashPosition(200,redraw = True)
answered Aug 3, 2015 at 11:44
Sign up to request clarification or add additional context in comments.

3 Comments

Can you show me the code version of what you said there? I'm just not good at this sorry :(
Thanks for the answer. Sorry for accepting so late I didn't get a notification :(
I had a similar case where I didn't use evt.Skip() which happened to be the culprit, seems like it's crucial.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.