4

I'm trying to build something like below:

enter image description here

It's a notebook with 2 panels, split horizontally. The panel on top is also split into 2, each split containing a wx.grid object.

I have tried the code below, but 2 grids on top panel do not show up:

class NoteBook(wx.Notebook):

    def __init__(self, parent, pages):

        wx.Notebook.__init__(self, parent, id=wx.ID_ANY, style= wx.BK_DEFAULT)
        self.parent = parent
        page = "TEST"

        self.splitter_window = wx.SplitterWindow(self)

        self.AddPage(self.splitter_window, page)
        title_name = page[1:]

        grid_panel = wx.Panel(self.splitter_window, style=wx.BORDER_THEME)
        grid_splitter = wx.SplitterWindow(grid_panel)

        grid_panel_1 = wx.Panel(grid_splitter, style=wx.BORDER_THEME)
        grid1 = grid_maker.GridArea(grid_panel_1)
        grid1.CreateGrid(page) #create the grid 1
        grid1.addToGrid(page) #adding some data to grid 1
        binder = cxt_functions.GridFunctions(self, grid1) #bind some functions to grid1
        binder.BindCrewGridMenu()            

        grid_panel_2 = wx.Panel(grid_splitter, style=wx.BORDER_THEME)
        grid2 = grid_maker.CreateGrid(grid_panel_2) #create the grid 1
        grid2.addToGrid(page) #adding some data to grid 1


        grid_splitter.SplitVertically(grid_panel_1, grid_panel_2, 100)

        grid_sizer = wx.BoxSizer(wx.VERTICAL)
        grid_sizer.Add(grid1, 1, wx.EXPAND | wx.ALL, 7)
        grid_sizer.Add(grid2, 0, wx.EXPAND | wx.ALL, 7)

        grid_panel.SetSizer(grid_sizer)

        chart_panel = wx.Panel(self.splitter_window, style=wx.BORDER_THEME)
        line_chart = bar_line.CanvasPanel(chart_panel, title_name)
        line_chart.draw()


        self.splitter_window.SplitHorizontally(grid_panel, chart_panel, 500)

        p_sizer = wx.BoxSizer(wx.VERTICAL)
        p_sizer.Add(self, 1, wx.EXPAND | wx.ALL, 7)    
        self.parent.SetSizer(p_sizer)


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

What is wrong above?

1 Answer 1

2

I'm not sure what's going on with your code as it's not exactly runnable, so I put together my own version:

import wx
import wx.grid as gridlib

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

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


########################################################################
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,8)

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


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

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

        notebook = wx.Notebook(self)

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

        panelOne = GridPanel(hSplitter)
        panelTwo = GridPanel(hSplitter)
        hSplitter.SplitVertically(panelOne, panelTwo)
        hSplitter.SetSashGravity(0.5)

        panelThree = RegularPanel(page)
        page.SplitHorizontally(hSplitter, panelThree)
        page.SetSashGravity(0.5)

        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)
        self.Show()

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

This is based on one of my nested SplitterWindow tutorial. I hope that helps you figure out what's going on in your own code.

6
  • Thanks, but I want to place it on a notebook, which is on a Frame. How to adjust it?
    – alwbtc
    Dec 17, 2013 at 3:07
  • Well all you'd want to do is add a Notebook and make it the parent of the first splitter. I adjusted the code slightly. Dec 17, 2013 at 14:33
  • Ok, I got it worked. Mike, please show me how to synchronously scroll the 2 grids on top panel, I have tried everything but couldn't get it work. I'll be grateful. Best regards
    – alwbtc
    Dec 17, 2013 at 15:08
  • I'm not aware of an easy way to accomplish that. The closest I've found that's ready made is the answer to this question: stackoverflow.com/questions/15870426/… Dec 17, 2013 at 15:35
  • Would you use a "vertically splitted window" or "2 separate panels" for those 2 grids? which one is more convenient?
    – alwbtc
    Dec 17, 2013 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.