1
1
import base64
2
2
import json
3
+ import re
3
4
import threading
4
5
import time
5
6
import uuid
6
7
from logging import getLogger
7
8
8
9
import ipywidgets as widgets
9
- import ipywidgets . embed
10
+ from ipywidgets import embed
10
11
import numpy as np
11
12
from IPython .display import display
12
13
from ipywidgets import (Image , Box , DOMWidget , HBox , VBox , IntSlider , Output , Play , Widget ,
@@ -84,9 +85,6 @@ def write_html(fp, views, frame_range=None):
84
85
>>> nglview.write_html('index.html', [view], frame_range=(0, 5)) # doctest: +SKIP
85
86
"""
86
87
views = isinstance (views , DOMWidget ) and [views ] or views
87
- embed = ipywidgets .embed
88
- color = None
89
- theme = None
90
88
91
89
for _ , v in _INIT_VIEWS .items ():
92
90
views .insert (0 , v )
@@ -110,6 +108,12 @@ def _unset_serialization(views):
110
108
snippet = '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.0/jquery-ui.css">\n '
111
109
snippet += '<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">\n '
112
110
snippet += embed .embed_snippet (views )
111
+ # hacky thing for https://github.com/nglviewer/nglview/issues/1107
112
+ # NGL must be fixed before we can remove this hack
113
+ _frontend = {'__frontend_version__' : __frontend_version__ }
114
+ pattern = r'("model_module":\s*"nglview-js-widgets",\s*"model_module_version":\s*)"' + re .escape (_frontend ['__frontend_version__' ]) + '",'
115
+ replacement = r'\g<1>"3.0.8",'
116
+ snippet = re .sub (pattern , replacement , snippet )
113
117
html_code = embed .html_template .format (title = 'nglview-demo' ,
114
118
snippet = snippet )
115
119
@@ -332,7 +336,7 @@ def camera(self):
332
336
@camera .setter
333
337
def camera (self , value ):
334
338
"""
335
-
339
+
336
340
Parameters
337
341
----------
338
342
value : str, {'perspective', 'orthographic'}
@@ -694,7 +698,7 @@ def _update_repr_dict(self):
694
698
695
699
def set_representations (self , representations , component = 0 ):
696
700
"""
697
-
701
+
698
702
Parameters
699
703
----------
700
704
representations : list of dict
@@ -840,7 +844,7 @@ def _add_shape(self, shapes, name='shape'):
840
844
Notes
841
845
-----
842
846
Supported shape: 'mesh', 'sphere', 'ellipsoid', 'cylinder', 'cone', 'arrow'.
843
-
847
+
844
848
See also
845
849
--------
846
850
{ngl_url}
@@ -983,7 +987,7 @@ def render_image(self,
983
987
--------
984
988
# tell NGL to render send image data to notebook.
985
989
view.render_image()
986
-
990
+
987
991
# make sure to call `get_image` method
988
992
view.get_image()
989
993
@@ -1183,7 +1187,7 @@ def add_pdbid(self, pdbid, **kwargs):
1183
1187
>>> import nglview
1184
1188
>>> view = nglview.NGLWidget()
1185
1189
>>> c = view.add_pdbid('1tsu')
1186
- >>> # which is equal to
1190
+ >>> # which is equal to
1187
1191
>>> # view.add_component('rcsb://1tsu.pdb')
1188
1192
'''
1189
1193
return self .add_component (f'rcsb://{ pdbid } .pdb' , ** kwargs )
@@ -1331,7 +1335,7 @@ def _get_remote_call_msg(self,
1331
1335
kwargs = None ,
1332
1336
** other_kwargs ):
1333
1337
"""call NGL's methods from Python.
1334
-
1338
+
1335
1339
Parameters
1336
1340
----------
1337
1341
method_name : str
0 commit comments