forked from InsightSoftwareConsortium/itkwidgets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add initial Viewer / view class
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
1 parent
6af62e7
commit 0c36f63
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |