Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr240 fixing static directory creation issue #242

Prev Previous commit
Next Next commit
Added static url to create and overwrite pydy-resources
  • Loading branch information
sahilshekhawat committed Jun 18, 2015
commit 5176bb70959f628ebb6aa3417501891c0e9f1353
15 changes: 10 additions & 5 deletions pydy/viz/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def __init__(self, reference_frame, origin, *visualization_frames,
for k, v in default_kwargs.items():
setattr(self, k, v)

self.static_url = os.path.join(os.getcwd(), "pydy-resources")

@property
def name(self):
"""Returns the name of the scene."""
Expand Down Expand Up @@ -526,7 +528,7 @@ def create_static_html(self, overwrite=False, silent=False):

"""

dst = os.path.join(os.getcwd(), 'static')
dst = self.static_url

if os.path.exists(dst) and overwrite is False:
ans = raw_input("The 'static' directory already exists. Would "
Expand All @@ -547,9 +549,9 @@ def create_static_html(self, overwrite=False, silent=False):
if not silent:
print("Copying Simulation data.")

_scene_outfile_loc = os.path.join(os.getcwd(), 'static',
_scene_outfile_loc = os.path.join(self.static_url,
self._scene_json_file)
_simulation_outfile_loc = os.path.join(os.getcwd(), 'static',
_simulation_outfile_loc = os.path.join(self.static_url,
self._simulation_json_file)
scene_outfile = open(_scene_outfile_loc, "w")
simulation_outfile = open(_simulation_outfile_loc, "w")
Expand Down Expand Up @@ -703,10 +705,13 @@ def display_ipython(self):
display(self._constants_container)
display(self._rerun_button)

with open("static/index_ipython.html", 'r') as html_file:
ipython_static_url = os.path.relpath(self.static_url, os.getcwd())

with open(os.path.join(ipython_static_url, "index_ipython.html"), 'r') as html_file:
html = html_file.read()

html = html.format(load_url='static/' + self._scene_json_file)
html = html.format(static_url=os.path.join('files', ipython_static_url),
load_url=os.path.join(ipython_static_url, self._scene_json_file))

self._html_widget = widgets.HTML(value=html)

Expand Down
34 changes: 17 additions & 17 deletions pydy/viz/static/index_ipython.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@
<title>PyDy Visualizer</title>

<!--CSS -->
<link type="text/css" rel="stylesheet" href="static/css/main.css">
<link type="text/css" rel="stylesheet" href="static/css/codemirror/blackboard.css">
<link type="text/css" rel="stylesheet" href="static/css/slider.css">
<link type="text/css" rel="stylesheet" href="static/css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="{static_url}/css/main.css">
<link type="text/css" rel="stylesheet" href="{static_url}/css/codemirror/blackboard.css">
<link type="text/css" rel="stylesheet" href="{static_url}/css/slider.css">
<link type="text/css" rel="stylesheet" href="{static_url}/css/bootstrap.min.css">

<!-- External Javascript -->
<script type="text/javascript" src="static/js/external/jquery/jquery-ui.js"></script>
<script type="text/javascript" src="{static_url}/js/external/jquery/jquery-ui.js"></script>

<script type="text/javascript" src="static/js/external/codemirror/javascript-mode.js" ></script>
<script type="text/javascript" src="{static_url}/js/external/codemirror/javascript-mode.js" ></script>

<script type="text/javascript" src="static/js/external/three/three.min.js"></script>
<script type="text/javascript" src="static/js/external/three/TrackballControls.js"></script>
<script type="text/javascript" src="{static_url}/js/external/three/three.min.js"></script>
<script type="text/javascript" src="{static_url}/js/external/three/TrackballControls.js"></script>

<script type="text/javascript" src="static/js/external/utils/modernizr-2.0.6.js"></script>
<script type="text/javascript" src="static/js/external/utils/bootstrap-slider.js"></script>
<script type="text/javascript" src="static/js/external/utils/prototype.js"></script>
<script type="text/javascript" src="{static_url}/js/external/utils/modernizr-2.0.6.js"></script>
<script type="text/javascript" src="{static_url}/js/external/utils/bootstrap-slider.js"></script>
<script type="text/javascript" src="{static_url}/js/external/utils/prototype.js"></script>

<!-- DyViz Javascripts -->
<script type="text/javascript" src="static/js/dyviz/dv.js"></script>
<script type="text/javascript" src="static/js/dyviz/scene.js"></script>
<script type="text/javascript" src="static/js/dyviz/parser.js"></script>
<script type="text/javascript" src="static/js/dyviz/param_editor.js"></script>
<script type="text/javascript" src="static/js/dyviz/materials.js"></script>
<script type="text/javascript" src="{static_url}/js/dyviz/dv.js"></script>
<script type="text/javascript" src="{static_url}/js/dyviz/scene.js"></script>
<script type="text/javascript" src="{static_url}/js/dyviz/parser.js"></script>
<script type="text/javascript" src="{static_url}/js/dyviz/param_editor.js"></script>
<script type="text/javascript" src="{static_url}/js/dyviz/materials.js"></script>

</head>

Expand Down Expand Up @@ -94,6 +94,6 @@
</div>
</body>

<script type="text/javascript" src="static/js/dyviz/main.js"></script>
<script type="text/javascript" src="{static_url}/js/dyviz/main.js"></script>

</html>