Mike thanks for your example. You don't happen to have made ScrollView.count
dynamic before? (ie. Change its value by resizing the panel?)
thanks
matt
···
-----Original Message-----
From: Mike C. Fletcher [mailto:mcfletch@rogers.com]
Sent: Thursday, January 17, 2002 8:30 PM
To: wxpython-users@lists.wxwindows.org; Robin Dunn
Subject: Re: [wxPython] optimizing layout of many widgets
Here's a simplified example (I only use a single control per editing
item, and I don't bother updating the data values after editing (since
you know how to do that), neither do I bother with catching tab on the
last and first editing controls to do forward/back tabbing, or even
pgup/pgdown or arrows). You'll note I use the wxScrollBar control, not
a scrolled panel.
Robin: There is inconsistent capitalisation in wxScrollBar versus
wxScrollBar::SetScrollbar, not sure to whom that should go as a bug
report, or if it's even a problem.
HTH,
Mike
from wxPython.wx import *
class ScrollView( wxPanel ):
currentTopView = 0
count = 20
def __init__( self, parent, data = () ):
wxPanel.__init__( self, parent, -1 )
self.data = data
outer = wxBoxSizer( wxHORIZONTAL )
inner = wxBoxSizer( wxVERTICAL )
self.controls = []
for x in range( self.count ):
ID = wxNewId()
# use your real editors here
control = wxTextCtrl( self, ID, "" )
self.controls.append( control )
inner.Add( control, 0, wxEXPAND )
outer.Add( inner, 1, wxEXPAND )
ID = wxNewId()
self.scroll = wxScrollBar( self, ID, style = wxSB_VERTICAL )
self.scroll.SetScrollbar( 0, self.count, len(self.data),
self.count )
outer.Add( self.scroll, 0, wxEXPAND )
EVT_COMMAND_SCROLL( self, self.scroll.GetId(), self.OnScroll )
self.SetSizer(outer)
self.SetAutoLayout(true)
self.Display( 0 )
def Display( self, start):
"""Update the items to show the virtual space"""
if start + self.count >= len( self.data ):
start = len(self.data)-self.count
for index in range( self.count ):
try:
self.controls[index].SetValue( self.data[start + index] )
except IndexError:
# not enought data to fill even one sheet
break
def OnScroll( self, event ):
position = event.GetPosition()
print 'OnScroll', position
self.Display( position )
event.Skip()
if __name__ == "__main__":
class TestApplication (wxPySimpleApp):
def OnInit(self):
frame =wxFrame (NULL, -1, "test", size = (300,500))
ScrollView( frame, data = map( str, range(2000)) )
frame.Show (1)
self.SetTopWindow(frame)
return 1
app = TestApplication ()
app.MainLoop()
Harrison, Matthew wrote:
Thanks for the advice Mike
is the m/v approach using a wxScrolledWindow? Is there a good
example of this somewhere that is using the OnDisplay and
OnScroll events? The demo/docs don't seem to help out here.thanks
matt
-----Original Message-----
From: Mike C. Fletcher [mailto:mcfletch@rogers.comModel:View Approach:
create X widgets where X is the number of widgets on a single screen
OnDisplay: update each widget with the data from
fulllist[topItem:bottomItem]
OnScroll: calculate shown area, OnDisplay( start, stop)
OnTab: ditto
...
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users