Hi,
first, I confirm that the previously described behavior
(event.WheelRotation=120 ->AttributeError: can’t set attibute)
is observed with versions 3.0.0.0 on MS windows, macOSX (cocoa), but not on 2.8.12.0 gtk (linux version)
On linux, I can set m_wheelRotation as mentioned in your post
So the trick to get it work with version 3.0 (at least on my mac, I don’t have my windows machine here) is to use monkey patching, testing either wx.version() or the presence of m_wheelRotation attribute
def FilterEvent(self,event):
if not hasattr(self, “WheelFunc”): # if it does not exist
self.WheelFunc=wx.MouseEvent.GetWheelRotation # preserve original GetWheelRotation method
setattr(wx.MouseEvent, ‘GetWheelRotation’, self.WheelFunc) # restore normal wheel behavior
if event.GetEventType()==wx.wxEVT_LEFT_DOWN:
if event.ControlDown():
event.SetEventType(wx.wxEVT_MOUSEWHEEL)
if wx.VERSION_STRING>=“3.0.0.0”:
#if not hasattr(event,‘m_wheelRotation’):
setattr(wx.MouseEvent, ‘GetWheelRotation’, lambda(x):120)
else:
event.m_wheelRotation=120
elif event.ShiftDown():
event.SetEventType(wx.wxEVT_MOUSEWHEEL)
if wx.VERSION_STRING>=“3.0.0.0”:
#if not hasattr(event,‘m_wheelRotation’):
setattr(wx.MouseEvent, ‘GetWheelRotation’, lambda(x):-120)
else:
event.m_wheelRotation=-120
However,
-
I don’t understand why monkey patching does not work on wx.version()=2.8.12.0…
-
I guess it would be nicer (less ugly) to use instance monkey patching instead of class monkey patching, but I couldn’t manage to get it work
Thanks anyway for your help!
Le vendredi 2 octobre 2015 09:32:39 UTC+2, Yves Le Feuvre a écrit :
···
Hello,
I’m trying to implement a FIlterEvent to emulate mouse wheel when user holds shift or control
The trouble is that I can change the event type using:
event.SetEventType(wx.wxEVT_MOUSEWHEEL)
however, I can’t set the wheel rotation value: I tried
event.WheelRotation=120 (which raises an Attibute error: can’t set attribute)
event.m_wheelRotation=120 (no error but event.GetWheelRotation returns 0)
In the same time, I can modify event.X and event.Y with no difficulties…
I attached a minimal exemple.
Any Ideas how to solve my problem?
Thanks in advance