By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,715 Members | 1,283 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,715 IT Pros & Developers. It's quick & easy.

left/right mouse button events not trapped

P: n/a
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()
"

Sep 6 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
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()

<mi*****@skynet.be> schrieb im Newsbeitrag
news:11**********************@z14g2000cwz.googlegr oups.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()
"

Sep 6 '05 #2

P: n/a
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" <cl************@freenet.de> schrieb im Newsbeitrag
news:3o************@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()

<mi*****@skynet.be> schrieb im Newsbeitrag
news:11**********************@z14g2000cwz.googlegr oups.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()
"


Sep 6 '05 #3

P: n/a
Thanks Claudio! This really really made my day. I have been searching
for the problem for hours! Thanks again.

Sep 6 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.