Skip to content

Commit 2df4ebe

Browse files
authored
Merge pull request #247 from martinRenou/update_multicanvas_events
Fix MultiCanvas events
2 parents 117a932 + ab1ca12 commit 2df4ebe

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

ipycanvas/canvas.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ def __getattr__(self, name):
15921592
if name in ("caching", "width", "height"):
15931593
return getattr(self._canvases[0], name)
15941594

1595-
return super(MultiCanvas, self).__getattr__(name)
1595+
raise AttributeError(f"'MultiCanvas' object has no attribute '{name}'")
15961596

15971597
def on_client_ready(self, callback, remove=False):
15981598
"""Register a callback that will be called when a new client is ready to receive draw commands.
@@ -1602,9 +1602,39 @@ def on_client_ready(self, callback, remove=False):
16021602
this function is useful for replaying your drawing whenever a new client connects and is
16031603
ready to receive draw commands.
16041604
"""
1605-
self._canvases[-1]._client_ready_callbacks.register_callback(
1606-
callback, remove=remove
1607-
)
1605+
self._canvases[-1].on_client_ready(callback, remove=remove)
1606+
1607+
def on_mouse_move(self, callback, remove=False):
1608+
"""Register a callback that will be called on mouse move."""
1609+
self._canvases[-1].on_mouse_move(callback, remove=remove)
1610+
1611+
def on_mouse_down(self, callback, remove=False):
1612+
"""Register a callback that will be called on mouse click down."""
1613+
self._canvases[-1].on_mouse_down(callback, remove=remove)
1614+
1615+
def on_mouse_up(self, callback, remove=False):
1616+
"""Register a callback that will be called on mouse click up."""
1617+
self._canvases[-1].on_mouse_up(callback, remove=remove)
1618+
1619+
def on_mouse_out(self, callback, remove=False):
1620+
"""Register a callback that will be called on mouse out of the canvas."""
1621+
self._canvases[-1].on_mouse_out(callback, remove=remove)
1622+
1623+
def on_touch_start(self, callback, remove=False):
1624+
"""Register a callback that will be called on touch start (new finger on the screen)."""
1625+
self._canvases[-1].on_touch_start(callback, remove=remove)
1626+
1627+
def on_touch_end(self, callback, remove=False):
1628+
"""Register a callback that will be called on touch end (a finger is not touching the screen anymore)."""
1629+
self._canvases[-1].on_touch_end(callback, remove=remove)
1630+
1631+
def on_touch_move(self, callback, remove=False):
1632+
"""Register a callback that will be called on touch move (finger moving on the screen)."""
1633+
self._canvases[-1].on_touch_move(callback, remove=remove)
1634+
1635+
def on_touch_cancel(self, callback, remove=False):
1636+
"""Register a callback that will be called on touch cancel."""
1637+
self._canvases[-1].on_touch_cancel(callback, remove=remove)
16081638

16091639
def clear(self):
16101640
"""Clear the Canvas."""

0 commit comments

Comments
 (0)