Attached is a short program demonstrating a problem with refreshing an
image in a ScrolledWindow. I need to be able to specify the location
of an image within the window, such as centering it if the image is
smaller than the window. I used the wxPIA example 12.3 as a model.
As demonstrated in the program, when I use the following paint event
handler (with useBlit=False in the file), the image does not repaint
correctly when scrolling.
def OnPaintBitmap(self, event):
dc = wx.PaintDC(self)
dc.DrawBitmap(self.bitmap, 0, 0)
If I use the following method instead (useBlit=True), everything is fine.
Attached is a short program demonstrating a problem with refreshing an
image in a ScrolledWindow. I need to be able to specify the location
of an image within the window, such as centering it if the image is
smaller than the window. I used the wxPIA example 12.3 as a model.
As demonstrated in the program, when I use the following paint event
handler (with useBlit=False in the file), the image does not repaint
correctly when scrolling.
def OnPaintBitmap(self, event):
dc = wx.PaintDC(self)
dc.DrawBitmap(self.bitmap, 0, 0)
If I use the following method instead (useBlit=True), everything is fine.
My normal platform is Solaris 10 with wxPython 2.6.3.3, Python 2.5.
However the same thing happens on Windows XP, wxPython 2.8.9.2.
I would appreciate any suggestions as to what I might be missing in
OnPaintBitmap or otherwise doing wrong.
You are missing the PrepareDC call. That adjusts the origin of the DC to match the scrolled offset of the window, so when you draw at (0,0) logical coordinates it may actually end up drawing at something like (-10,-20) device coordinates if the user has scrolled the window.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Ah! That does indeed fix it. So the example in the book (12.3)
doesn't need it because the coordinates never need to be adjusted.
Thanks Robin!
Chris
···
On 3/5/09, Robin Dunn <robin@alldunn.com> wrote:
You are missing the PrepareDC call. That adjusts the origin of the DC
to match the scrolled offset of the window, so when you draw at (0,0)
logical coordinates it may actually end up drawing at something like
(-10,-20) device coordinates if the user has scrolled the window.