wxpython and zoom/pan image

Dave Angel davea at ieee.org
Sat May 23 21:29:46 EDT 2009

rzzzwilson at gmail.com wrote:
> Hi,
> I've googled for this, but can only find things like openlayers that
> is a web-based javascript solution.
> I need to display an image at various zoom levels and want to allow
> the user to pan around in the Google maps style, that is, left-click
> hold and drag.  The code should also action double-clicks on the image
> (but that's easy).
> There are no 'standard' wxpython widgets that allow this.  Can anyone
> point me to information on how to implement such a thing, or maybe
> some working code?
> Thanks,
> Ross
These are all (?) of the pieces in my working image display program.  It 
rotates and scales.  It's an exercise to the reader to divide it up.  
For example, you don't want to rerun all of this every time the mouse
drags a little.  So these are in two different places, where the first 
group only happens when you change the image file, or rotate by an angle 
other than 90 degrees
            self._img = wx.Image(self.fname, wx.BITMAP_TYPE_ANY)
            self._img = wx.EmptyImage(42, 42, True)  #create a plain 
black image, 42 x 42 pixels
            self._img = self._img.Rotate90()
            self._img = self._img.Rotate(-radians, center)

        img2 = img1.Scale(self.imageW()*scale/1000, 
self.imageH()*scale/1000)    #this is where image is scaled to final bit 
dimensions.  It's clipped during drawBitmap()
        tracer("drawStuff  Scale", "draw")
        bmp = wx.BitmapFromImage(img2)

        w, h = self.GetClientSize()                         #self is a 
subclass of Panel
        self.buffer = wx.EmptyBitmap(w, h)
        dc = wx.BufferedDC(wx.ClientDC(self), self.buffer)
        dc.DrawBitmap(bmp, cornerX, cornerY, False)

Hope this helps.  I tied the scaling to the mousewheel, and used drag to 
move the cornerX and cornerY.  Notice they can go negative, as well as 

More information about the Python-list mailing list