#------------------------------------------------------------------------------

class ImagePanel( wx.Panel ) :
    
    def __init__( self, parent, id=-1, size=(50, 50), bgColor=(100, 100, 155) ) : 
        
        wx.Panel.__init__( self, parent, id, size=size )
    
        self.SetBackgroundColour( bgColor )
    
    #end __init__ def
    
#end ImagePanel class

#------------------------------------------------------------------------------

class ImageWindow( wx.Window ):
    
    def __init__( self, parent, id, pos, size, bgColor ) :
        
        self.parent = parent
        self.bgColor = bgColor

        wx.Window.__init__( self, self.parent, id, pos, size )
        self.size = self.GetClientSize()        # must come after __init__ !
        
        self.panel = ImagePanel( self, bgColor=self.bgColor, size=self.size )
        self.panel.Bind( wx.EVT_RIGHT_UP, self.parent.OnQuit )       # mouse right-click
        
        #----------
        
        self.wxImage = wx.Image( 'PYTHON_SMALL.PNG' )
        self.wxBmap = self.wxImage.ConvertToBitmap()
        
        # Make the image background transparent.
        # The following works specifically because the self.wxBmap was 
        # derived from a PNG file which has an alpha transparency plane.
        # All image files don't have a transparency layer.
        wxImage = self.wxBmap.ConvertToImage()
        wxImage.InitAlpha()
        self.wxBmap = wxImage.ConvertToBitmap()
        
        self.imageSize = self.wxBmap.GetSize()
        self.imagePos = pos
        
        self.Bind( wx.EVT_PAINT, self.OnPaint )

    #end def __init__
    
    #----------------------------------------------------------------

    def OnPaint( self, event ):     # invoked on parent.Refresh()
        dc = wx.PaintDC( self.panel )     # created on every OnPaint event.
        self.DrawImage( dc )
        
        event.Skip()    # Very important to let all higher level handlers be called.
    #end def
    
    #----------------------------------------------------------------
    
    def DrawImage( self, dc ) :
        
        clientSize = self.GetClientSize()
        clientSizeX, clientSizeY = clientSize
        
        insideColor = self.bgColor
        dc.SetBrush( wx.Brush( wx.NamedColour( insideColor ), wx.SOLID ) )
        borderWidth = 5
        borderColor = self.bgColor
        dc.SetPen( wx.Pen( borderColor, borderWidth ) )
        clientOffsetX = clientOffsetY = 0
        dc.DrawRectangle( clientOffsetX, clientOffsetY , *clientSize )
        
        # draw the bitmap on the drawWindow client
        dc.DrawBitmap( self.wxBmap, 0, 0 )      # relative to ImageWindow
            
        #end if
        
    #end DrawImage def

#end ImageWindow class

#------------------------------------------------------------------------------

parentFrame:
    
        self.imageWindow = ImageWindow( self, -1, pos=(50, 50), size=(100, 100), 
                                        bgColor=self.bgColor )
    

