Skip to content

Commit

Permalink
ENH: Add initial Viewer / view class
Browse files Browse the repository at this point in the history
Works in Colab!

Addresses InsightSoftwareConsortium#99, more can be done with the window size.

Co-authored-by: Brianna Major <brianna.major@kitware.com>
Co-authored-by: Wei Ouyang <oeway007@gmail.com>
  • Loading branch information
3 people committed May 20, 2022
1 parent 6af62e7 commit 0c36f63
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions itkwidgets/view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .viewer import Viewer

__all__ = [
"view",
]

def view(image=None):
return api.export(Viewer(image=image))
27 changes: 27 additions & 0 deletions itkwidgets/viewer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
__all__ = [
"Viewer",
]

class Viewer:
"""Viewer class."""

def __init__(self, **kwargs):
try:
from google.colab import output
self.running_in_colab = True
except ModuleNotFoundError:
self.running_in_colab = False
self.image = kwargs.get('image', None)

async def setup(self):
if self.running_in_colab:
viewer = await api.showDialog(
type='itk-vtk-viewer',
src='https://kitware.github.io/itk-vtk-viewer/app',
)
else:
viewer = await api.createWindow(
type='itk-vtk-viewer',
src='https://kitware.github.io/itk-vtk-viewer/app',
)
await viewer.setImage(self.image)

0 comments on commit 0c36f63

Please sign in to comment.