left/right mouse button events not trapped
Claudio Grondi
claudio.grondi at freenet.de
Tue Sep 6 12:11:38 EDT 2005
Below code which does the trick :))
Claudio
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)
self.Bitmap = 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.OnLeftClickDown)
wx.EVT_LEFT_UP(self.Panel,self.OnLeftClickUp)
wx.EVT_LEFT_DCLICK(self.Panel, self.OnLeftDoubleClick)
wx.EVT_LEFT_DOWN(self.Bitmap, self.OnLeftClickDownOnBitmap)
self.CreateStatusBar()
self.Show()
self.SetStatusText('Submap Coordinates:')
def OnLeftClickDown(self, event):
print " OnLeftClickDown"
def OnLeftClickDownOnBitmap(self, event):
print " OnLeftClickDownOnBitmap"
def OnLeftClickUp(self, event):
print " OnLeftClickUp"
def OnLeftDoubleClick(self, event):
print " OnLeftDoubleClick"
class MyApp(wx.App):
cD = 0
def OnInit(self):
wx.InitAllImageHandlers()
return 1
#
# Main
#
if __name__ == "__main__":
app = MyApp(0)
data = open('e:\winnt\Granit.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()
"Claudio Grondi" <claudio.grondi at freenet.de> schrieb im Newsbeitrag
news:3o5leuF46dvvU1 at individual.net...
> I don't know much about wxPython, but
> the left/right mouse button events _ARE_ trapped, but
> not when clicking on the image, probably because they
> are registered to the panel not to the image.
> Just resize the window and click next to the image.
>
> Hope this helps for now, before you get a response
> from someone who knows some more about wxPython
> (e.g. why the events from the bitmap are not forwarded
> to the panel containing it?).
>
> Claudio
> P.S. Here the corrected code I was able to run on my machine:
>
> 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('e:\winnt\Granit.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()
>
> <mitsura at skynet.be> schrieb im Newsbeitrag
> news:1126011805.903624.194460 at z14g2000cwz.googlegroups.com...
> > 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