|
| 1 | +# Jupyter Clickable Image Widget |
1 | 2 |
|
2 |
| -# jupyter_clickable_image_widget |
| 3 | +This repository contains an image widget (much like the ipywidgets.Image), but will send messages when the image is clicked. |
3 | 4 |
|
4 |
| -[](https://travis-ci.org/jaybdub/jupyter_clickable_image_widget) |
5 |
| -[](https://codecov.io/gh/jaybdub/jupyter_clickable_image_widget) |
| 5 | +# Setup |
6 | 6 |
|
7 |
| - |
8 |
| -A clickable image widget for Jupyter. |
9 |
| - |
10 |
| -## Installation |
11 |
| - |
12 |
| -You can install using `pip`: |
| 7 | +To install the widget type the following in a terminal |
13 | 8 |
|
14 | 9 | ```bash
|
15 |
| -pip install jupyter_clickable_image_widget |
| 10 | +sudo npm install -g typescript |
| 11 | +git clone https://github.com/jaybdub/jupyter_clickable_image_widget |
| 12 | +cd jupyter_clickable_image_widget |
| 13 | +sudo python3 setup.py build |
| 14 | +sudo npm run build |
| 15 | +sudo pip3 install . |
| 16 | +sudo jupyter labextension install . |
| 17 | +sudo jupyter labextension install @jupyter-widgets/jupyterlab-manager |
16 | 18 | ```
|
17 | 19 |
|
18 |
| -Or if you use jupyterlab: |
| 20 | +# Usage |
19 | 21 |
|
20 |
| -```bash |
21 |
| -pip install jupyter_clickable_image_widget |
22 |
| -jupyter labextension install @jupyter-widgets/jupyterlab-manager |
23 |
| -``` |
| 22 | +```python |
| 23 | +from jupyter_clickable_image_widget import ClickableImageWidget |
24 | 24 |
|
25 |
| -If you are using Jupyter Notebook 5.2 or earlier, you may also need to enable |
26 |
| -the nbextension: |
27 |
| -```bash |
28 |
| -jupyter nbextension enable --py [--sys-prefix|--user|--system] jupyter_clickable_image_widget |
| 25 | + |
| 26 | +image_widget = ClickableImageWidget() |
| 27 | + |
| 28 | +def on_message(_, content, _): |
| 29 | + if content['event'] == 'click': |
| 30 | + data = content['eventData'] |
| 31 | + alt_key = data['altKey'] |
| 32 | + ctrl_key = data['ctrlKey'] |
| 33 | + shift_key = data['shiftKey'] |
| 34 | + x = data['offsetX'] |
| 35 | + y = data['offsetY'] |
| 36 | + |
| 37 | + # do something... |
| 38 | + |
| 39 | +image_widget.on_msg(on_message) |
29 | 40 | ```
|
0 commit comments