473,574 Members | 2,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

left/right mouse button events not trapped

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,w xID_ANY, title, size = ( w, h),
style=wxDEFAULT _FRAME_STYLE)

mD = 0

self.Panel=wx.P anel(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_DOW N(self.Panel, self.OnLeftClic k)
wx.EVT_LEFT_UP( self.Panel, self.OnLeftClic k)
wx.EVT_LEFT_DCL ICK(self.Panel, self.OnLeftClic k)
self.CreateStat usBar()
self.Show()

self.SetStatusT ext('Submap Coordinates:')

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

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

#
# Main
#

if __name__ == "__main__":
app = MyApp(0)
data = open(opj('c:\wi nnt\Greenstone. bmp'), "rb").read( )
stream = cStringIO.Strin gIO(data)
bmp = wx.BitmapFromIm age( wx.ImageFromStr eam( stream ))
bmpW = bmp.GetWidth()
bmpH = bmp.GetHeight()
DisplayPictureP anel=DisplayPic ture(None, -1, "Test MB", bmp, bmpW,
bmpH)
#MainFrame = DisplayPicture( None,-1,"Test Mouse Clicks")
app.MainLoop()
"

Sep 6 '05 #1
3 3596
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.P anel(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_DOW N(self.Panel, self.OnLeftClic k)
wx.EVT_LEFT_UP( self.Panel, self.OnLeftClic k)
wx.EVT_LEFT_DCL ICK(self.Panel, self.OnLeftClic k)

self.CreateStat usBar()
self.Show()

self.SetStatusT ext('Submap Coordinates:')

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

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

#
# Main
#

if __name__ == "__main__":
app = MyApp(0)
data = open('e:\winnt\ Granit.bmp', "rb").read( )
stream = cStringIO.Strin gIO(data)
bmp = wx.BitmapFromIm age( wx.ImageFromStr eam( stream ))
bmpW = bmp.GetWidth()
bmpH = bmp.GetHeight()
DisplayPictureP anel=DisplayPic ture(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.goo glegroups.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,w xID_ANY, title, size = ( w, h),
style=wxDEFAULT _FRAME_STYLE)

mD = 0

self.Panel=wx.P anel(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_DOW N(self.Panel, self.OnLeftClic k)
wx.EVT_LEFT_UP( self.Panel, self.OnLeftClic k)
wx.EVT_LEFT_DCL ICK(self.Panel, self.OnLeftClic k)
self.CreateStat usBar()
self.Show()

self.SetStatusT ext('Submap Coordinates:')

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

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

#
# Main
#

if __name__ == "__main__":
app = MyApp(0)
data = open(opj('c:\wi nnt\Greenstone. bmp'), "rb").read( )
stream = cStringIO.Strin gIO(data)
bmp = wx.BitmapFromIm age( wx.ImageFromStr eam( stream ))
bmpW = bmp.GetWidth()
bmpH = bmp.GetHeight()
DisplayPictureP anel=DisplayPic ture(None, -1, "Test MB", bmp, bmpW,
bmpH)
#MainFrame = DisplayPicture( None,-1,"Test Mouse Clicks")
app.MainLoop()
"

Sep 6 '05 #2
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_DOW N(self.Panel, self.OnLeftClic kDown)
wx.EVT_LEFT_UP( self.Panel,self .OnLeftClickUp)
wx.EVT_LEFT_DCL ICK(self.Panel, self.OnLeftDoub leClick)

wx.EVT_LEFT_DOW N(self.Bitmap, self.OnLeftClic kDownOnBitmap)

self.CreateStat usBar()
self.Show()

self.SetStatusT ext('Submap Coordinates:')

def OnLeftClickDown (self, event):
print " OnLeftClickDown "

def OnLeftClickDown OnBitmap(self, event):
print " OnLeftClickDown OnBitmap"

def OnLeftClickUp(s elf, event):
print " OnLeftClickUp"

def OnLeftDoubleCli ck(self, event):
print " OnLeftDoubleCli ck"

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

#
# Main
#

if __name__ == "__main__":
app = MyApp(0)
data = open('e:\winnt\ Granit.bmp', "rb").read( )
stream = cStringIO.Strin gIO(data)
bmp = wx.BitmapFromIm age( wx.ImageFromStr eam( stream ))
bmpW = bmp.GetWidth()
bmpH = bmp.GetHeight()
DisplayPictureP anel=DisplayPic ture(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.P anel(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_DOW N(self.Panel, self.OnLeftClic k)
wx.EVT_LEFT_UP( self.Panel, self.OnLeftClic k)
wx.EVT_LEFT_DCL ICK(self.Panel, self.OnLeftClic k)

self.CreateStat usBar()
self.Show()

self.SetStatusT ext('Submap Coordinates:')

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

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

#
# Main
#

if __name__ == "__main__":
app = MyApp(0)
data = open('e:\winnt\ Granit.bmp', "rb").read( )
stream = cStringIO.Strin gIO(data)
bmp = wx.BitmapFromIm age( wx.ImageFromStr eam( stream ))
bmpW = bmp.GetWidth()
bmpH = bmp.GetHeight()
DisplayPictureP anel=DisplayPic ture(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.goo glegroups.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,w xID_ANY, title, size = ( w, h),
style=wxDEFAULT _FRAME_STYLE)

mD = 0

self.Panel=wx.P anel(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_DOW N(self.Panel, self.OnLeftClic k)
wx.EVT_LEFT_UP( self.Panel, self.OnLeftClic k)
wx.EVT_LEFT_DCL ICK(self.Panel, self.OnLeftClic k)
self.CreateStat usBar()
self.Show()

self.SetStatusT ext('Submap Coordinates:')

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

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

#
# Main
#

if __name__ == "__main__":
app = MyApp(0)
data = open(opj('c:\wi nnt\Greenstone. bmp'), "rb").read( )
stream = cStringIO.Strin gIO(data)
bmp = wx.BitmapFromIm age( wx.ImageFromStr eam( stream ))
bmpW = bmp.GetWidth()
bmpH = bmp.GetHeight()
DisplayPictureP anel=DisplayPic ture(None, -1, "Test MB", bmp, bmpW,
bmpH)
#MainFrame = DisplayPicture( None,-1,"Test Mouse Clicks")
app.MainLoop()
"


Sep 6 '05 #3
Thanks Claudio! This really really made my day. I have been searching
for the problem for hours! Thanks again.

Sep 6 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6207
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 interact with the applet he needs to click on buttons, which is fine most of the time (he comes from a Mac environment, so I accept mouse clicks from the right or left button when he's working on the...
4
2092
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 in new window option.if he clicks on the left button i should prompt an alert message till he clicks the right mouse button ..i just want to write only a FEW lines of code.the code needs to written...
5
7938
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 = event.x; p.y = event.y; } ... (show) } document.onmousemove=mousePos; Seems to do fine on many browsers.
12
18301
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, for a button, I would listen to MouseDown and if I need to display the menu, I would contextMenu.Show(buttonCtrl, new Point(0)). But I can't do this for a notifyIcon because notifyIcons aren't...
6
6979
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 lblP1JoyUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblP1JoyUp.Click If bMouseMove = False Then If bCtrlKey = True Then
6
9706
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 "e.button == 0 for standard 'click', usually left button" http://developer.mozilla.org/en/docs/DOM:event.button Tracing of mouse clicks or mousedown/mouseup events looks not reliable, because mouse can...
8
3683
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I disable the right mouse button? ----------------------------------------------------------------------- The oncontextmenu intrinsic event is the only safe and reliable method. Of the other approaches often presented, most depend on an alert box...
18
3934
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 using: if(event.button==3) {alert("Both right and left mouse buttons pressed");} I am calling the above code on mousedown or mouseup events.
5
4838
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 button options to appear below the button. If the users mouse leaves the button, or the buttons in the list I want the list to disappear. I originally tried to place all of the drop down buttons into...
0
7805
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8053
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7817
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8098
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5301
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3741
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3752
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2245
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1060
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.