EVT_MOTION and a staticbitmap

Hello Folks

I am trying to display the coordinates of a wx.StaticBitmap
continuously as the mouse moves over it. I wrote an EVT_MOTION call
back to display it. It doesn't work. From what I understand,
wx.StaticBitmap is derived ffrom wx.Window and wx.Window supports
EVT_MOTION? Any thoughts would be helpful.

My code skeleton

self.img = wx.StaticBitmap(bitmap=wx.NullBitmap, id=wxID_FRAME1IMG,
              name=u'img', parent=self.panel2, pos=wx.Point(8, 8),
              size=wx.Size(2000,2000), style=wx.STATIC_BORDER)
wx.EVT_MOTION(self.img,self.OnMouseMove)

in the __init__ of the frame class

def OnMouseMove(self,event):
        pt = event.GetPosition()
        x=pt.x
        y=pt.y
        print x,y
        event.Skip()

but it doesn't print x,y ..

I wrote a OnLeftButton event for the image which works!

(I load a different image using a different callback. So self.img is
not always wx.NullBitmap)

thanks
Krish

Hello Krish,

    On Windows, if I use the module from wx.lib.GetStaticBitmap, my EVT_MOTION
function works. It does not work with the standard wx.StaticBitmap. I attach
an example at the end of the mail. However, I don't know why, I get the
error:

Traceback (most recent call last):
  File "C:\Python23\Lib\site-packages\wx-2.6-msw-ansi\wx\lib\statbmp.py",
line 7
7, in OnPaint
    dc.DrawBitmap(self._bitmap, 0, 0, True)
  File "C:\Python23\Lib\site-packages\wx-2.6-msw-ansi\wx\_gdi.py", line
2911, in
DrawBitmap
    return _gdi_.DC_DrawBitmap(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed in ..\..\src\m
sw\dc.cpp(1052): invalid bitmap in wxDC::DrawBitmap

If I use wx.NullBitmap as an input for wx.lib.GenStaticBitmap... don't know,
maybe Robin will know it. For the rest, it works.

HTH.

Andrea.

import wx
from wx.lib.statbmp import GenStaticBitmap as StaticBitmap

class MyFrame(wx.Frame):

    def __init__(self, parent):

        wx.Frame.__init__(self, parent, -1, "Bitmap EVT_MOTION Test",
                          size=(500,400))

        panel = wx.Panel(self, -1)
        bmp = wx.NullBitmap
        img = StaticBitmap(panel, -1, bmp, pos=wx.Point(50,50),
                           size=wx.Size(300,300),
                           style=wx.STATIC_BORDER)

        img.Bind(wx.EVT_MOTION, self.OnMouseMove)

    def OnMouseMove(self,event):

        pt = event.GetPosition()
        x=pt.x
        y=pt.y
        print x,y
        event.Skip()

def main():
    app = wx.PySimpleApp()
    frame = MyFrame(None)
    frame.Show()
    app.MainLoop()

if __name__ == "__main__":
    main()