Hi,
I have an annoying problem that is quite hard to reproduce - a scrolled
pane "jumps" to a different scroll position in certain cases.
The code below demonstrates the problem - I am sorry it is not shorter,
but I cannot reproduce what I am seeing in my app with anything simpler.
If you run the code (I am using Python 2.5.2, wx 2.8.7.1 on Linux) you
should see a frame with two columns of unlabelled buttons. The buttons
work something like nested CollapsiblePanes. Unfortunately, however, the
scroll position "jumps" when you click on a button.
You can stop this jumping by expanding the frame vertically (ie make the
main window smaller by using the cursor to drag a corner or edge) so that
more than 10 rows are visible (ie so that an entire "outer" selection can
fit in the screen) - there appears to be no jumping when an entire outer
section is visible.
You may need to play a little to see the problem - it only occurs the
first time a button is used (subsequent clicks on the same button do not
cause the scroll to jump).
Is there a problem with my code? Can anyone explain what is happening?
Do I need to be setting some sizes somewhere?
Thanks in advance for anyone who takes the time to run this,
Andrew
import wx
from wx.lib.buttons import GenToggleButton
from wx.lib.scrolledpanel import ScrolledPanel
class TestApp(wx.App):
def OnInit(self):
frame = wx.Frame(None, -1)
self.scroll = ScrolledPanel(frame)
scrollsizer = wx.BoxSizer(wx.VERTICAL)
for i in range(10):
outer = wx.BoxSizer(wx.HORIZONTAL)
button = GenToggleButton(self.scroll, size=(10,10))
outer.Add(button)
outercontents = wx.BoxSizer(wx.VERTICAL)
a = wx.StaticText(self.scroll, label='a')
outercontents.Add(a)
p = wx.Panel(self.scroll)
psizer = wx.BoxSizer(wx.VERTICAL)
for j in range(10):
inner = wx.BoxSizer(wx.HORIZONTAL)
button2 = GenToggleButton(p, size=(10,10))
inner.Add(button2)
innercontents = wx.BoxSizer(wx.VERTICAL)
a2 = wx.StaticText(p, label='a2')
innercontents.Add(a2)
b = wx.StaticText(p, label='b')
innercontents.Add(b)
a2.Show(False)
p.Bind(wx.EVT_BUTTON,
lambda event, x=button2, a=a2, b=b: self.handler(x,
a, b),
button2)
inner.Add(innercontents)
psizer.Add(inner)
p.SetSizer(psizer)
outercontents.Add(p)
self.scroll.Bind(wx.EVT_BUTTON,
lambda event, x=button, a=a, b=p: self.handler(x,
a, b),
button)
a.Show(False)
outer.Add(outercontents)
scrollsizer.Add(outer)
self.scroll.SetSizer(scrollsizer)
self.scroll.Layout()
self.scroll.SetupScrolling()
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.scroll, proportion=1, flag=wx.EXPAND|wx.ALL)
frame.SetSizer(sizer)
frame.SetSize((100, 100))
frame.Layout()
frame.Show(True)
self.SetTopWindow(frame)
return True
def handler(self, button, a, b):
a.Show(button.GetToggle())
b.Show(not button.GetToggle())
self.scroll.Layout()
if __name__ == '__main__':
app = TestApp(0)
app.MainLoop()