I am trying to build this GUI tool in wxpython as part of my project. I have a basic frame that has a splitter window(wx.SplitterWindow object), split horizontally. When the application is first opened, it will show just the splitter window with some text. I also have a menu that houses various menu-items that are binded to the respective event-handlers. Now, when I click on a particular menu-item for the first time, I need a new wx.Notebook object to be created with a page that hosts the info related to that event-handler, on top of the already existing content in the frame (the wx.SplitterWindow object). Typically, I would want a new panel to be created on top of the old content, that will be the parent to the notebook object. Every subsequent click of a menu-item should create a new page in the notebook. May I know how this can be achieved?
Here are the necessary code snippets, that I have written, but ofc I have gone horribly wrong somewhere:
This code creates the initial splitter window composed of two panels:
self.splitter = wx.SplitterWindow(self, id = wx.ID_ANY) self.panel1 = wx.Panel(self.splitter, id = wx.ID_ANY) self.panel2 = wx.Panel(self.splitter, id = wx.ID_ANY) self.panel1.SetBackgroundColour(wx.LIGHT_GREY) self.splitter.SplitHorizontally(self.panel1, self.panel2)
Code for the first menu-item click event:
def displayNodes(self,event): if hasattr(self, "notebook") == False: #If the notebook object has not been already created #create notebook if it does not exitst already. This script should be present in every event handler self.panel = wx.Panel(self,wx.ID_ANY) self.notebook = NotebookDemo(self.panel) #creating vertical sizer for the notebook self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.notebook, 1, wx.ALL|wx.EXPAND, 5) self.panel.SetSizer(self.sizer) self.nodesname = "nodes" self.nodesinstance = wx.SingleInstanceChecker(self.nodesname) if self.nodesinstance.IsAnotherRunning(): self.notebook.ChangeSelection(self.nodesindex) else: #creating a tab self.nodesTab = TabPanel(self.notebook) self.notebook.AddPage(self.nodesTab, "List of all the nodes") self.nodes = wx.ListBox(self.nodesTab, 11, (10,40), (200,130), self.nodeslist, wx.LB_SINGLE) self.nodesindex = self.notebook.GetPageCount() - 1 self.notebook.SetSelection(self.nodesindex) #self.Bind(wx.EVT_CONTEXT_MENU, self.OnShowPopup)
PS: My knowledge of wxpython is limited, and I am still learning! Would be more than happy if the objective can be achieved in a much elegant way!