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

Make moving making work again #1103

Merged
merged 2 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion nglview/contrib/movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def hook(frame):
frame, movie_making=True, render_params=self.render_params)
self._progress.description = 'Rendering ...'

def on_msg(widget, msg, _):
def on_msg(widget, msg, buffers):
if msg['type'] == 'movie_image_data':
image_array.append(msg.get('data'))
try:
Expand Down
16 changes: 8 additions & 8 deletions nglview/tests/test_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,29 +238,29 @@ class DummWidget():
[view])['methodName'] == 'setSyncCamera'

msg = dict(type='request_frame', data=dict())
view._handle_custom_msg(msg=msg, buffers=[])
view._handle_nglview_custom_msg(None, msg=msg, buffers=[])
msg = dict(type='repr_parameters', data=dict(name='hello'))
view._handle_custom_msg(msg=msg, buffers=[])
view._handle_nglview_custom_msg(None, msg=msg, buffers=[])
view.loaded = True
msg = dict(type='request_loaded', data=True)
view._handle_custom_msg(msg=msg, buffers=[])
view._handle_nglview_custom_msg(None, msg=msg, buffers=[])
view.loaded = False
msg = dict(type='request_loaded', data=True)
view._handle_custom_msg(msg=msg, buffers=[])
view._handle_nglview_custom_msg(None, msg=msg, buffers=[])
msg = dict(type='all_reprs_info', data=REPR_DICT)
view._handle_custom_msg(msg=msg, buffers=[])
view._handle_nglview_custom_msg(None, msg=msg, buffers=[])
msg = dict(type='stage_parameters', data=dict())
view._handle_custom_msg(msg=msg, buffers=[])
view._handle_nglview_custom_msg(None, msg=msg, buffers=[])
# test negative frame (it will be set to self.count - 1)
view.frame = -1
msg = dict(type='request_frame', data=dict())
# async_message
msg = {'type': 'async_message', 'data': 'ok'}
view._handle_custom_msg(msg, [])
view._handle_nglview_custom_msg(None, msg, [])
# render_image
r = view.render_image()
msg = {'type': 'image_data', 'ID': r.model_id, 'data': b'YmxhIGJsYQ=='}
view._handle_custom_msg(msg, [])
view._handle_nglview_custom_msg(None, msg, [])
view.loaded = True
view.show_only([
0,
Expand Down
9 changes: 6 additions & 3 deletions nglview/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def __init__(self,
self.stage = Stage(view=self)
self.control = ViewerControl(view=self)
self._handle_msg_thread = threading.Thread(
target=self.on_msg, args=(self._handle_custom_msg, ))
target=self.on_msg, args=(self._handle_nglview_custom_msg, ))
# # register to get data from JS side
self._handle_msg_thread.daemon = True
self._handle_msg_thread.start()
Expand Down Expand Up @@ -1036,13 +1036,16 @@ def download_image(self,
],
kwargs=params)

def _handle_custom_msg(self, msg, buffers):
def _handle_nglview_custom_msg(self, _, msg, buffers):
# Similar signature to
# https://github.com/jupyter-widgets/ipywidgets/blob/b78de43e12ff26e4aa16e6e4c6844a7c82a8ee1c/python/ipywidgets/ipywidgets/widgets/widget_string.py#L122
# NOTE: "self" is not counted as first argument.
"""store message sent from Javascript.

How? use view.on_msg(get_msg)

Notes: message format should be {'type': type, 'data': data}
_handle_custom_msg will call appropriate function to handle message "type"
_handle_nglview_custom_msg will call appropriate function to handle message "type"
"""
self._ngl_msg = msg

Expand Down