Domanda

I'm trying to embed splitter windows in set of panels, but when I run the following I see a flash, as if the top splitter window is overlaying the top panel of the second splitter window. I tried to keep track of the children of the frame and panels but can't figure out whos on top. Can anyone help me sort this out and explain why the layout changes and the top panel is apparantly masked by the 2nd panel added to the splitter? Thanks David

#!/usr/bin/env python2.6
# encoding: ISO-8859-1
"""
Basic Splitter Panel Skeleton.py
"""

import sys
reload(sys) 
sys.setdefaultencoding("utf-8")
import os
import time
import wx


def timenow():
    return time.time()

########################################################################

class VSplitterPanel(wx.Panel):
    """ Constructs a Vertical splitter window with left and right panels"""
    #----------------------------------------------------------------------
    def __init__(self, parent, color):
        """Constructor"""
        wx.Panel.__init__(self, parent)
        self.SetBackgroundColour(color)
        splitter = wx.SplitterWindow(self, style = wx.SP_3D| wx.SP_LIVE_UPDATE)
        leftPanel = wx.Panel(splitter)
        rightPanel = wx.Panel(splitter)
        leftPanel.SetBackgroundColour('SEA GREEN')
        rightPanel.SetBackgroundColour('STEEL BLUE')

        splitter.SplitVertically(leftPanel, rightPanel) 
        PanelSizer=wx.BoxSizer(wx.VERTICAL)
        PanelSizer.Add(splitter, 1, wx.EXPAND | wx.ALL)
        self.SetSizer(PanelSizer)
########################################################################

class HSplitterPanel(wx.Panel):
    """ Constructs a Horizontal splitter window with top and bottom panels"""
    #----------------------------------------------------------------------
    def __init__(self, parent, color):
        """Constructor"""
        wx.Panel.__init__(self, parent)
        self.SetBackgroundColour(color)
        splitter = wx.SplitterWindow(self, style = wx.SP_3D| wx.SP_LIVE_UPDATE)
        TopPanel = wx.Panel(splitter)
        BottomPanel = wx.Panel(splitter)
        TopPanel.SetBackgroundColour('YELLOW GREEN')
        BottomPanel.SetBackgroundColour('SLATE BLUE')


        splitter.SplitHorizontally(TopPanel, BottomPanel) 
        PanelSizer=wx.BoxSizer(wx.VERTICAL)
        PanelSizer.Add(splitter, 1, wx.EXPAND | wx.ALL)
        self.SetSizer(PanelSizer)
########################################################################

class MainFrame(wx.Frame):
    """Constructor"""
    #----------------------------------------------------------------------
    def __init__(self, parent, id):
        wx.Frame.__init__(self, None, title="Basic Splitter Panel Skeleton",size=(800,600))
        t0=timenow()
        self.sb=self.CreateStatusBar()
        ################################################################
        # Define mainsplitter as child of Frame and add H and VSplitterPanel as children
        mainsplitter = wx.SplitterWindow(self, style = wx.SP_3D| wx.SP_LIVE_UPDATE)
        #splitterpanel1 = HSplitterPanel(mainsplitter,'LIGHT BLUE') 
        splitterpanel1 = HSplitterPanel(mainsplitter,'LIGHT BLUE') 
        splitterpanel2 = VSplitterPanel(mainsplitter,'LIGHT BLUE') 
        #print self.GetChildren(),'\n'
        #print splitterpanel1.leftPanel.GetChildren()
        mainsplitter.SplitHorizontally(splitterpanel2, splitterpanel1)
        MainSizer = wx.BoxSizer(wx.VERTICAL)
        MainSizer.Add(mainsplitter, 1, wx.EXPAND | wx.ALL)
        self.SetSizer(MainSizer)
        #################################################################
        self.sb.SetStatusText('Initialized in  %6.4f secs'%(timenow()-t0))
        self.Refresh()
        self.Show()

#---------------------------------------------------------------------- 


if __name__ == '__main__':
    app = wx.App()
    MainFrame(None, -1)
    app.MainLoop()
È stato utile?

Soluzione

I see the following when I run it on Windows:

enter image description here

Which panel is messed up? Regardless, the easiest way to tell which widget is where is to use the Widget Inspection Tool. You can read about it here. It's easy to use and it can even make your sizers visible to help you figure out layout issues.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top