44from ._frontend import module_name , module_version
55import json
66
7- from ..graphics import CanvasSelection , canvas_selection , DispatchEvent , ReceiveEvent
7+ from .JupyterCanvas import JupyterCanvas
8+ from ..graphics import CanvasSelection , canvas_selection , EventHandler , DispatchEvent , ReceiveEvent
89
9-
10- class JupyterWidget (DOMWidget ):
11- _model_name = Unicode ('CanvasModel' ).tag (sync = True )
10+ class JupyterClient (DOMWidget , EventHandler ):
11+ _model_name = Unicode ('AlgorithmxModel' ).tag (sync = True )
1212 _model_module = Unicode (module_name ).tag (sync = True )
1313 _model_module_version = Unicode (module_version ).tag (sync = True )
14- _view_name = Unicode ('CanvasView ' ).tag (sync = True )
14+ _view_name = Unicode ('AlgorithmxView ' ).tag (sync = True )
1515 _view_module = Unicode (module_name ).tag (sync = True )
1616 _view_module_version = Unicode (module_version ).tag (sync = True )
1717
18- _dispatch_events : SyncList = SyncList (Unicode , []).tag (sync = True )
19- _show_buttons : SyncBool = SyncBool (False ).tag (sync = True )
20-
2118 _subscriptions : List [Callable [[ReceiveEvent ], Any ]]
2219
20+ events : SyncList = SyncList (Unicode , []).tag (sync = True )
21+ show_buttons : SyncBool = SyncBool (False ).tag (sync = True )
22+
2323 def __init__ (self , ** kwargs ):
2424 super ().__init__ (** kwargs )
2525
2626 self ._subscriptions = []
2727 if 'buttons' in kwargs :
28- self ._show_buttons = kwargs ['buttons' ]
28+ self .show_buttons = kwargs ['buttons' ]
2929
3030 def on_msg (widget , content , buffers ):
3131 event = json .loads (content )
@@ -38,17 +38,10 @@ def on_msg(widget, content, buffers):
3838
3939 def dispatch (self , event : DispatchEvent ):
4040 str_event = json .dumps (event )
41- self ._dispatch_events = self ._dispatch_events + [str_event ]
41+ self .events = self .events + [str_event ]
4242
4343 def subscribe (self , listener : Callable [[ReceiveEvent ], Any ]):
4444 self ._subscriptions .append (listener )
4545
46- def canvas (self ) -> CanvasSelection :
47- """
48- Creates a new :class:`~graphics.CanvasSelection` which will dispatch and receive events through the Jupyter
49- widget. The default canvas size is (400, 250).
50-
51- Note that by default, you need to hold down the ``ctrl``/``cmd`` key to zoom in
52- (see :meth:`~graphics.CanvasSelection.zoomkey`).
53- """
54- return canvas_selection ('_jupyter' , self )
46+ def canvas (self ) -> JupyterCanvas :
47+ return canvas_selection ('_jupyter' , self , JupyterCanvas )
0 commit comments