Skip to content

Commit 1ab9a4d

Browse files
committed
Replace on_click with on_mouse_down, update documentation
1 parent f2da812 commit 1ab9a4d

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

docs/source/events.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Interactions
44
Using built-in events
55
---------------------
66

7-
There are currently two built-in mouse events: ``click`` and ``mouse_move``.
7+
The following built-in mouse events are supported: ``mouse_down``, ``mouse_move``, ``mouse_up`` and ``mouse_out``.
88

99
.. code:: Python
1010
@@ -14,11 +14,11 @@ There are currently two built-in mouse events: ``click`` and ``mouse_move``.
1414
1515
canvas.on_mouse_move(handle_mouse_move)
1616
17-
def handle_click(x, y):
17+
def handle_mouse_down(x, y):
1818
# Do something else
1919
pass
2020
21-
canvas.on_click(handle_click)
21+
canvas.on_mouse_down(handle_mouse_down)
2222
2323
.. note::
2424
Please open an issue or a Pull Request if you want more events to be supported by ipycanvas

examples/plotting.ipynb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@
132132
" self.canvas[2].on_mouse_down(self.mouse_down_handler)\n",
133133
" self.canvas[2].on_mouse_move(self.mouse_move_handler)\n",
134134
" self.canvas[2].on_mouse_up(self.mouse_up_handler)\n",
135-
" \n",
135+
"\n",
136+
" def _ipython_display_(self):\n",
137+
" display(self.canvas)\n",
138+
"\n",
136139
" def show(self):\n",
137140
" with hold_canvas(self.canvas):\n",
138141
" self.canvas.clear()\n",
@@ -170,7 +173,7 @@
170173
" break\n",
171174
" \n",
172175
" def mouse_move_handler(self, pixel_x, pixel_y):\n",
173-
" if (self.dragging):\n",
176+
" if self.dragging:\n",
174177
" unscaled_x = self.unscale_x(pixel_x)\n",
175178
" unscaled_y = self.unscale_y(pixel_y)\n",
176179
" self.x[self.i_mark] = unscaled_x\n",
@@ -297,7 +300,7 @@
297300
"sizes = np.random.randint(2, 8, n_points)\n",
298301
"colors = np.random.rand(n_points) * 10 - 2\n",
299302
"\n",
300-
"plot = Scatter_plot(x, y, sizes, colors, branca.colormap.linear.viridis, stroke_color='white').canvas\n",
303+
"plot = Scatter_plot(x, y, sizes, colors, branca.colormap.linear.viridis, stroke_color='white')\n",
301304
"plot"
302305
]
303306
},

ipycanvas/canvas.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ class Canvas(DOMWidget):
112112
_mouse_down_callbacks = Instance(CallbackDispatcher, ())
113113
_mouse_up_callbacks = Instance(CallbackDispatcher, ())
114114
_mouse_out_callbacks = Instance(CallbackDispatcher, ())
115-
_click_callbacks = Instance(CallbackDispatcher, ())
116115

117116
def __init__(self, *args, **kwargs):
118117
"""Create a Canvas widget."""
@@ -460,10 +459,6 @@ def on_mouse_out(self, callback, remove=False):
460459
"""Register a callback that will be called on mouse mouse_out."""
461460
self._mouse_out_callbacks.register_callback(callback, remove=remove)
462461

463-
def on_click(self, callback, remove=False):
464-
"""Register a callback that will be called on mouse click."""
465-
self._click_callbacks.register_callback(callback, remove=remove)
466-
467462
def __setattr__(self, name, value):
468463
super(Canvas, self).__setattr__(name, value)
469464

@@ -500,7 +495,6 @@ def _handle_frontend_event(self, _, content, buffers):
500495
if content.get('event', '') == 'mouse_move':
501496
self._mouse_move_callbacks(content['x'], content['y'])
502497
if content.get('event', '') == 'mouse_down':
503-
self._click_callbacks(content['x'], content['y'])
504498
self._mouse_down_callbacks(content['x'], content['y'])
505499
if content.get('event', '') == 'mouse_up':
506500
self._mouse_up_callbacks(content['x'], content['y'])

src/widget.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ class CanvasView extends DOMWidgetView {
320320
}
321321

322322
private onMouseDown(event: MouseEvent) {
323-
this.model.send({ event: 'click', ...this.getMouseCoordinate(event) }, {});
324323
this.model.send({ event: 'mouse_down', ...this.getMouseCoordinate(event) }, {});
325324
}
326325

0 commit comments

Comments
 (0)