Dynamic Resizing and Centering Image.

Hello,

Does anyone give me a hand?
What I want to do is showing image on center of a panel.
And if panel is resized, image is dynamically moved, and placed at center of panel.
Also, panel might be resized bigger and smaller,
so, if panel size is changed, image size is also changed.

I thought that , I have to implement event handler of EVT_PAINT.
And in that event handler, what I have to do is,

1. erase previous image
2. reculcurating image size and position.
3. redraw image

But I failed to erase image. The following is sample code I wrote.
Please check OnPaint method especially.
In that method, I try to call EraseImg() at two point.

If I call EraseImg() at 1st point, image is never erased.
If I call EraseImg() at 2nd point, image is never shown.

I dont understand why 1st point never erased the image.
Does anyone tell me why?

Kindly Regards,
mk

---------- sample code -----------

import wx, sys

class SampleFrame(wx.Frame):

    def __init__(self, parent):

        # global variables
        self.img = wx.Image( 'PATH_TO_IMAGE' )
        self.pos = None
        self.size = None
        
        # init operations
        wx.Frame.__init__(self, parent, -1, size=(550, 550))
        self.Show()
        self.panel = wx.Panel(self, -1, size=(550,550))
        
        # set event handler
        self.panel.Bind(wx.EVT_PAINT, self.OnPaint)

    # event handler...
    def OnPaint(self, evt):
        
        dc = wx.PaintDC(self.panel)
        self.panel.PrepareDC(dc)

        # ######## 1st point. ############
        #in this case, image isnt erased
        #self.EraseImg(dc)
        #dc.Clear()

        (size, pos) = self.__reCulcImgSize('PATH_TO_IMAGE' )
        bmp = self.img.Scale(size[0], size[1]).ConvertToBitmap()
        dc.DrawBitmap(bmp, pos[0], pos[1])

        # remember for erasing this image.
        self.size = size
        self.pos = pos

        # ######## 2nd point. ############
        #in this case, image never be showm
        #dc.Clear()
        #self.EraseImg(dc)

    # culcurating image size and position to put image on center.
    def __reCulcImgSize(self, imgPath):
        
        scSize = self.panel.GetSize()
        sw = scSize[0]
        sh = scSize[1]

        img = wx.Image( imgPath )
        iw = img.GetWidth()
        ih = img.GetHeight()
        
        if ih * sw/iw < ih :
            iw = iw * sh/ih
            ih = sh
        else :
            iw = sw
            ih = ih * sw/iw
        
        pw = sw/2 - iw/2
        if pw < 0 : pw = 0
        
        ph = sh/2 - ih/2
        if ph < 0 : ph = 0

        return ( (iw,ih), (pw, ph) )

    # erase image
    def EraseImg(self, dc):
        if self.pos == None : return
        r = wx.Rect(self.pos[0], self.pos[1], self.size[0], self.size[1])
        dc.SetClippingRect(r)
        dc.DestroyClippingRegion()