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()
" 3 3607
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() "
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() "
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 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 PC). But every once in a
while, he'll press and hold the right mouse button, move onto a JButton,...
|
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 inside the <a href></a> tags.can any one help me.
waiting for ur solutions.thanking u in advance.
|
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.
|
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 controls. How can I
display a contextMenu where the cursor is by command only?
-mdb
|
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
| |
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 be pressed elsewhere out of the html
element (even outside of the browser) and then move over the...
|
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 interrupting the process and rarely work. Note that
oncontextmenu is a non-standard event and is not...
|
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.
|
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 a single user control, and to then have them appear when users enter some button and disappear when...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
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
| |