Hello,
I’ve been struggling with using an image displayed in a wx.ScrolledWindow. The problems I’m having are all refresh(repaint) problems related to scrollbars being moved, window resizing, and incorrect image positioning when a repaint occurs and the sliders are not at 0,0… I’ve looked at some past posts related to this, as well as wxWidgets and wxPython documentation, and the book, but it’s sadly not sinking in. I would most appreciate any suggestions!
I’ve listed my test code below. My platform is Solaris 10, Python 2.4.3, wxPython 2.6.3.3 (a little behind in upgrading), though it is no better on windows.
Thanks in advance.
-Chris Botos
import wx
class ImageWindow(wx.ScrolledWindow):
“”“Window for displaying a bitmapped Image”""
def __init__(self, parent):
wx.ScrolledWindow.__init_
_(self, parent)
self.SetScrollRate(5,5)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def SetBitmap(self, bitmap):
self.bitmap = bitmap
self.SetVirtualSize(bitmap.GetSize())
# The following does nothing when called before
# the app starts.
cdc = wx.ClientDC(self)
cdc.DrawBitmap(self.bitmap, 0, 0)
def OnPaint(self, event):
dc = wx.BufferedPaintDC(self, self.bitmap)
## I have tried it with and without the following two lines
#x,y = self.GetViewStart()
#dc.DrawBitmap(self.bitmap, x, y)
class TestFrame(
wx.Frame):
def init(self):
wx.Frame.init(self, None, -1)
# image is 3072 x 2700
self.im1 = wx.Image("image.bmp", wx.BITMAP_TYPE_ANY)
[
self.bm](http://self.bm) = self.im1.ConvertToBitmap()
self.wind = ImageWindow(self)
self.wind.SetSize((600,400))
self.wind.SetBitmap(self.bm)
sizer = wx.BoxSizer
()
sizer.Add(self.wind)
self.SetSizer(sizer)
self.Fit()
self.Bind(wx.EVT_SIZE, self.OnSize)
def OnSize(self, event):
self.wind.SetSize(self.GetSize
())
if name==‘main’:
app = wx.PySimpleApp()
f = TestFrame()
f.Show()
app.MainLoop()