[wxPython] optimizing layout of many widgets

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

Model: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

Grid Approach:

Use a wxGrid, it won't look at all the same, but would likely handle a
huge data set with very little work.

I personally would use the first approach. You just create a set of the
widgets with a scroll-bar control next to them, set the displayed number
/ total number as the height of the slider, then head off to the races.

HTH,
Mike

Harrison, Matthew wrote:

···

-----Original Message-----
From: Mike C. Fletcher [mailto:mcfletch@rogers.com

Hi All-

I'm working on an application to classify a bunch of words.
Each word is represented by a widget that consists of 7 buttons(to change
word attributes) and a text control (to edit the word).
The application needs to process many terms (~20,000).
Currently each control in the word widget is layed out by a box sizer.
Is there a more efficient way to do this? The widget will not have to be
resized. Will a grid sizer be any more efficient? Any other ideas?

Also I want to display thes 20,000 widgets in a scrolling panel.
Currently it is a wxScrolledWindow with a boxSizer to hold to widgets.
Again, I will probably not be resizing anything, but performance is very
slow with only 500 widgets (pIII 800Mhz, 512Megs).
What is the best way allow scrolling through many widgets? Right
now, it isn't responsive enough to be useful.

Any hints or suggestions on how to improve the performance would be
great.

thanks

matt

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

--
_______________________________________
   Mike C. Fletcher
   http://members.rogers.com/mcfletch/

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

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

From: Mike C. Fletcher [mailto:mcfletch@rogers.com

Model: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

...

···

-----Original Message-----