Skip to content

Commit

Permalink
Do not use CellWatcher outside of notebook env
Browse files Browse the repository at this point in the history
Signed-off-by: Brianna Major <[email protected]>
  • Loading branch information
bnmajor committed Dec 29, 2023
1 parent d20b17b commit ac60a45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion itkwidgets/standalone_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def standalone_viewer(url):

def input_dict(viewer_options):
user_input = read_files(viewer_options)
data = build_init_data(user_input)
data = build_init_data(user_input, {})
ui = user_input.get("ui", "reference")
data["config"] = build_config(ui)

Expand Down
22 changes: 13 additions & 9 deletions itkwidgets/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@

_viewer_count = 1
_codecs_registered = False
CellWatcher() # Instantiate the singleton class right away
if ENVIRONMENT is not Env.HYPHA:
CellWatcher() # Instantiate the singleton class right away


class ViewerRPC:
Expand All @@ -63,11 +64,10 @@ def __init__(
self.img = display(HTML(f'<div />'), display_id=str(uuid.uuid4()))
self.wid = None
self.parent = parent
if ENVIRONMENT is not Env.JUPYTERLITE:
if ENVIRONMENT is not Env.JUPYTERLITE and ENVIRONMENT is not Env.HYPHA:
CellWatcher().add_viewer(self.parent)
if ENVIRONMENT is not Env.HYPHA:
self.viewer_event = threading.Event()
self.data_event = threading.Event()
self.viewer_event = threading.Event()
self.data_event = threading.Event()

async def setup(self):
pass
Expand Down Expand Up @@ -146,7 +146,8 @@ def set_event(self, event_data):
if not self.data_event.is_set():
# Once the data has been set the deferred queue requests can be run
asyncio.get_running_loop().call_soon_threadsafe(self.data_event.set)
self.update_viewer_status()
if ENVIRONMENT is not Env.HYPHA:
self.update_viewer_status()


class Viewer:
Expand Down Expand Up @@ -286,7 +287,8 @@ def set_image(self, image: Image, name: str = 'Image'):
svc.set_label_or_image('image')
else:
self.queue_request('setImage', image, name)
CellWatcher().update_viewer_status(self.name, False)
if ENVIRONMENT is not Env.HYPHA:
CellWatcher().update_viewer_status(self.name, False)
elif render_type is RenderType.POINT_SET:
image = _get_viewer_point_set(image)
self.queue_request('setPointSets', image)
Expand Down Expand Up @@ -555,7 +557,8 @@ def compare_images(self, fixed_image: Union[str, Image], moving_image: Union[str
if swap_image_order is not None:
options['swapImageOrder'] = swap_image_order
self.queue_request('compareImages', fixed_name, moving_name, options)
CellWatcher().update_viewer_status(self.name, False)
if ENVIRONMENT is not Env.HYPHA:
CellWatcher().update_viewer_status(self.name, False)

@fetch_value
def set_label_image(self, label_image: Image):
Expand All @@ -570,7 +573,8 @@ def set_label_image(self, label_image: Image):
svc.set_label_or_image('label_image')
else:
self.queue_request('setLabelImage', label_image)
CellWatcher().update_viewer_status(self.name, False)
if ENVIRONMENT is not Env.HYPHA:
CellWatcher().update_viewer_status(self.name, False)
elif render_type is RenderType.POINT_SET:
label_image = _get_viewer_point_set(label_image)
self.queue_request('setPointSets', label_image)
Expand Down

0 comments on commit ac60a45

Please sign in to comment.