简体   繁体   中英

Wxpython size of nested panel and it's behavior when resizing whole application

My problem is about behavior of "panelThree" in code. I coloured it and that showed me that space in my panel is really tiny. I don't really know where i made mistake. The second thing about panelThree behavior is that when you maximalize whole app and back to default size, it's getting wierd, maybe because it don't have background, but it's connect with previous.

Here's the code:

import wx
import wx.aui
import wx.grid as gridlib

########################################################################
class ColorPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)
        self.SetBackgroundColour((193,255,193))




class MenuPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)

        notebook = wx.aui.AuiNotebook(self)
        page = wx.SplitterWindow(notebook)
        menuSplitter = wx.SplitterWindow(page)

        Color = ColorPanel(page)
        Color.SetBackgroundColour((193,255,193))

        notebook.AddPage(page, "Colors Menu")
        #notebook.AddPage(page, "Colors Menu2")
        #notebook.AddPage(page, "Colors Menu2")
        #notebook.AddPage(page, "Colors Menu2")
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(notebook, 1, wx.EXPAND)
        self.SetSizer(sizer)


########################################################################
class GridPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)
        self.grid = gridlib.Grid(self, style=wx.BORDER_SUNKEN)
        self.grid.CreateGrid(25,25)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.grid, 1, wx.EXPAND)
        self.SetSizer(sizer)
    def Create (self,Rows,Cols):
        self.grid.CreateGrid(Rows,Cols)
    #def Fill (self,ValuesList)

    #def Colour (self, ColorList) #Color list format [(Color,Value1,Value2=None)]
########################################################################
class MainPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)

        notebook = wx.aui.AuiNotebook(self)

        page = wx.SplitterWindow(notebook)
        notebook.AddPage(page, "Splitter")
        hSplitter = wx.SplitterWindow(page)

        panelOne = GridPanel(hSplitter)
        panelTwo = GridPanel(hSplitter)
        panelThree = MenuPanel(page)
        hSplitter.SplitHorizontally(panelOne, panelTwo)
        page.SplitVertically(hSplitter, panelThree)
        hSplitter.SetSashGravity(0.5)
        page.SetSashGravity(0.70)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(notebook, 1, wx.EXPAND)
        self.SetSizer(sizer)


########################################################################
class MainFrame(wx.Frame):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, title="Nested Splitters",
                          size=(800,600))
        panel = MainPanel(self)

        menubar = wx.MenuBar()

        fileMenu = wx.Menu()
        fileMenu.Append(wx.ID_NEW, '&New\tCtrl+N')
        fileMenu.Append(wx.ID_OPEN, '&Open\tCtrl+O')
        fileMenu.Append(wx.ID_SAVE, '&Save\tCtrl+S')
        fileMenu.AppendSeparator()

        menubar.Append(fileMenu, '&File')
        self.SetMenuBar(menubar)
        self.Show()

#----------------------------------------------------------------------
if __name__ == "__main__":
    app = wx.App(False)
    frame = MainFrame()
    app.MainLoop()

I believe that your issue is that you haven't put anything in it.
Try changing class MenuPanel to this:

class MenuPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)

        notebook = wx.Notebook(self)
        page = wx.SplitterWindow(notebook)
        text_ctrl = wx.TextCtrl(notebook, style=wx.TE_MULTILINE)
        text_ctrl.SetValue("A whole bunch of text\nand then some more\nand finally some more")
        menuSplitter = wx.SplitterWindow(page)

        Color = ColorPanel(page)
        Color.SetBackgroundColour((193,255,193))

        notebook.AddPage(text_ctrl, "Colors Menu")
        #notebook.AddPage(page, "Colors Menu2")
        #notebook.AddPage(page, "Colors Menu2")
        #notebook.AddPage(page, "Colors Menu2")
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(notebook, 1, wx.EXPAND)
        self.SetSizer(sizer)

This adds in text_ctrl which has some data and see the difference!
If you are going to use AuiNoteBook you should probably read or re-read this http://www.wiki.wxpython.org/AuiNotebook%20%28AGW%29
Whilst wx.Aui labels itself as cutting edge, there can be issues, as it will not have been as extensively tested as the more mundane standard version, in this case wx.NoteBook.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM