Repository navigation
Closed
Description
I implemented a small utility to visualize images timeseries. On jupyterlab 1.x everything was working as expected. There are two axes in the figure. When the mouse cursor is on one of the axes, you can scroll the mouse wheel to visualize a different image in the timeseries or zoom in... etc.
Since I updated to version 2.x when I use the mouse wheel to trigger the widget actions, the widget works as expected, but the webpage scrolls as well, so I need to move the cursor out of the widget, scroll back and repeat...
This is the code I use to handle the events:
class Click:
"""
Handles clicks of the mouse on the different axes.
Also controls that it is a single click and not a drag and release which
is used to zoom and would instead trigger an action without this control
"""
def __init__(self, visualizer, select_buttons=[1, 't'], debug=False):
self.vis = visualizer
self.select_buttons = select_buttons
self.press = False
self.move = False
self._debug = debug
events_connections = {'button_press_event': self.onpress,
'button_release_event': self.onrelease,
'motion_notify_event': self.onmove,
'scroll_event': self.onscroll,
'key_press_event': self.onclick}
self._mpl_connections = [self.vis.fig.canvas.mpl_connect(k, f) for
k, f in events_connections.items()]
def onclick(self, event):
if isinstance(event, KeyEvent):
button = event.key
else:
button = event.button
if button == 'r':
self.vis.reset_zoom()
elif button == 'y':
self.vis._toggle_mask()
elif button in self.select_buttons:
if event.inaxes == self.vis.axs[0]:
self.vis.select_pixel(event)
elif event.inaxes == self.vis.axs[1]:
self.vis.select_slice(event)
def onscroll(self, event):
if event.inaxes == self.vis.axs[1]:
self.vis.slicetime(event)
elif event.inaxes == self.vis.axs[0]:
self.vis.zoom(event)
def onpress(self, event):
self.press = True
def onmove(self, event):
if self.press:
self.move = True
def onrelease(self, event):
if self.press and not self.move:
self.onclick(event)
self.press = False
self.move = False
If necessary I can provide the full widget or perhaps workout a reproducible example.
Versions
python -c "import sys; print('\n',sys.version); import ipympl; print('ipympl version:', ipympl.__version__)" && jupyter --version && jupyter nbextension list && jupyter labextension list-->
3.7.6 | packaged by conda-forge | (default, Jun 1 2020, 18:57:50)
[GCC 7.5.0]
ipympl version: 0.5.6
jupyter core : 4.6.3
jupyter-notebook : 6.0.3
qtconsole : not installed
ipython : 7.15.0
ipykernel : 5.3.0
jupyter client : 6.1.3
jupyter lab : 2.1.4
nbconvert : 5.6.1
ipywidgets : 7.5.1
nbformat : 5.0.6
traitlets : 4.3.3
Known nbextensions:
config dir: /home/dzanaga/miniconda3/etc/jupyter/nbconfig
notebook section
jupyter-matplotlib/extension enabled
- Validating: OK
nbdime/index enabled
- Validating: OK
jupyter-js-widgets/extension enabled
- Validating: OK
config dir: /usr/local/etc/jupyter/nbconfig
notebook section
plotlywidget/extension enabled
- Validating: OK
JupyterLab v2.1.4
Known labextensions:
app dir: /home/dzanaga/miniconda3/share/jupyter/lab
@jupyter-widgets/jupyterlab-manager v2.0.0 enabled OK
@jupyterlab/debugger v0.3.0-beta.1 enabled OK
@jupyterlab/git v0.20.0 enabled OK
@krassowski/jupyterlab-lsp v1.0.0 enabled OK
@oriolmirosa/jupyterlab_materialdarker v0.5.0 enabled OK
jupyter-matplotlib v0.7.2 enabled OK
nbdime-jupyterlab v2.0.0 enabled OK
Metadata
Metadata
Assignees
Labels
No labels
Activity
martinRenou commentedon Jun 24, 2020
This PR should have fixed this issue #235. It has not been released yet though.