wxpython: overlay wx.panel with another wx.panel b

2019-09-11 18:40发布

问题:

I've a frame with a splitter with 2 panels. one of these panels (right one = choosePanel) has a button which should open a new panel (infopanel) on the same place of the the choosepanel. I used this technique (wxPython: Good way to overlay a wx.Panel on an existing wx.Panel).

This part works. But the infopanel doesn't resize right. When I add this panelhardcoded in the place of choosepanel, then it works. But when I use the overlay technique something happens.

Code:

class Main(wx.Frame):

def __init__(self, parent=None, id=-1, notify_channel="browser_view",**kwargs):
    wx.Frame.__init__(self, parent, id, config.programname)
    self.parent = parent
    self.notify_channel = notify_channel
    pub.subscribe(self.on_message, notify_channel)

    self.backgroundpanel = wx.Panel(self, wx.ID_ANY)
    self.splitter = wx.SplitterWindow(self.backgroundpanel, wx.ID_ANY, style=wx.SP_LIVE_UPDATE | wx.SP_BORDER)# style=wwx.SP_LIVE_UPDATE : Don't draw XOR line but resize the child windows immediately.
    self.filter = filter_view.Main(self.splitter, wx.ID_ANY, notify_channel=self.notify_channel)
    self.menubar = menubar_view.Main(self, wx.ID_ANY, notify_channel=self.notify_channel)
    self.statusbar = self.CreateStatusBar()
    self.ChoosePanel = choosePanel_view.Main(self.splitter, wx.ID_ANY)
    # self.ChoosePanel = cellinfo_view.Main(self.splitter, wx.ID_ANY, notify_channel="cellinfo_view")

    self._do_layout()
    self._do_bindings()

    self.Maximize()
    self.Show()

def _do_layout(self):
    self.backgroundsizer = wx.BoxSizer()
    self.sizer = wx.BoxSizer(wx.HORIZONTAL)
    self.backgroundsizer.Add(self.backgroundpanel, 1, wx.EXPAND)
    self.SetMenuBar(self.menubar)
    self.sizer.Add(self.splitter, 1, wx.EXPAND)
    self.backgroundpanel.SetSizer(self.sizer)
    self.sizer.Fit(self.backgroundpanel)
    self.SetSizer(self.backgroundsizer)
    self.backgroundsizer.Fit(self)
    self.splitter.SplitVertically(self.filter, self.ChoosePanel, 500)
    self.splitter.SetMinimumPaneSize(50)

When I click on the button in the choosepanel, there is a pubsub message back to this to this file:

def on_cellinfo_panel(self,message):
    # print self.ChoosePanel.GetPosition()
    self.ChoosePanel.Hide()
    self.cellinfo = cellinfo_view.Main(self.splitter, wx.ID_ANY, notify_channel="cellinfo_view", style=wx.EXPAND)
    self.cellinfo.SetPosition((504, 0))
    self.cellinfo.Layout()

switch these 2:

    self.ChoosePanel = choosePanel_view.Main(self.splitter, wx.ID_ANY)
    # self.ChoosePanel = cellinfo_view.Main(self.splitter, wx.ID_ANY, notify_channel="cellinfo_view")

回答1:

I've solved this problem with another approach. I still have the self.ChoosePanel in the splitter. But instead of opening a new panel, I just added the second panel (self.cellinfo) also in the self.choosepanel, but hidden.

So when calling self.choosepanel, the choisepanel is showed and the self.cellinfo panel is hidden, and when clicking the button the choice panel is hidden and the self.cellinfo panel is showed.

I added a picture to help understanding my solution.