'''  image2.py  20060331
EVT_LEFT_DOWN doesn't generate an event when over the image!!!!

EVT_MOUSE_EVENTS did return x/y positions over the bitmap image...
but only when the cursor moves. These didn't work over the bitmap:
event.LeftDown()   event.LeftUp()   event.LeftIsDown()  event.ButtonDown()
'''

import  cStringIO, wx, wxPython.wx
import numpy as N

class TestPanel(wx.Panel):

    def __init__(self, parent):

        wx.Panel.__init__(self, parent, -1)

        bytes = open('xyz.png', "rb").read()
        stream = cStringIO.StringIO(bytes)
        bmp = wx.BitmapFromImage(wx.ImageFromStream(stream))
        wx.StaticBitmap(self, -1, bmp,
                        (15, 45),           # x,y corner
                        (bmp.GetWidth(),    # bitmap width
                         bmp.GetHeight()))  # bitmap height

class MyFrame (wxPython.wx.wxFrame):

    def __init__ ( self, parent, id ):    
        wxPython.wx.wxFrame.__init__ ( self, parent, id, "Idle Test" )
        self.SetSize((900,700))
        self.client = TestPanel(self)
        wx.EVT_LEFT_DOWN(self.client, self.OnMouseLeftDown)
        wx.EVT_MOUSE_EVENTS(self.client, self.OnMouseEvent)
        
    def OnMouseLeftDown(self, event):       # Doesn't work!
        x,y = N.array(event.GetPosition())  # over the bitmap
        print x,y
        event.Skip()

    def OnMouseEvent(self, event):
        ''' Handles ALL mouse events '''

        # These event don't work over the bitmap image...
        if event.LeftDown():
            print "Left button just pressed"
        if event.LeftUp():
            print "Left button just released"
        if event.ButtonDown():
            print "ButtonDown().."
        if event.IsButton():
            print "IsButton().."
        if event.Button(wxPython.wx.wxMOUSE_BTN_LEFT):
            print "Button.."

        # These events work - but only when the mouse is moved...
        if event.ButtonIsDown(wxPython.wx.wxMOUSE_BTN_LEFT):
            print "ButtonIsDown().."
        if event.LeftIsDown():
            print "Left button is down.."
            
        x,y = N.array(event.GetPosition())  # I get response when
        print x,y                           # over the bitmap, but only
        event.Skip()                        # when the cursor moves
          
class MyApp(wxPython.wx.wxApp):
    def OnInit(self):
        frame = MyFrame(wxPython.wx.NULL, -1)   
        frame.Show(True)
        self.SetTopWindow(frame)
        return True        

def main():
    app = MyApp()       
    app.MainLoop()

if __name__ == "__main__":
    main()
