[wxPython] Clearing an Image from a Panel (Re-Post)

MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

This is a re-post as I had no responses to the
original. I've included a little extra info I've
discovered.

I am porting an Image Archiving application to
wxPython as a learning exercise. I have a panel which
I am painting images to using the usual wxStaticBitmap
call on the image once converted to a BMP. This works
fine. However, to avoid image overlap I need to clear
the panel prior to each call to wxStaticBitmap. First
I tried what is used in lib/imagebrowser.py -
panel.SetBackgroundColour(wxColour(255,255,255))
followed by panel.Refresh() which achieved nothing.
After scouring the doco I tried panel.Clear() followed
by panel.Refresh() also with no luck. The code is
definitely being executed as it appears just prior to
the wxStaticBitmap call. My platform is Redhat Linux
7.1/Python 2.1.1/wxPython 2.3.1. Any suggestions as
to where I'm going wrong?

New Info: The panel is definitely storing all previous
images. When <ALT-TAB>ing between apps I can see the
images being painted over each other. wxLogMessage
definitely indicates only the expected single call to
display is made. I have also tried image.Destroy() to
discard old images (see code), but that only leads to
a core dump.

class Canvas(wxPanel):
    def
__init__(self,parent,id,pos=wxDefaultPosition,size=wxDefaultSize,style=wxTAB_TRAVERSAL):
       
wxPanel.__init__(self,parent,id,pos,size,style)
        self.img=NULL
        
    def display(self,imgpath,point=wxPoint(0,0)):
        #if self.img:
            #self.img.Destroy()
          
self.img=wxImage(imgpath,wxBITMAP_TYPE_JPEG).ConvertToBitmap()
       
#self.SetBackgroundColour(wxColour(255,255,255))
        #self.Clear()
        wxLogMessage('Displaying %s' % imgpath)
       
wxStaticBitmap(self,-1,self.img,point,wxSize(self.img.GetWidth(),self.img.GetHeight()))
        #self.Refresh()

···

__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

I am porting an Image Archiving application to
wxPython as a learning exercise. I have a panel which
I am painting images to using the usual wxStaticBitmap
call on the image once converted to a BMP. This works
fine. However, to avoid image overlap I need to clear
the panel prior to each call to wxStaticBitmap. First
I tried what is used in lib/imagebrowser.py -
panel.SetBackgroundColour(wxColour(255,255,255))
followed by panel.Refresh() which achieved nothing.
After scouring the doco I tried panel.Clear() followed
by panel.Refresh() also with no luck. The code is
definitely being executed as it appears just prior to
the wxStaticBitmap call. My platform is Redhat Linux
7.1/Python 2.1.1/wxPython 2.3.1. Any suggestions as
to where I'm going wrong?

wxStaticBitmap is not just a function to place a bitmap on the panel. It is
a class that derives from wxWindow, so it is a separate window than your
panel. THat is why when you clear or refresh the panel nothing appears to
happen, because it is happening under this other window that does contain
the bitmap.

What you probably want to do is draw your bitmap on the window by using a
DC. Use a wxClientDC to draw it immediately, use a wxPaintDC inside an
EVT_PAINT handler to redraw it when the window needs repaining. See the
demo for examples.

If you really want to do it with wxStaticBitmap then save a reference to the
window it creates and use it to load new bitmaps, etc. But only create one
of them.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!