wxpython:用另一个wx.panel覆盖wx.panel,但是新面板的大小无法正确调整 [英] wxpython: overlay wx.panel with another wx.panel but new panel doesn't resize right
问题描述
我有一个带有带2个面板的分离器的框架.这些面板中的一个(右一个= choicePanel)具有一个按钮,该按钮应在choicepanel的同一位置打开一个新面板(infopanel).我使用了这种技术( wxPython :将wx.Panel覆盖在现有wx.Panel上的好方法).
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.
代码:
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()
切换这些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")
推荐答案
我已经用另一种方法解决了这个问题.我仍然有self.ChoosePanel在拆分器中.但是,我没有打开新面板,而是在self.choosepanel中也添加了第二个面板(self.cellinfo),但已隐藏.
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.
因此,在调用self.choosepanel时,将显示choisepanel并隐藏self.cellinfo面板,单击按钮时,将隐藏选择面板并显示self.cellinfo面板.
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.
这篇关于wxpython:用另一个wx.panel覆盖wx.panel,但是新面板的大小无法正确调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!