EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <20172018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <20172018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: CSS PyDev - capturing mouse event
From: "Kasemir, Kay" <[email protected]>
To: Mogamad-Amien Crombie <[email protected]>, EPICS Tech-Talk <[email protected]>
Date: Tue, 9 May 2017 13:54:54 +0000
Hi:

> 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"

CSS BOY invokes Jython or JavaScript scripts, with the class path of the Java code that runs the BOY code.
This is comparable to JavaScript running within the web browser seeing the DOM of the web page.
JavaScript running within your web browser is only meant to interact with your web page and not just anything installed on the computer.
Similarly, Jython or JavaScript code invoked by a BOY script is meant to use the documented API, refer to the CSS online help.
Something like

value = PVUtil.getDouble(pvs[0])
widget.setPropertyValue("text", "The value is now %g" % value)

In reality, JavaScript running inside your web browser might actually be able to do more than intended.
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

class MyListener(MouseWheelListener):
    def mouseScrolled(self, event):
        print("Scrolled!")

my_listener = MyListener()

shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()
shell.addMouseWheelListener(my_listener)


.. 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.

Thanks,
Kay

References:
CSS PyDev - capturing mouse event Mogamad-Amien Crombie

Navigate by Date:
Prev: RE: AreaDetector bindings and RBV propagation Mark Rivers
Next: Re: V4 question. Andrew Johnson
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <20172018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: CSS PyDev - capturing mouse event Mogamad-Amien Crombie
Next: Question about Edm dynamic display zone's fill color according to PVs lzf neu
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <20172018  2019  2020  2021  2022  2023  2024 
ANJ, 21 Dec 2017 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·