left/right mouse button events not trapped

mitsura at skynet.be mitsura at skynet.be
Tue Sep 6 15:03:26 CEST 2005


Hi,

I have included a small listing. The test program opens a panel and
show a bitmap.
What I want is to when the mouse is over the bitmap panel, I want to
trap the left mouse click.
The purpose is to get the position of the mouse pointer on the bitmap.
However, for some reason, the left (I also tried right) mouse clicks
are not intercepted.
I new to Python and wxWindows so any help would be greatly appreciated.

With kind regards,

Kris
"
import  string
import  wx
import  images
import  os
import  cStringIO
import xml.sax

from wxPython.wx import *
from Main import opj

class DisplayPicture(wx.Frame):
      cD = 0

      def __init__(self, parent, id, title, bmp, w, h):
    	 wxFrame.__init__(self,parent,wxID_ANY, title, size = ( w, h),
                                    style=wxDEFAULT_FRAME_STYLE)

      	 mD = 0

	 self.Panel=wx.Panel(self)
         wx.StaticBitmap(self.Panel, -1, bmp, (5, 5) )

	 """ FOR SOME REASON THE MOUSE CLICKS DON'T WORK!"""
	 """ SHIT SHIT SHIT SHIT ... x 1000 """
	 wx.EVT_LEFT_DOWN(self.Panel, self.OnLeftClick)
         wx.EVT_LEFT_UP(self.Panel, self.OnLeftClick)
         wx.EVT_LEFT_DCLICK(self.Panel, self.OnLeftClick)


	 self.CreateStatusBar()
         self.Show()

         self.SetStatusText('Submap Coordinates:')

      def OnLeftClick(self, event):
      	  print "ok the mouse click works!"

class MyApp(wx.App):
    cD = 0
    def OnInit(self):
        wx.InitAllImageHandlers()
        return 1

#
# Main
#

if __name__ == "__main__":
    app = MyApp(0)


    data = open(opj('c:\winnt\Greenstone.bmp'), "rb").read()
    stream = cStringIO.StringIO(data)
    bmp = wx.BitmapFromImage( wx.ImageFromStream( stream ))
    bmpW = bmp.GetWidth()
    bmpH = bmp.GetHeight()
    DisplayPicturePanel=DisplayPicture(None, -1, "Test MB", bmp, bmpW,
bmpH)
    #MainFrame = DisplayPicture(None,-1,"Test Mouse Clicks")
 

    app.MainLoop()
"




More information about the Python-list mailing list