ScrolledPanel scrolling for no reason(?)

Robin Dunn <robin <at> alldunn.com> writes:

The scrolledpanel is catching the EVT_CHILD_FOCUS event and in the
handler it scrolls itself to try and make the whole child visible.
Since the only child widget you have is a wx.Panel, and since it is
filling the whole scrolledpanel, then I imagine that is confusing the
child focus handler in some way.

BTW, there is probably no need for the extra panel. ScrolledPanel is a
panel so it can contain the other widgets itself.

(Sorry for starting another thread. I had issues trying to figure out
this mailing list thing...)

Thanks for the response.

I got things working by mapping the EVT_CHILD_FOCUS to a function that does
nothing. But it looks to me like I'm working around a bug.
Here's an example that better illustrates what I'm doing:

import wx
import wx.lib.scrolledpanel as scrolled

app = wx.App()

frame = wx.Frame( None, title="Scroll Panel Issue", size=(400,400) )

main_panel = wx.Panel( frame )

control_panel = wx.Panel( main_panel, style= wx.SIMPLE_BORDER )
control_panel.sizer = wx.BoxSizer( wx.VERTICAL )
control_panel.SetSizer( control_panel.sizer )
control_panel.sizer.Add( wx.Button( control_panel, wx.ID_ANY, "New" ) )
control_panel.sizer.Add( wx.Button( control_panel, wx.ID_ANY, "Save" ) )
control_panel.sizer.Add( wx.TextCtrl( control_panel, wx.ID_ANY, "Another widget"
) )

canvas = scrolled.ScrolledPanel( main_panel, wx.ID_ANY )
canvas.SetVirtualSizeWH( 1000, 1000 )
canvas.SetScrollRate(20,20)
wx.Button( canvas, wx.ID_ANY, "Canvas Button. This should scroll around.",
(20,20) )

#Begin work-around

def do_nothing(e):
pass

canvas.Bind( wx.EVT_CHILD_FOCUS, do_nothing )

# End work-around

main_panel.sizer = wx.BoxSizer( wx.HORIZONTAL )
main_panel.SetSizer( main_panel.sizer )
main_panel.sizer.Add( control_panel, flag=wx.EXPAND )
main_panel.sizer.Add( canvas, proportion=1, flag=wx.EXPAND )

frame.Show()

app.MainLoop()