diff --git a/IPython/html/static/widgets/js/widget.js b/IPython/html/static/widgets/js/widget.js index 7e79414..dd17ded 100644 --- a/IPython/html/static/widgets/js/widget.js +++ b/IPython/html/static/widgets/js/widget.js @@ -69,7 +69,7 @@ define(["widgets/js/manager", var method = msg.content.data.method; switch (method) { case 'update': - this.apply_update(msg.content.data.state); + this.set_state(msg.content.data.state); break; case 'custom': this.trigger('msg:custom', msg.content.data.content); @@ -80,7 +80,7 @@ define(["widgets/js/manager", } }, - apply_update: function (state) { + set_state: function (state) { // Handle when a widget is updated via the python side. this.state_lock = state; try { diff --git a/IPython/html/tests/widgets/widget.js b/IPython/html/tests/widgets/widget.js index 9364f03..d51a833 100644 --- a/IPython/html/tests/widgets/widget.js +++ b/IPython/html/tests/widgets/widget.js @@ -118,8 +118,8 @@ casper.notebook_test(function () { ' b = CInt(0, sync=True)\n' + ' c = CInt(0, sync=True)\n' + ' d = CInt(-1, sync=True)\n' + // See if it sends a full state. - ' def _handle_receive_state(self, sync_data):\n' + - ' widgets.Widget._handle_receive_state(self, sync_data)\n'+ + ' def set_state(self, sync_data):\n' + + ' widgets.Widget.set_state(self, sync_data)\n'+ ' self.d = len(sync_data)\n' + 'multiset = MultiSetWidget()\n' + 'display(multiset)\n' + diff --git a/IPython/html/widgets/widget.py b/IPython/html/widgets/widget.py index e274b46..eba315f 100644 --- a/IPython/html/widgets/widget.py +++ b/IPython/html/widgets/widget.py @@ -208,6 +208,15 @@ class Widget(LoggingConfigurable): value = getattr(self, k) state[k] = f(value) return state + + def set_state(self, sync_data): + """Called when a state is received from the front-end.""" + for name in self.keys: + if name in sync_data: + json_value = sync_data[name] + from_json = self.trait_metadata(name, 'from_json', self._trait_from_json) + with self._lock_property(name, json_value): + setattr(self, name, from_json(json_value)) def send(self, content): """Sends a custom msg to the widget model in the front-end. @@ -304,22 +313,13 @@ class Widget(LoggingConfigurable): # Handle backbone sync methods CREATE, PATCH, and UPDATE all in one. if method == 'backbone' and 'sync_data' in data: sync_data = data['sync_data'] - self._handle_receive_state(sync_data) # handles all methods + self.set_state(sync_data) # handles all methods # Handle a custom msg from the front-end elif method == 'custom': if 'content' in data: self._handle_custom_msg(data['content']) - def _handle_receive_state(self, sync_data): - """Called when a state is received from the front-end.""" - for name in self.keys: - if name in sync_data: - json_value = sync_data[name] - from_json = self.trait_metadata(name, 'from_json', self._trait_from_json) - with self._lock_property(name, json_value): - setattr(self, name, from_json(json_value)) - def _handle_custom_msg(self, content): """Called when a custom msg is received.""" self._msg_callbacks(self, content)