@@ -301,6 +301,11 @@ def __init__(self, nb, km=None, **kw):
301
301
self .nb = nb
302
302
self .km = km
303
303
self .reset_execution_trackers ()
304
+ self .widget_registry = {
305
+ '@jupyter-widgets/output' : {
306
+ 'OutputModel' : OutputWidget
307
+ }
308
+ }
304
309
305
310
def reset_execution_trackers (self ):
306
311
"""Resets any per-execution trackers.
@@ -313,7 +318,7 @@ def reset_execution_trackers(self):
313
318
# to support nested use of output widgets.
314
319
self .output_hook_stack = collections .defaultdict (list )
315
320
# our front-end mimicing Output widgets
316
- self .output_widget_objects = {}
321
+ self .widget_objects = {}
317
322
318
323
def start_kernel_manager (self ):
319
324
"""Creates a new kernel manager.
@@ -863,17 +868,18 @@ def handle_comm_msg(self, outs, msg, cell_index):
863
868
data = content ['data' ]
864
869
state = data ['state' ]
865
870
comm_id = msg ['content' ]['comm_id' ]
866
- if state ['_model_module' ] == '@jupyter-widgets/output' and \
867
- state ['_model_name' ] == 'OutputModel' :
868
- self .output_widget_objects [comm_id ] = OutputWidget (comm_id , state , self .kc , self )
871
+ module = self .widget_registry .get (state ['_model_module' ])
872
+ if module :
873
+ widget_class = module .get (state ['_model_name' ])
874
+ self .widget_objects [comm_id ] = widget_class (comm_id , state , self .kc , self )
869
875
elif msg ['msg_type' ] == 'comm_msg' :
870
876
content = msg ['content' ]
871
877
data = content ['data' ]
872
878
if 'state' in data :
873
879
state = data ['state' ]
874
880
comm_id = msg ['content' ]['comm_id' ]
875
- if comm_id in self .output_widget_objects :
876
- self .output_widget_objects [comm_id ].set_state (state )
881
+ if comm_id in self .widget_objects :
882
+ self .widget_objects [comm_id ].set_state (state )
877
883
878
884
def _serialize_widget_state (self , state ):
879
885
"""Serialize a widget state, following format in @jupyter-widgets/schema."""
0 commit comments