Skip to content

Commit

Permalink
move viewers to submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Jan 2, 2019
1 parent 6b6ca61 commit a9969d9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'trimesh.path.exchange',
'trimesh.scene',
'trimesh.visual',
'trimesh.viewer',
'trimesh.exchange',
'trimesh.resources',
'trimesh.interfaces'],
Expand Down
13 changes: 10 additions & 3 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@ class ViewTest(g.unittest.TestCase):

def test_JSHTML(self):

import trimesh.scene.viewerJS as js
import trimesh.viewer.notebook as js

m = g.get_mesh('featuretype.STL')
s = m.scene()

# a viewable scene
html = js.scene_to_html(s)

assert len(html) > 0

# check it out as an LXML document
from lxml.html import fromstring
h = fromstring(html)

# should have some children
children = list(h.body.iterchildren())
assert len(children) >= 2

def test_inNB(self):
import trimesh.scene.viewerJS as js
import trimesh.viewer.notebook as js

# should only return True inside
# jypyter/IPython notebooks
Expand Down
4 changes: 1 addition & 3 deletions trimesh/scene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

from .scene import Scene, split_scene

from .viewerJS import in_notebook

# add to __all__ as per pep8
__all__ = [Camera, Scene, split_scene, in_notebook]
__all__ = [Camera, Scene, split_scene]
6 changes: 3 additions & 3 deletions trimesh/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,16 +809,16 @@ def show(self, viewer=None, **kwargs):

if viewer is None:
# check to see if we are in a notebook or not
from .viewerJS import in_notebook
from ..viewer import in_notebook
viewer = ['gl', 'notebook'][int(in_notebook())]

if viewer == 'gl':
# this imports pyglet, and will raise an ImportError
# if pyglet is not available
from .viewer import SceneViewer
from ..viewer import SceneViewer
return SceneViewer(self, **kwargs)
elif viewer == 'notebook':
from .viewerJS import scene_to_notebook
from ..viewer import scene_to_notebook
return scene_to_notebook(self, **kwargs)
else:
raise ValueError('viewer must be "gl", "notebook", or None')
Expand Down
21 changes: 21 additions & 0 deletions trimesh/viewer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
viewer
-------------
View meshes and scenes via pyglet or inline HTML.
"""

from .windowed import (SceneViewer,
render_scene)

from .notebook import (in_notebook,
scene_to_notebook,
scene_to_html)

# explicitly list imports in __all__
# as otherwise flake8 gets mad
__all__ = [SceneViewer,
render_scene,
in_notebook,
scene_to_notebook,
scene_to_html]
File renamed without changes.
File renamed without changes.

0 comments on commit a9969d9

Please sign in to comment.