@@ -28,44 +28,19 @@ class ViewerRPC:
28
28
"""Viewer remote procedure interface."""
29
29
30
30
def __init__ (
31
- self , ui_collapsed = True , rotate = False , ui = "pydata-sphinx" , ** add_data_kwargs
31
+ self , ui_collapsed = True , rotate = False , ui = "pydata-sphinx" , data = None
32
32
):
33
33
"""Create a viewer."""
34
34
self ._init_viewer_kwargs = dict (ui_collapsed = ui_collapsed , rotate = rotate , ui = ui )
35
- self ._init_viewer_kwargs .update (** add_data_kwargs )
36
- self .init_data = {}
35
+ self .init_data = data
37
36
self .img = display (HTML (f'<div />' ), display_id = str (uuid .uuid4 ()))
38
37
self .wid = None
39
38
if ENVIRONMENT is not Env .JUPYTERLITE :
40
39
self .viewer_event = threading .Event ()
41
40
self .data_event = threading .Event ()
42
41
43
- def _get_input_data (self ):
44
- input_options = ["data" , "image" , "label_image" , "point_sets" ]
45
- inputs = []
46
- for option in input_options :
47
- data = self ._init_viewer_kwargs .get (option , None )
48
- if data is not None :
49
- inputs .append ((option , data ))
50
- return inputs
51
-
52
- def setup (self ):
53
- self .init_data .clear ()
54
- input_data = self ._get_input_data ()
55
- result = None
56
- for (input_type , data ) in input_data :
57
- render_type = _detect_render_type (data , input_type )
58
- key = init_key_aliases ()[input_type ]
59
- if render_type is RenderType .IMAGE :
60
- if input_type == 'label_image' :
61
- result = _get_viewer_image (data , label = True )
62
- else :
63
- result = _get_viewer_image (data , label = False )
64
- elif render_type is RenderType .POINT_SET :
65
- result = _get_viewer_point_sets (data )
66
- if result is None :
67
- result = data
68
- self .init_data [key ] = result
42
+ async def setup (self ):
43
+ pass
69
44
70
45
async def run (self , ctx ):
71
46
"""ImJoy plugin setup function."""
@@ -157,9 +132,11 @@ class Viewer:
157
132
def __init__ (
158
133
self , ui_collapsed = True , rotate = False , ui = "pydata-sphinx" , ** add_data_kwargs
159
134
):
135
+ input_data = self .input_data (add_data_kwargs )
136
+ data = self .init_data (input_data )
160
137
"""Create a viewer."""
161
138
self .viewer_rpc = ViewerRPC (
162
- ui_collapsed = ui_collapsed , rotate = rotate , ui = ui , ** add_data_kwargs
139
+ ui_collapsed = ui_collapsed , rotate = rotate , ui = ui , data = data
163
140
)
164
141
if ENVIRONMENT is not Env .JUPYTERLITE :
165
142
self .bg_jobs = bg .BackgroundJobManager ()
@@ -176,6 +153,33 @@ def loop(self):
176
153
def has_viewer (self ):
177
154
return hasattr (self .viewer_rpc , 'itk_viewer' )
178
155
156
+ def input_data (self , init_data_kwargs ):
157
+ input_options = ["data" , "image" , "label_image" , "point_sets" ]
158
+ inputs = []
159
+ for option in input_options :
160
+ data = init_data_kwargs .get (option , None )
161
+ if data is not None :
162
+ inputs .append ((option , data ))
163
+ return inputs
164
+
165
+ def init_data (self , input_data ):
166
+ _init_data = {}
167
+ result = None
168
+ for (input_type , data ) in input_data :
169
+ render_type = _detect_render_type (data , input_type )
170
+ key = init_key_aliases ()[input_type ]
171
+ if render_type is RenderType .IMAGE :
172
+ if input_type == 'label_image' :
173
+ result = _get_viewer_image (data , label = True )
174
+ else :
175
+ result = _get_viewer_image (data , label = False )
176
+ elif render_type is RenderType .POINT_SET :
177
+ result = _get_viewer_point_sets (data )
178
+ if result is None :
179
+ raise RuntimeError (f"Could not process the viewer { input_type } " )
180
+ _init_data [key ] = result
181
+ return _init_data
182
+
179
183
async def run_queued_requests (self ):
180
184
def _run_queued_requests (queue ):
181
185
method_name , args , kwargs = queue .get ()
0 commit comments