@@ -337,10 +337,10 @@ class NiiVue(anywidget.AnyWidget):
337337 opts = t .Instance (ConfigOptions ).tag (
338338 sync = True , to_json = serialize_options , from_json = deserialize_options
339339 )
340- _volumes = t .List (t .Instance (Volume ), default_value = []).tag (
340+ volumes = t .List (t .Instance (Volume ), default_value = []).tag (
341341 sync = True , ** ipywidgets .widget_serialization
342342 )
343- _meshes = t .List (t .Instance (Mesh ), default_value = []).tag (
343+ meshes = t .List (t .Instance (Mesh ), default_value = []).tag (
344344 sync = True , ** ipywidgets .widget_serialization
345345 )
346346
@@ -378,7 +378,7 @@ def __init__(self, height: int = 300, **options): # noqa: D417
378378 """
379379 # convert to JS camelCase options
380380 opts = ConfigOptions (parent = self , ** options )
381- super ().__init__ (height = height , opts = opts , _volumes = [], _meshes = [])
381+ super ().__init__ (height = height , opts = opts , volumes = [], meshes = [])
382382
383383 # handle messages coming from frontend
384384 self ._event_handlers = {}
@@ -441,17 +441,17 @@ def _handle_custom_msg(self, content, buffers):
441441 elif event == "frame_change" :
442442 idx = self .get_volume_index_by_id (data ["id" ])
443443 if idx != - 1 :
444- handler (self ._volumes [idx ], data ["frame_index" ])
444+ handler (self .volumes [idx ], data ["frame_index" ])
445445 elif event in {"image_loaded" , "intensity_change" }:
446446 idx = self .get_volume_index_by_id (data ["id" ])
447447 if idx != - 1 :
448- handler (self ._volumes [idx ])
448+ handler (self .volumes [idx ])
449449 else :
450450 handler (data )
451451 elif event == "mesh_loaded" :
452452 idx = self .get_mesh_index_by_id (data ["id" ])
453453 if idx != - 1 :
454- handler (self ._meshes [idx ])
454+ handler (self .meshes [idx ])
455455 else :
456456 handler (data )
457457 elif event == "mesh_added_from_url" :
@@ -466,20 +466,20 @@ def _handle_custom_msg(self, content, buffers):
466466 def _add_volume_from_frontend (self , volume_data ):
467467 index = volume_data .pop ("index" , None )
468468 volume = Volume (** volume_data )
469- if index is not None and 0 <= index <= len (self ._volumes ):
470- self ._volumes = [* self ._volumes [:index ], volume , * self ._volumes [index :]]
469+ if index is not None and 0 <= index <= len (self .volumes ):
470+ self .volumes = [* self .volumes [:index ], volume , * self .volumes [index :]]
471471 else :
472- self ._volumes = [* self ._volumes , volume ]
472+ self .volumes = [* self .volumes , volume ]
473473
474474 def _add_mesh_from_frontend (self , mesh_data ):
475475 index = mesh_data .pop ("index" , None )
476476 layers_data = mesh_data .pop ("layers" , [])
477477 mesh = Mesh (** mesh_data )
478478 mesh .layers = [MeshLayer (** layer_data ) for layer_data in layers_data ]
479- if index is not None and 0 <= index <= len (self ._meshes ):
480- self ._meshes = [* self ._meshes [:index ], mesh , * self ._meshes [index :]]
479+ if index is not None and 0 <= index <= len (self .meshes ):
480+ self .meshes = [* self .meshes [:index ], mesh , * self .meshes [index :]]
481481 else :
482- self ._meshes = [* self ._meshes , mesh ]
482+ self .meshes = [* self .meshes , mesh ]
483483
484484 def close (self ):
485485 """
@@ -506,7 +506,7 @@ def get_volume_index_by_id(self, volume_id: str) -> int:
506506 volume_id : str
507507 The id of the volume.
508508 """
509- for idx , vol in enumerate (self ._volumes ):
509+ for idx , vol in enumerate (self .volumes ):
510510 if vol .id == volume_id :
511511 return idx
512512 return - 1
@@ -519,7 +519,7 @@ def get_mesh_index_by_id(self, mesh_id: str) -> int:
519519 mesh_id : str
520520 The id of the mesh.
521521 """
522- for idx , mesh in enumerate (self ._meshes ):
522+ for idx , mesh in enumerate (self .meshes ):
523523 if mesh .id == mesh_id :
524524 return idx
525525 return - 1
@@ -546,7 +546,7 @@ def load_volumes(self, volumes: list):
546546
547547 """
548548 volumes = [Volume (** item ) for item in volumes ]
549- self ._volumes = volumes
549+ self .volumes = volumes
550550
551551 def add_volume (self , volume : dict ):
552552 """
@@ -569,26 +569,7 @@ def add_volume(self, volume: dict):
569569 nv.add_volume({"path": "mni152.nii.gz"})
570570
571571 """
572- self ._volumes = [* self ._volumes , Volume (** volume )]
573-
574- @property
575- def volumes (self ):
576- """
577- Returns the list of volumes.
578-
579- Returns
580- -------
581- list
582- A list of dictionairies containing the volume information.
583-
584- Examples
585- --------
586- ::
587-
588- print(nv.volumes)
589-
590- """
591- return list (self ._volumes )
572+ self .volumes = [* self .volumes , Volume (** volume )]
592573
593574 def load_meshes (self , meshes : list ):
594575 """
@@ -612,7 +593,7 @@ def load_meshes(self, meshes: list):
612593
613594 """
614595 meshes = [Mesh (** item ) for item in meshes ]
615- self ._meshes = meshes
596+ self .meshes = meshes
616597
617598 def add_mesh (self , mesh : Mesh ):
618599 """
@@ -635,26 +616,7 @@ def add_mesh(self, mesh: Mesh):
635616 nv.add_mesh({"path": "BrainMesh_ICBM152.lh.mz3"})
636617
637618 """
638- self ._meshes = [* self ._meshes , mesh ]
639-
640- @property
641- def meshes (self ):
642- """
643- Returns the list of meshes.
644-
645- Returns
646- -------
647- list
648- A list of dictionairies containing the mesh information.
649-
650- Examples
651- --------
652- ::
653-
654- print(nv.meshes)
655-
656- """
657- return list (self ._meshes )
619+ self .meshes = [* self .meshes , mesh ]
658620
659621 """
660622 Other functions
@@ -804,7 +766,7 @@ def set_mesh_property(self, mesh_id: str, attribute: str, value: typing.Any):
804766 if idx == - 1 :
805767 raise ValueError (f"Mesh with id '{ mesh_id } ' not found." )
806768
807- mesh = self ._meshes [idx ]
769+ mesh = self .meshes [idx ]
808770 setattr (mesh , attribute , value )
809771
810772 def set_mesh_layer_property (
@@ -854,7 +816,7 @@ def set_mesh_layer_property(
854816 if idx == - 1 :
855817 raise ValueError (f"Mesh with id '{ mesh_id } ' not found." )
856818
857- mesh = self ._meshes [idx ]
819+ mesh = self .meshes [idx ]
858820 if layer_index < 0 or layer_index >= len (mesh .layers ):
859821 raise IndexError (f"Layer index { layer_index } out of range." )
860822
@@ -955,7 +917,7 @@ def set_colormap(self, imageID: str, colormap: str):
955917 """
956918 idx = self .get_volume_index_by_id (imageID )
957919 if idx != - 1 :
958- self ._volumes [idx ].colormap = colormap
920+ self .volumes [idx ].colormap = colormap
959921 else :
960922 raise ValueError (f"Volume with ID '{ imageID } ' not found" )
961923
0 commit comments