Drawing over an image in a ScrolledWindow, with buffering

Hello,

I am trying to use the “ScrolledWindow” example from the wxPython demo to draw points at mouse clicks over a large image file. The image file is loaded into a ScrolledWindow, which is placed in a Frame with other buttons. I have it set up to use buffering, per the example.

I can get points to draw if they are included in the self.pts list at init, but I can’t get any new points (based on mouse clicks) to draw.

Is there something I’m missing in my DoDrawing method?

The ‘test.png’ file should be in the same directory when the app is run. Any help on getting the mouse click points to draw would be much appreciated.

This is on:

wx 2.8.10.1

Python 2.6.2

WindowsXP

Thanks,

jim

scrolledCanvas.py (3.62 KB)

test.png

Two things. First, don't save the dc in self. Most platforms won't let you select the buffer bitmap into more than one DC at a time. Instead, recreate the DC each time you need it, all you need to save is the buffer bitmap itself. Secondly, OnClick is only updating the buffer, it won't update the screen unless you tell it to. I did this by adding a call to Refresh() but if you want to optimize the update a bit you can use RefreshRect passing a rectangle that encloses the area of the window around the new point that needs to be redrawn. You can also further optimize this example by not redrawing the entire buffer in OnClick, just add the new lines to the existing buffer.

scrolledCanvas.py (3.54 KB)

···

On 4/6/10 9:31 AM, Jim R wrote:

Hello,

I am trying to use the "ScrolledWindow" example from the wxPython demo
to draw points at mouse clicks over a large image file. The image file
is loaded into a ScrolledWindow, which is placed in a Frame with other
buttons. I have it set up to use buffering, per the example.
I can get points to draw if they are included in the self.pts list at
__init__, but I can't get any new points (based on mouse clicks) to draw.
Is there something I'm missing in my DoDrawing method?
The 'test.png' file should be in the same directory when the app is run.
Any help on getting the mouse click points to draw would be much
appreciated.

--
Robin Dunn
Software Craftsman