Pan operation with many objects is very slow

Ralf Werner wrote:

Here comes my problem. I have to draw many objects to an wx.DC.
My currently biggest file has 5500 objects (circles, lines, rectangles).
This is only one layer. I have to read and display 6 layers.
...
My Question is how can i optimize my code, so that pan is a smooth
operation with so many objects. --

I have several suggestions. Right now, you are forcing all of your
drawing to be done in the "mouse move" message. You can get hundreds of
mouse move messages in a very small amount of time; you don't really
need to handle each and every one. Instead, in the mouse move message,
just remember the new location and call Refresh(). Then, do your
drawing in the Paint handler. That way, if Refresh gets called 10 times
before it can be painted, you'll only get one Paint event.

Next, you should do your drawing to a bitmap instead of live to the
screen. That way, you only pay the cost of the drawing once, and
scrolling just becomes a single copy operation from the bitmap to the
screen. The wx.ScrolledWindow class can help with that -- check the
wxPython demo.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

take a look at the Wiki, under "Double Buffered"

Also, you may want to consider wx.lib.floatcanvas, it was more or less
designed for this sort of thing, and has worked out a lot of these
issues.

Some more floatcanvas info:

http://trac.paulmcnett.com/floatcanvas

-Chris

···

On Mon, Mar 4, 2013 at 12:11 PM, Tim Roberts <timr@probo.com> wrote:

Next, you should do your drawing to a bitmap instead of live to the
screen. That way, you only pay the cost of the drawing once, and
scrolling just becomes a single copy operation from the bitmap to the
screen.

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov