Code Monkey home page Code Monkey logo

ipyevents's Introduction

ipyevents

Browsers events for your jupyter widgets

ipyevents provides a custom widget for returning mouse and keyboard events to Python. Use it to:

  • add keyboard shortcuts to an existing widget;
  • react to the user clicking on an image;
  • add callbacks on arbitrary mouse and keyboard events.

See this demo notebook for documentation.

Special thanks to the contributors to ipyevents!

Try it on binder:

Dev version: Binder

Documentation

Documentation Status

Installation

To install using conda:

$ conda install -c conda-forge ipyevents

To install use pip:

$ pip install ipyevents

Using with JupyterLab (whether you installed with conda or pip):

  • The stable releases of ipyevents (2.0.0 and higher) are only built for JupyterLab 3 and up.
  • The last release that is built for JupyterLab 2 is 0.9.0. See the README for that version for installation instructions.
$ jupyter labextension install @jupyter-widgets/jupyterlab-manager ipyevents

For a development installation (requires npm),

$ git clone https://github.com/mwcraig/ipyevents.git
$ cd ipyevents
$ pip install -e .
$ jupyter nbextension install --py --symlink --sys-prefix ipyevents
$ jupyter nbextension enable --py --sys-prefix ipyevents

For Jupyter Lab also do this:

$ npm install
$ npm run build
$ jupyter labextension install

ipyevents's People

Contributors

akaszynski avatar astrofrog avatar cfhammill avatar dependabot[bot] avatar itssimon avatar jtpio avatar lordvlad avatar martinrenou avatar mwcraig avatar pbugnion avatar pkgw avatar prabhuramachandran avatar schwehr avatar sylvaincorlay avatar zerline avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ipyevents's Issues

provide event target information?

I made a feature suggestion for JupyterLab, jupyterlab/jupyterlab#7873, where I noted that I tried to use ipyevents to implement it, and ran into problems.

Could you have a look there and tell me whether you would be interested in extending your package to enable the behavior I need?

Briefly, I need to detect mouse click events, but not by x,y coordinates but by targeted element (or even better, a parent of the target element via event.target.closest(selector)).

prevent_default_action does not work if wheel event

import ipywidgets as widgets
from ipywidgets import Label, HTML, HBox, Image, VBox, Box, HBox, Textarea, Layout
from ipyevents import Event 
from IPython.display import display

c = ""
for i in range(100):
   c += "%daaaaaaaaaaaaaaaaaaaaa\n" % i
   
text =Textarea(c, layout=Layout(height='200px', width='200px'))
h = HTML('Event info')
d = Event(source=text, watched_events=['wheel'], prevent_default_action=False)

def handle_event_default_demo(event):
   lines = ['{}: {}'.format(k, v) for k, v in event.items()]
   content = ' '.join(lines)
   h.value = content
d.on_dom_event(handle_event_default_demo)
display(text, h)

I tested above code, the default wheel action does not work. The textarea scroll does not move.
I want to know scroll movement of textarea.

conda update complains about pre-unlink script failed

conda told me to notify maintainer about this, so here it is.

$ conda update ipyevents
Solving environment: ...working... done

## Package Plan ##

  environment location: C:\...\Miniconda3\envs\py37

  added / updated specs:
    - ipyevents


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    notebook-5.7.4             |        py37_1000         7.4 MB  conda-forge
    ipyevents-0.4.0            |        py37_1000          46 KB  conda-forge
    ------------------------------------------------------------
                                           Total:         7.4 MB

The following NEW packages will be INSTALLED:

    jsonschema: 3.0.0a3-py37_1000 conda-forge

The following packages will be UPDATED:

    ipyevents:  0.3.1-py37_1000   conda-forge --> 0.4.0-py37_1000 conda-forge
    notebook:   5.7.0-py37_1000   conda-forge --> 5.7.4-py37_1000 conda-forge

Proceed ([y]/n)? y


Downloading and Extracting Packages
notebook-5.7.4       | 7.4 MB    | ########## | 100%
ipyevents-0.4.0      | 46 KB     | ########## | 100%
Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... WARNING conda.core.link:run_script(818): pre-unlink script failed for package conda-forge::ipyevents-0.3.1-py37_1000
consider notifying the package maintainer
done

Add link to documentation in README

ipyevents is really great. I think the widgets community could really benefit from using it.

It has great documentation, but finding it isn't completely obvious. Maybe we could add a link in the README to the docs/ directory?

Happy to implement this if you think it's a good idea.

Examples fail on binder and local. Script error for "ipyevents"

When I try to launch the examples on BinderHub or on may local computer, the examples do not work.

Looking at the JS Console, I see the following error:

manager-base.js:575 Error: Script error for "ipyevents"
http://requirejs.org/docs/errors.html#scripterror

Any ideas what is going wrong or how to fix it?

manager-base.js:575 Error: Script error for "ipyevents"
http://requirejs.org/docs/errors.html#scripterror
    at makeError (require.js?v=d37b48bb2137faa0ab98157e240c084dd5b1b5e74911723aa1d1f04c928c2a03dedf922d049e4815f7e5a369faa2e6b6a1000aae958b7953b5cc60411154f593:168:17)
    at HTMLScriptElement.onScriptError (require.js?v=d37b48bb2137faa0ab98157e240c084dd5b1b5e74911723aa1d1f04c928c2a03dedf922d049e4815f7e5a369faa2e6b6a1000aae958b7953b5cc60411154f593:1735:36)
loadModelClass @ manager-base.js:575
await in loadModelClass (async)
_make_model @ manager-base.js:402
new_model @ manager-base.js:245
handle_comm_open @ manager-base.js:155
(anonymous) @ comm.js:89
Promise.then (async)
CommManager.comm_open @ comm.js:85
i @ jquery.min.js:2
Kernel._handle_iopub_message @ kernel.js:1239
Kernel._finish_ws_message @ kernel.js:1018
(anonymous) @ kernel.js:1009
Promise.then (async)
Kernel._handle_ws_message @ kernel.js:1009
i @ jquery.min.js:2

Cannot use input widgets whilst listening to keyboard events

This might only apply to the FloatText/IntText, but I assume it might be a broader issue.

By calling preventDefault on the widget, we lose the ability to enter values into widgets.

ipyevents/src/events.ts

Lines 268 to 269 in b6a94c7

event.stopPropagation()
event.preventDefault()

Perhaps a solution here would be to enable a list of keycodes that are either ignored, or always blocked. I was thinking otherwise the Python event handler could veto the blocking, but that would add the roundtrip time to each event ๐Ÿคฎ

How to trigger an event?

Let's say we have the following code:

l = Label('Click or type on me!')
l.layout.border = '2px solid red'

h = HTML('Event info')
d = Event(source=l, watched_events=['click', 'keydown', 'mouseenter', 'touchmove'])

def handle_event(event):
    lines = ['{}: {}'.format(k, v) for k, v in event.items()]
    content = '<br>'.join(lines)
    h.value = content

d.on_dom_event(handle_event)
                            
display(l, h)

For test purposes, I would like to trigger the d event by interacting with the label l. How could I do something similar to l.click()?

package.json update needed for JupyterLab 3 compatibility, maybe

As per this Jupyter Discourse thread, I have been running into some funky issues with ipyevents on JupyterLab 3.

I don't feel that I understand this well at all, but I think what might be going on is simply that this project's package.json needs to be updated to indicate that it is also compatible with the 4.x series of @jupyter-widgets/base. @mwcraig if you agree with this diagnosis I'm happy to prepare a PR, but I wanted to post an issue first since you're a lot more familiar with this stuff than I am.

CC @matthewturk who expressed interest in this topic on Twitter.

Jupyter Lab: Throttling causes keyboard events to continue propagating

When an event monitor is set up on keyboard events, if it's throttled the event isn't stopped from propagating. That results in this code

from IPython.display import display
from ipycanvas import Canvas
from ipyevents import Event

canvas = Canvas(width=500, height=48)

canvas.font = "32px serif"
canvas.fill_style = "black"
mon = Event(source=canvas, watched_events=['keyup', 'keydown'], wait = 1000//30)

def handle_event(event):
    global canvas
    if event['type'] == "keydown":
        canvas.clear()
        canvas.fill_text(f"last_pressed: {event['key']}", 0, 32)

mon.on_dom_event(handle_event)

display(canvas)

scrolling the notebook when the up or down arrow keys are pressed.

plot window bug

Hey @mwcraig, logging the bug I came across during our JWST hackday. It's kind of hard to describe, but basically if I have an active clicked on cell in the notebook, and I then go mouse onto and off of a plot window, the notebook flashes back to the active cell.

The notebook I was working on can be found here: https://github.com/SaOgaz/dat_pyinthesky/blob/mos_notebook/jwst_nb_viz/mos/MOS_spec_xgal_fields.ipynb

Video clip of bug can be found here: https://stsci.box.com/s/9m7py2u4wrtqgop2jifbvzfpw859itxn

Including my whole conda list here, sorry for the cruft. Not sure what libraries are dependencies for this stuff.

My current versions of things are:
Name Version Build Channel
aggdraw 1.3.9
appnope 0.1.0 py37_0
astropy 3.1.1 py37h1de35cc_0
astrowidgets 0.1.0.dev104
atomicwrites 1.3.0 py_0
attrs 18.2.0 py37h28b3542_0
backcall 0.1.0 py37_0
blas 1.0 mkl
bleach 3.1.0 py37_0
bzip2 1.0.6 h1de35cc_5
ca-certificates 2019.1.23 0
cairo 1.14.12 hc4e6be7_4
certifi 2018.11.29 py37_0
cloudpickle 0.7.0 py_0
cycler 0.10.0 py37_0
cython 0.29.5 py37h0a44026_0
cytoolz 0.9.0.1 py37h1de35cc_1
dask-core 1.1.1 py_0
dbus 1.13.6 h90a0687_0
decorator 4.3.2 py37_0
entrypoints 0.3 py37_0
expat 2.2.6 h0a44026_0
ffmpeg 4.0 h01ea3c9_0
fontconfig 2.13.0 h5d5b041_1
freetype 2.9.1 hb4e5f40_0
gettext 0.19.8.1 h15daf44_3
ginga 2.7.2 py37_0 http://ssb.stsci.edu/astroconda
glib 2.56.2 hd9629dc_0
graphite2 1.3.13 h2098e52_0
harfbuzz 1.8.8 hb8d4a28_0
hdf5 1.10.2 hfa1e0ec_1
icu 58.2 h4b95b61_1
imageio 2.4.1 py37_0
imexam 0.8.1 py37_0 http://ssb.stsci.edu/astroconda
intel-openmp 2019.1 144
ipyevents 0.4.0
ipykernel 5.1.0 py37h39e3cac_0
ipython 7.2.0 py37h39e3cac_0
ipython_genutils 0.2.0 py37_0
ipywidgets 7.4.2 py37_0
jasper 2.0.14 h636a363_1
jedi 0.13.2 py37_0
jinja2 2.10 py37_0
jpeg 9b he5867d9_2
jsonschema 2.6.0 py37_0
jupyter 1.0.0 py37_7
jupyter_client 5.2.4 py37_0
jupyter_console 6.0.0 py37_0
jupyter_core 4.4.0 py37_0
kiwisolver 1.0.1 py37h0a44026_0
libcxx 4.0.1 hcfea43d_1
libcxxabi 4.0.1 hcfea43d_1
libedit 3.1.20181209 hb402a30_0
libffi 3.2.1 h475c297_4
libgfortran 3.0.1 h93005f0_2
libiconv 1.15 hdd342a3_7
libopencv 3.4.2 h7c891bd_1
libopus 1.3 h1de35cc_0
libpng 1.6.36 ha441bb4_0
libsodium 1.0.16 h3efe00b_0
libtiff 4.0.10 hcb84e12_2
libvpx 1.7.0 h378b8a2_0
libxml2 2.9.9 hab757c2_0
markupsafe 1.1.0 py37h1de35cc_0
matplotlib 3.0.2 py37h54f8f79_0
mistune 0.8.4 py37h1de35cc_0
mkl 2019.1 144
mkl_fft 1.0.10 py37h5e564d8_0
mkl_random 1.0.2 py37h27c97d8_0
more-itertools 5.0.0 py37_0
nbconvert 5.3.1 py37_0
nbformat 4.4.0 py37_0
ncurses 6.1 h0a44026_1
networkx 2.2 py37_1
notebook 5.7.4 py37_0
numpy 1.15.4 py37hacdab7b_0
numpy-base 1.15.4 py37h6575580_0
olefile 0.46 py37_0
opencv 3.4.2 py37h6fd60c2_1
openssl 1.1.1a h1de35cc_0
pandoc 2.2.3.2 0
pandocfilters 1.4.2 py37_1
parso 0.3.2 py37_0
pcre 8.42 h378b8a2_0
pexpect 4.6.0 py37_0
photutils 0.6 py37_0 http://ssb.stsci.edu/astroconda
pickleshare 0.7.5 py37_0
pillow 5.4.1 py37hb68e598_0
pip 19.0.1 py37_0
pixman 0.36.0 h1de35cc_0
pluggy 0.8.1 py37_0
prometheus_client 0.5.0 py37_0
prompt_toolkit 2.0.8 py_0
psutil 5.5.0 py37h1de35cc_0
ptyprocess 0.6.0 py37_0
py 1.7.0 py37_0
py-opencv 3.4.2 py37h7c891bd_1
pygments 2.3.1 py37_0
pyparsing 2.3.1 py37_0
pyqt 5.9.2 py37h655552a_2
pytest 4.2.1 py37_0
pytest-arraydiff 0.3 py37h39e3cac_0
pytest-astropy 0.5.0 py37_0
pytest-doctestplus 0.2.0 py37_0
pytest-openfiles 0.3.2 py37_0
pytest-remotedata 0.3.1 py37_0
python 3.7.2 haf84260_0
python-dateutil 2.7.5 py37_0
pytz 2018.9 py37_0
pywavelets 1.0.1 py37h1d22016_0
pyzmq 17.1.2 py37h0a44026_2
qt 5.9.7 h468cd18_1
qtconsole 4.4.3 py37_0
qtpy 1.6.0 py_0
readline 7.0 h1de35cc_5
scikit-image 0.14.1 py37h0a44026_0
scikit-learn 0.20.2 py37h27c97d8_0
scipy 1.2.0 py37h1410ff5_0
send2trash 1.5.0 py37_0
setuptools 40.8.0 py37_0
sip 4.19.8 py37h0a44026_0
six 1.12.0 py37_0
sqlite 3.26.0 ha441bb4_0
terminado 0.8.1 py37_1
testpath 0.4.2 py37_0
tk 8.6.8 ha441bb4_0
toolz 0.9.0 py37_0
tornado 5.1.1 py37h1de35cc_0
traitlets 4.3.2 py37_0
wcwidth 0.1.7 py37_0
webencodings 0.5.1 py37_1
wheel 0.32.3 py37_0
widgetsnbextension 3.4.2 py37_0
xz 5.2.4 h1de35cc_4
zeromq 4.3.1 h0a44026_3
zlib 1.2.11 h1de35cc_3
zstd 1.3.7 h5bba6e5_0

Installation of ipyevents.json creates spurious error message

https://github.com/mwcraig/ipyevents/blob/master/setup.py#L144

With ipyevents.json present in etc/jupyter/jupyter_notebook_config.d, Jupyter thinks ipyevents is installed as a serverextension, and it is not one.

[root@7781f13e5ddc tmp]# jupyter serverextension list
config dir: /usr/etc/jupyter
    jupyterlab  enabled
    - Validating...
      jupyterlab 0.35.4 OK
config dir: /usr/local/etc/jupyter
    ipyevents  enabled
    - Validating...
      X is ipyevents importable?
    jupyter_server_proxy  enabled
    - Validating...
      jupyter_server_proxy  OK
    jupyterlab  enabled
    - Validating...
      jupyterlab 0.35.4 OK
    nbdime  enabled
    - Validating...
      nbdime 1.0.4 OK
[root@7781f13e5ddc tmp]# mv /usr/local/etc/jupyter/jupyter_notebook_config.d/ipyevents.json /usr/local/etc/jupyter/jupyter_notebook_config.d/ipyevents.json.disable
[root@7781f13e5ddc tmp]# jupyter serverextension list
config dir: /usr/etc/jupyter
    jupyterlab  enabled
    - Validating...
      jupyterlab 0.35.4 OK
config dir: /usr/local/etc/jupyter
    jupyter_server_proxy  enabled
    - Validating...
      jupyter_server_proxy  OK
    jupyterlab  enabled
    - Validating...
      jupyterlab 0.35.4 OK
    nbdime  enabled
    - Validating...
      nbdime 1.0.4 OK

Can't enable x, y coordinate as a trait.

I get an AttributeError when I try to access the xy trait from no_drag.
This happened while following the demo notebook.

The full error is

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-75ef162e19fd> in <module>()
----> 1 no_drag.xy

AttributeError: 'Event' object has no attribute 'xy'

Optionally passing some events to browser

Is there are way we can propagate a keydown event to browser to do default action? For example, with Ctrl + P we can print page, but it doesn't work with ipyevents as expected.

Related to this is another option of dispatching a new event when a key is pressed, e.g. let say I press key Ctrl + P and it does not propagate to notebook/browser that is fine, but what if I can handle that by adding something like:

def handle_keydown(event):
    if event["ctrlKey"] and event["code"] == "p":
        ipyevents.propagate() # This is less flexible, 
        # OR
        ipyevents.dispatch_javascript_event("window.print();") # if such function exists, it is much more flexible      

This second way to dispatch events selectively looks better than just passing events to browser. I am looking specifically for window.dispatchEvent(new Event('resize')); on press of some key or some layout change of widgets.

Running ipyevents in Jupyter lab 2

Hello,
I'm trying to ipyevents in Jupyter Lab 2

When I try to do the example I get the following error in the javascript console:
Module ipyevents, semver range 1.8.0 is not registered as a widget module

Does anyone know what I could do to make it work?

Best,
Florian

Display of images seems to be handled differently in lab than not in lab

This is not really an ipyevents issue, I think, but wanted to note it somewhere. In the plain notebook, images are compressed/stretched to fit into the box in which they are placed. In jupyterlab the aspect ratio is preserved and scrollbars are added.

This does affect the documentation notebook...

Support for Mobile Browser

First off, great work here! This is working great for me on the desktop.

Is there any support for mobile browser DOM events? I'd be happy to contribute if you can point me in the right direction.

Up/down arrow key events captured by browser

UPDATE: I also see this on RHEL 7 64-bit using Firefox 52.8.0.

Discovered during Scipy 2018. While panning using Ginga viewer with ipyevents, the up/down arrows where somehow captured by the browser. This resulted in notebook jumping up and down, instead of panning up and down. I was running eteq/astrowidgets#1 on Windows 7 64-bit:

I think I see the image did pan like a few pixels but I am not sure because the browser was also unintentionally scrolling at the same time.

Reset an event

Hi! Thanks for the good work!
In order to suppress all callbacks for a given event, I find no better solution than:

my_click_event._dom_handlers.callbacks.clear()

Should we not benefit on a new method like for ex. Event.reset_callbacks to do that in a more sensible way?

Events not working with jupyterlab 1.0.0

Thanks for the really useful package and clean API.
I just tried to run the example in doc/Widget DOM Events.ipynb and it works fine on a jupyter notebook but does not work with jupyterlab 1.0.0. No events are captured on jupyterlab. This is with ipyevents 0.5.0 from conda-forge and Python 3.7.3. Thanks.

python setup.py build broken

If I try doing python setup.py build I get:

$ python setup.py build
setup.py entered
$PATH=/opt/local/bin:/opt/local/sbin:/Users/tom/.gem/ruby/2.0.0/bin:/Users/tom/.rvm/gems/ruby-2.3.0/bin:/Users/tom/.rvm/gems/ruby-2.3.0@global/bin:/Users/tom/.rvm/rubies/ruby-2.3.0/bin:/Applications/Julia-0.4.0.app/Contents/Resources/julia/bin:/Users/tom/miniconda3/envs/dev/bin:/Users/tom/miniconda3/bin:/Applications/git-annex.app/Contents/MacOS:/opt/local/bin:/opt/local/sbin:/usr/local/heroku/bin:/Users/tom/usr/Montage_v3.3/bin:/Users/tom/Library/Python/3.4/bin:/Users/tom/usr/hyperion/bin:/Users/tom/Dropbox/usr/bin:/Users/tom/usr/bin:/Users/tom/Library/Python/3.4/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/Users/tom/.rvm/bin:/usr/local/opt/go/libexec/bin:/Users/tom/.go/bin
Traceback (most recent call last):
  File "setup.py", line 125, in <module>
    exec(f.read(), {}, version_ns)
  File "<string>", line 9, in <module>
KeyError: 'dev'

JupyterLab keybinding issues

My hack of key events seems to fail miserably in jupyterlab. It works fine until you press a key that is also interpreted by the notebook (e.g. the 1 key which sets the cell type to Heading 1). Then the notebook executes the command (e.g. changing the cell type) and the handler which had been bound to the cell becomes bound to the document instead (I think).

Once in that state pushing a key anywhere in the notebook makes the handler react (which makes sense) and the default action for the key happens. Need to figure out a better way of attaching things in lab...

Even better, you cannot then type anywhere in the notebook because there is a document-level event handler that swallows the event...

Support for JupyterLab 2.0

JupyterLab has had a major version release (2.0) and unfortunately, it broke a lot of extensions, including ipyevents.

I think all it will take is to follow the instructions in the extension migration guide to make it work again.

How to obtain the coordinates of a click on the image when object_fit='contain'?

Hello maintainers and contributors of ipyevents ๐Ÿ‘‹


The context

I contribute to mne-python(opened issue) and I am working on integration into the Jupyter Notebook environment. The project has tight interactions between ipyevents, ipycanvas, ipyvtklink(opened issue) and ipywidgets, that's why I am not 100% sure it is the right place to open this issue but I will try to explain the unexpected behaviour I observe anyway.

Here is a demo of the final app in mne-python:

output.mp4

The issue

Let's assume an image contained in an HBox called viewer and a VBox called right_dock containing multiple widgets in an Accordion folded by default. Both viewer and right_dock are in turn contained into an HBox called app which is finally displayed:

image

I would like to get the coordinates of the click in image when the layout is set to image.layout.object_fit = 'contain' (useful to preserve the aspect ratio).

image

Unfortunately, I think ipyevents is not aware of object_fit because the coordinates that I observe in my experiments are the same as if the image was 'stretched' to fit its container.

output.mp4

Is there a way to obtain the real coordinates of a click on the image in this situation?


Minimum reproducible example

I share below a simplified example (inspired from the demo notebook):

from ipywidgets import Box, VBox, HBox, HTML, Image, Accordion
from ipyevents import Event

def gen_opts(n):
    return[HTML(f"option{i}") for i in range(n)]

with open('images/gaussian_600_x_300.png', 'rb') as f:
    value = f.read()

image = Image(value=value, format='png')
image.layout.object_fit = 'contain'
image.layout.border = '5px red solid'

right_dock = Accordion([VBox(gen_opts(15))])
right_dock.set_title(0, "Right dock")
right_dock.selected_index = None

im_events = Event()
im_events.source = image
im_events.watched_events = ['click']

viewer = HBox([image])
red_layout(image)

coordinates = HTML('<h3>Click an image to see the click coordinates here</h3>')
def update_coords(event):
    coordinates.value = '<h3>Clicked at ({}, {})</h3>'.format(event['dataX'], event['dataY'])
    
im_events.on_dom_event(update_coords)

row = HBox([viewer, right_dock])
app = VBox([row, coordinates])
app

cc @larsoner, @banesullivan

Decide whether to round or not

See discussion at jupyter-widgets/ipywidgets#1727 (comment)

Basically, right now it rounds because there is not subpixel resolution anyway. If the image is really enlarged, though, it might make sense not to round.

That scenario is detectable, I think, since we can get the "natural" size of an image and we know its display size, so we can work out the size of pixels on the screen.

Compatible with Jupyter Hub ?

We are using TLJH on our teaching stations for several students to access and run their notebooks. We have been using ipyevents <0.9 without issue on it, but it seems that version >2 doesn't run on it. Can you help us fix the compatibility issue? Is it that same as with Jupyter Lab <3?

Thank you.

Failed binder build

Hi,

Just to let you know I could not try out ipyevents on binder.

# [...]
Step 47/50 : RUN ./binder/postBuild
 ---> [Warning] Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.
 ---> Running in 52809131dd56
Enabling notebook extension ipyevents/extension...
      - Validating: OK
Node v14.15.4

> /usr/bin/npm pack @jupyter-widgets/jupyterlab-manager
# [...]
ValueError: "@jupyter-widgets/jupyterlab-manager" is not a valid extension:
schemaDir is empty: "./schema"

I tried twice, just in case - same outcome.

Thanks

Mousemove events not emitted after shift+mousedown with button 1 in Jupyter Lab

I'm trying to allow the user to "draw" a line across a widget, and have the shift key have special meaning. I check mousemove events with button 1 depressed to do regular drawing, but for shift+draw, no events are emitted by ipyevents.

The following code has been modified from the example notebook.

from ipywidgets import Label, HTML, HBox, Image, VBox, Box, HBox
from ipyevents import Event 
from IPython.display import display

l = Label('Move the mouse across me!')
l.layout.border = '2px solid red'

h = HTML('Event info')
d = Event(source=l, watched_events=['mousemove'])

def handle_event(event):
    lines = ['{}: {}'.format(k, v) for k, v in event.items()]
    content = '<br>'.join(lines)
    h.value = content

d.on_dom_event(handle_event)
                            
display(l, h)

In Jupyter Lab,

  • Mouse moves with no buttons depressed are displayed.
  • Mouse moves with mouse button 1 depressed are displayed.
  • Mouse moves with the shift key depressed are displayed.
  • Mouse moves with shift and button 1 depressed, where shift went down before button 1, are not displayed. Releasing the shift key while leaving the mouse button down does not make mouse moves visible.
  • Mouse moves with shift and button 1 depressed, where the mouse button went down before shift are displayed.
  • Mouse moves with mouse button 2 depressed are displayed irrespective of the shift key.

In Jupyter Notebook, all events I just listed are displayed appropriately. Adding prevent_default_action=True had no effect.

!jupyter --version

produces

Selected Jupyter core packages...
IPython          : 8.3.0
ipykernel        : 6.13.0
ipywidgets       : 7.7.0
jupyter_client   : 7.3.1
jupyter_core     : 4.10.0
jupyter_server   : 1.17.0
jupyterlab       : 3.5.0b0
nbclient         : 0.6.3
nbconvert        : 6.5.0
nbformat         : 5.4.0
notebook         : 6.4.11
qtconsole        : 5.3.0
traitlets        : 5.2.1.post0

and

import ipyevents
ipyevents.__version__

produces

'2.0.1'

I upgraded from JupyterLab 3.4.0 to make this report; I got identical behavior in both versions.

[IPKernelApp] WARNING | No such comm: 606159...

Hi, I've noticed strange behavior of ipyevents:

Code capturing mouse scroll event(wheel > movementY ) works flawlessly on mac, but raises error on linux.

# triggered function when mouse wheel event happens
def handle_event(event):
    # how many steps on mouse scroll is detected
    steps=int(event['movementY'])
    # updated X chart calling layout_scroll_zoom function
    f1.layout.xaxis.range=layout_scroll_zoom(steps)

# listening to mouse wheel events
Event(source=f1, watched_events=['wheel']).on_dom_event(handle_event)

Drag mouse event works on both platform flawlessly. Since one event is detected correctly and other is not, I do not know where to start looking for potential problem.

Thank you for anyone who takes a look into it. You rock! ;)

ipyevents not enabled by default when installing from pip

I just tried installing ipyevents 0.3.2 with pip, and it looks like the extension doesn't appear by default when looking at jupyter nbextension list. However, it looks like you are using a reasonably recent template for the package and setup.py, so I'm not sure why that is?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.