@@ -69,6 +69,8 @@ class BaseAnyWidget(anywidget.AnyWidget):
6969 _data_handlers : typing .ClassVar [dict ] = {}
7070 _event_handlers : typing .ClassVar [dict ] = {}
7171
72+ _binary_trait_to_js_names : typing .ClassVar [dict ] = {}
73+
7274 def __init__ (self , * args , ** kwargs ):
7375 super ().__init__ (* args , ** kwargs )
7476 self ._setup_binary_change_handlers ()
@@ -80,7 +82,8 @@ def set_state(self, state):
8082
8183 for attr_name , attr_value in state .items ():
8284 if attr_name .startswith ("chunk_" ):
83- _ , data_property , chunk_index = attr_name .split ("_" )
85+ base , chunk_index = attr_name .rsplit ("_" , 1 )
86+ data_property = base [6 :]
8487 chunk_index = int (chunk_index )
8588 chunk_info = attr_value
8689 chunk_index_received = chunk_info ["chunk_index" ]
@@ -122,8 +125,12 @@ def _setup_binary_change_handlers(self):
122125 def _get_binary_traits (self ):
123126 return []
124127
128+ def _get_js_name (self , trait_name ):
129+ """Get the JavaScript attribute name for a trait."""
130+ return self ._binary_trait_to_js_names .get (trait_name , trait_name )
131+
125132 def _handle_binary_trait_change (self , change ):
126- trait_name = change ["name" ]
133+ trait_name = self . _get_js_name ( change ["name" ])
127134 old_value = change ["old" ]
128135 new_value = change ["new" ]
129136 if old_value is not None :
@@ -802,6 +809,8 @@ class NiiVue(BaseAnyWidget):
802809
803810 _esm = pathlib .Path (__file__ ).parent / "static" / "widget.js"
804811
812+ _binary_trait_to_js_names : typing .ClassVar [dict ] = {"draw_bitmap" : "drawBitmap" }
813+
805814 height = t .Int ().tag (sync = True )
806815 opts = t .Instance (ConfigOptions ).tag (
807816 sync = True , to_json = serialize_options , from_json = deserialize_options
@@ -847,6 +856,10 @@ class NiiVue(BaseAnyWidget):
847856 sync = False
848857 )
849858
859+ draw_bitmap = t .Instance (np .ndarray , allow_none = True ).tag (
860+ sync = True , to_json = serialize_ndarray
861+ )
862+
850863 @t .validate ("other_nv" )
851864 def _validate_other_nv (self , proposal ):
852865 value = proposal ["value" ]
@@ -904,6 +917,9 @@ def __init__(self, height: int = 300, **options): # noqa: D417
904917 self ._event_handlers = {}
905918 self .on_msg (self ._handle_custom_msg )
906919
920+ def _get_binary_traits (self ):
921+ return ["draw_bitmap" ]
922+
907923 def set_state (self , state ):
908924 """Override set_state to silence notifications for certain updates."""
909925 if "scene" in state :
0 commit comments