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()
" 3 3470
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() "
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() "
Thanks Claudio! This really really made my day. I have been searching
for the problem for hours! Thanks again. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John Champaign |
last post by:
Hi all,
I'm working on an educational applet for a child with special needs.
He's got a bit of a trick to make my life more difficult... To...
|
by: Lakshmi Narayanan |
last post by:
hi all,
i have this problem.i want the user of my page to only click the link
with the right mouse button and open a word document using the open...
|
by: gsb |
last post by:
I track the mouse location like this code:
function mousePos(e) {
var p = new Object();
if(e) { p.x = e.pageX; p.y = e.pageY; }
else { p.x =...
|
by: mdb |
last post by:
My app has a notify icon in the systray. I want the left mouse click to
initiate a menu, and a right-mouse click to do something else. Normally,...
|
by: jcrouse |
last post by:
I have the following mouse events assigned to a label control. Is the a way
I can tell which mouse button the users has clicked with?
Private Sub...
|
by: marss |
last post by:
Hi,
How can I define in Firefox whether the left mouse button is pressed
when I move mouse over a html element?
The documentation says that...
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I disable the right mouse button?...
|
by: Shocky |
last post by:
Hi there,
I am trying to detect whether my IE6 users have pressed both right and
left mouse buttons simultaneously in my Javascript code, by...
|
by: Zaxxon21 |
last post by:
I'm basically trying to implement a simple drop down menu list for a button that I have. When the user hovers over the button, I want a list of...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
| |