scrollToTop 在带有 RadioBox 的 ScrollPanel 中无法正常工作
scrollToTop not working correctly in ScrollPanel with RadioBox
我在使用包含单选框的 wxPython
滚动面板时遇到问题。当从另一个面板更改焦点时尝试 select 单选框中的项目时,滚动条会跳到顶部。然后您需要滚动并再次单击。重现问题的最小示例:
#!/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()
当我点击另一个单选面板并返回滚动面板时,如此处,
它跳到顶部,而不是 select 单选按钮。我已经检查过,EVT_COMBOBOX
似乎不是由第一次点击触发的。我也尝试添加 scrollToTop=False
但没有帮助。我正在使用 Python 2.7.3 和 wxPython 版本 3.0.2.0.
OnChildFocus(self, evt)
如果获得焦点的 child window 不完全可见,此处理程序将尝试滚动到足以看到它。
参数: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
声明了两次。
我在使用包含单选框的 wxPython
滚动面板时遇到问题。当从另一个面板更改焦点时尝试 select 单选框中的项目时,滚动条会跳到顶部。然后您需要滚动并再次单击。重现问题的最小示例:
#!/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()
当我点击另一个单选面板并返回滚动面板时,如此处,
它跳到顶部,而不是 select 单选按钮。我已经检查过,EVT_COMBOBOX
似乎不是由第一次点击触发的。我也尝试添加 scrollToTop=False
但没有帮助。我正在使用 Python 2.7.3 和 wxPython 版本 3.0.2.0.
OnChildFocus(self, evt)
如果获得焦点的 child window 不完全可见,此处理程序将尝试滚动到足以看到它。
参数: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
声明了两次。