> Hi, I have a python script file that must capture the mouse scroll-wheel (in my case).
> I need this functionality in my xygraph widget.
> Having installed pynput in my Python2.7, it works outside CSS but when I run my CSS with the script below,
> it comes back with "ImportError: No module named pynput"
value = PVUtil.getDouble(pvs)
widget.setPropertyValue("text", "The value is now %g" % value)
Similarly, BOY scripts do have access to the full Java API of CSS BOY.
So you can read the source code and see what else is possible beyond what's described in the online help.
In this specific case, however, I'm not sure there is a way to get at the scroll wheel events in a reliable way into scripts.
If you check the type of the 'widget' that's handed to your script (print the widget.__class__.__name__), you'll find that it's based on the Draw2D org.eclipse.gef.editparts.AbstractEditPart.
You can call getFigure() to obtain the underlying draw2d Figure, which in turn has methods addMouseListener() and addMouseMotionListener().
Those listeners, however, only get the usual mouse click and move events, no mouse wheel events.
As far as I understand, for handling the mouse wheel events the Draw2D figure needs to implement the org.eclipse.gef.MouseWheelHelper interface (https://github.com/eclipse/gef-legacy/blob/master/org.eclipse.gef/src/org/eclipse/gef/MouseWheelHelper.java).
That's something you'd have to do on for example the XYGraph widget itself, you can't change the class of an existing object from the script.
I was hoping to get somewhere by locating the hosting SWT Shell, to which you can attach a mouse wheel listener, like this:
# Attach script to for example the display, trigger it once via a dummy input like loc://init(1)
from org.eclipse.ui import PlatformUI
from org.eclipse.swt.events import MouseWheelListener
def mouseScrolled(self, event):
my_listener = MyListener()
shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()
.. but that listener is rarely called. It is invoked when I use the scroll wheel over the name tab of a display, but not while the mouse is within the display itself. Presumably, the underlying shell doesn't receive the mouse events because they're already captured by the Draw2D figures, and then ignored because they don't implement the MouseWheelHelper.
So bottom line it looks to me as if you'd have to update the BOY XYGraph to handle mouse wheel events.
For what it's worth, the Display Builder update of BOY (see presentation at previous or upcoming EPICS meetings) already includes an XY Plot widget that handles mouse wheel events. In there, you can use Ctrl + Mouse Wheel to zoom in or out of the axis under the mouse, or the whole plot while the mouse is inside the plot.
- CSS PyDev - capturing mouse event Mogamad-Amien Crombie
- Navigate by Date:
RE: AreaDetector bindings and RBV propagation Mark Rivers
Re: V4 question. Andrew Johnson
- Navigate by Thread:
CSS PyDev - capturing mouse event Mogamad-Amien Crombie
Question about Edm dynamic display zone's fill color according to PVs lzf neu