[wxPython] wxScrolledWindow bug or feature?

The attached program demonstrates a problem
I am having with wxPython 2.2.0 running
on Windows98 (and Python 1.5.2).

Start the program.
Click the 'Add button' twice. The scrollbar
should appear.
Dragg the scrollbar to the bottom.
Click the 'Add button' again.
After that click I cannot scroll back to
the top of the page.

Am I doing something wrong? Or is there
a problem with the wxScrolledWindow
implementation?

Thanks!
        Ralf

from wxPython.wx import *

class MyApp(wxApp):

  def OnInit(self):
    main_frame = wxFrame(NULL, -1, 'Main Frame', size = wxSize(200, 200))

    self.scr_win = wxScrolledWindow(main_frame, -1, style = wxSUNKEN_BORDER)

    self.panel_win = wxPanel(self.scr_win, -1, style = wxSIMPLE_BORDER)
    self.panel_szr = wxBoxSizer(wxVERTICAL)
    self.panel_win.SetAutoLayout(true)
    self.panel_win.SetSizer(self.panel_szr)

    btn = wxButton(self.panel_win, -1, 'Dummy Button')
    self.panel_szr.Add(btn, 0, wxALL, 10)

    btn = wxButton(self.panel_win, -1, 'Add Button')
    self.panel_szr.Add(btn, 0, wxALL, 10)
    self.n = 0
    EVT_BUTTON(self.panel_win, btn.GetId(), self.OnAddButton)

    self.panel_szr.Fit(self.panel_win)
    self.SetScrollbars()

    main_frame.Show(true)
    self.SetTopWindow(main_frame)
    return true

  def SetScrollbars(self):
    (W, H) = self.panel_win.GetSizeTuple()
    self.scr_win.SetScrollbars(20, 20, (W + 19) / 20, (H + 19) / 20)

  def OnAddButton(self, event):
    self.n = self.n + 1
    btn = wxButton(self.panel_win, -1, 'Additional button %d' % (self.n,))
    self.panel_szr.Add(btn, 0, wxALL, 10)
    self.panel_szr.Fit(self.panel_win)
    self.SetScrollbars()

app = MyApp(0)
app.MainLoop()

--== Sent via Deja.com http://www.deja.com/ ==--
Before you buy.

Hi Ralf,

Ralf Grosse-Kunstleve wrote:

The attached program demonstrates a problem
I am having with wxPython 2.2.0 running
on Windows98 (and Python 1.5.2).

Start the program.
Click the 'Add button' twice. The scrollbar
should appear.
Dragg the scrollbar to the bottom.
Click the 'Add button' again.
After that click I cannot scroll back to
the top of the page.

Am I doing something wrong? Or is there
a problem with the wxScrolledWindow
implementation?

Thanks!
        Ralf

from wxPython.wx import *

class MyApp(wxApp):

  def OnInit(self):
    main_frame = wxFrame(NULL, -1, 'Main Frame', size = wxSize(200, 200))

    self.scr_win = wxScrolledWindow(main_frame, -1, style = wxSUNKEN_BORDER)

    self.panel_win = wxPanel(self.scr_win, -1, style = wxSIMPLE_BORDER)
    self.panel_szr = wxBoxSizer(wxVERTICAL)
    self.panel_win.SetAutoLayout(true)
    self.panel_win.SetSizer(self.panel_szr)

    btn = wxButton(self.panel_win, -1, 'Dummy Button')
    self.panel_szr.Add(btn, 0, wxALL, 10)

    btn = wxButton(self.panel_win, -1, 'Add Button')
    self.panel_szr.Add(btn, 0, wxALL, 10)
    self.n = 0
    EVT_BUTTON(self.panel_win, btn.GetId(), self.OnAddButton)

    self.panel_szr.Fit(self.panel_win)
    self.SetScrollbars()

    main_frame.Show(true)
    self.SetTopWindow(main_frame)
    return true

  def SetScrollbars(self):
    (W, H) = self.panel_win.GetSizeTuple()

change this:

    self.scr_win.SetScrollbars(20, 20, (W + 19) / 20, (H + 19) / 20)

to:
    (WP, HP) = self.scr_win.GetViewStart()
    self.scr_win.SetScrollbars(20, 20, (W + 19) / 20, (H + 19) / 20, WP,
HP)

I ran across this myself before, the default values fot the new scroll
offsets are 0, but it has actually been scrolled.

···

  def OnAddButton(self, event):
    self.n = self.n + 1
    btn = wxButton(self.panel_win, -1, 'Additional button %d' % (self.n,))
    self.panel_szr.Add(btn, 0, wxALL, 10)
    self.panel_szr.Fit(self.panel_win)
    self.SetScrollbars()

app = MyApp(0)
app.MainLoop()

--== Sent via Deja.com http://www.deja.com/ ==--
Before you buy.

_______________________________________________
wxPython-users mailing list wxPython-users@wxwindows.org
http://wxwindows.org/mailman/listinfo/wxpython-users

--
Riaan >>> a='a=%s;a%%`a`';a%`a`
___________________________________________________
Boa Constructor - RAD GUI building IDE for wxPython
     http://boa-constructor.sourceforge.net