我遇到了wxPython
滚动面板的问题,其中包含一个radiobox。当从另一个面板更改焦点时,当尝试从radiobox中选择一个项目时,滚动条会跳到顶部。然后,您需要滚动并再次单击。一个重现问题的最小例子:
#!/bin/env python
import wx
import wx.lib.scrolledpanel as SP
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, - 1, "Frame", size=(300, 300))
self.scrolledPanel = ScrollPanel(self, size=(-1, 200))
self.panel = PlotTypePanel(self)
hbox = wx.BoxSizer(wx.VERTICAL)
hbox.Add(self.scrolledPanel, 0, wx.EXPAND | wx.ALL, 0)
hbox.Add(self.panel, 1, wx.EXPAND | wx.ALL, 0)
self.SetSizer(hbox)
class PlotTypePanel(wx.Panel):
def __init__(self, parent, **kwargs):
wx.Panel.__init__(self, parent,**kwargs)
self.anotherradiobox = wx.RadioBox(self,label='other',
style=wx.RA_SPECIFY_COLS,
choices=["some", "other", "box"])
class ScrollPanel(SP.ScrolledPanel):
def __init__(self, parent, **kwargs):
SP.ScrolledPanel.__init__(self, parent, -1, **kwargs)
self.parent = parent
self.SetupScrolling(scroll_x=False, scroll_y=True, scrollToTop=False)
choices = [l for l in "abcdefghijklmnopqrstuv"]
self.fieldradiobox = wx.RadioBox(self,label='letters',
style=wx.RA_SPECIFY_ROWS,
choices=choices)
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(self.fieldradiobox, 0, wx.EXPAND|wx.ALL, 10)
self.SetSizer(vbox)
self.SetupScrolling(scroll_x=False, scrollToTop=False)
if __name__ == '__main__':
app = wx.App()
frame = MyFrame()
frame.Show(True)
app.MainLoop()
当我点击其他电台面板并返回滚动面板时,如此处
它跳到顶部并且不选择单选按钮。我已经检查过,似乎第一次点击没有触发EVT_COMBOBOX
。我也尝试添加scrollToTop=False
但没有帮助。我正在使用Python 2.7.3和wxPython版本3.0.2.0。
答案 0 :(得分:1)
OnChildFocus(self,evt)
如果获得焦点的子窗口不完全可见,则此处理程序将尝试滚动足以查看它。
参数:evt - 要处理的ChildFocusEvent事件。
显然它适用于这种情况,至少在Linux上是
#!/bin/env python
import wx
import wx.lib.scrolledpanel as SP
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, - 1, "Frame", size=(300, 300))
self.scrolledPanel = ScrollPanel(self, size=(-1, 200))
self.panel = PlotTypePanel(self)
hbox = wx.BoxSizer(wx.VERTICAL)
hbox.Add(self.scrolledPanel, 0, wx.EXPAND | wx.ALL, 0)
hbox.Add(self.panel, 1, wx.EXPAND | wx.ALL, 0)
self.SetSizer(hbox)
class PlotTypePanel(wx.Panel):
def __init__(self, parent, **kwargs):
wx.Panel.__init__(self, parent,**kwargs)
self.anotherradiobox = wx.RadioBox(self,label='other',
style=wx.RA_SPECIFY_COLS,
choices=["some", "other", "box"])
class ScrollPanel(SP.ScrolledPanel):
def __init__(self, parent, **kwargs):
SP.ScrolledPanel.__init__(self, parent, -1, **kwargs)
self.parent = parent
self.SetupScrolling(scroll_x=False, scroll_y=True, scrollToTop=False)
choices = [l for l in "abcdefghijklmnopqrstuv"]
self.fieldradiobox = wx.RadioBox(self,label='letters',
style=wx.RA_SPECIFY_ROWS,
choices=choices)
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(self.fieldradiobox, 0, wx.EXPAND|wx.ALL, 10)
self.SetSizer(vbox)
self.Bind(wx.EVT_CHILD_FOCUS, self.on_focus)
self.SetupScrolling(scroll_x=False, scrollToTop=False)
def on_focus(self,event):
pass
if __name__ == '__main__':
app = wx.App()
frame = MyFrame()
frame.Show(True)
app.MainLoop()
注意:这不是一个问题,但你已经宣布了两次self.SetupScrolling
。