##// END OF EJS Templates
Make the widget property_lock store the JSON state, not the original object...
Jason Grout -
Show More
@@ -202,9 +202,7 b' class Widget(LoggingConfigurable):'
202 raise ValueError("key must be a string, an iterable of keys, or None")
202 raise ValueError("key must be a string, an iterable of keys, or None")
203 state = {}
203 state = {}
204 for k in keys:
204 for k in keys:
205 f = self.trait_metadata(k, 'to_json')
205 f = self.trait_metadata(k, 'to_json', self._trait_to_json)
206 if f is None:
207 f = self._trait_to_json
208 value = getattr(self, k)
206 value = getattr(self, k)
209 state[k] = f(value)
207 state[k] = f(value)
210 return state
208 return state
@@ -255,6 +253,8 b' class Widget(LoggingConfigurable):'
255 def _lock_property(self, key, value):
253 def _lock_property(self, key, value):
256 """Lock a property-value pair.
254 """Lock a property-value pair.
257
255
256 The value should be the JSON state of the property.
257
258 NOTE: This, in addition to the single lock for all state changes, is
258 NOTE: This, in addition to the single lock for all state changes, is
259 flawed. In the future we may want to look into buffering state changes
259 flawed. In the future we may want to look into buffering state changes
260 back to the front-end."""
260 back to the front-end."""
@@ -280,7 +280,9 b' class Widget(LoggingConfigurable):'
280
280
281 def _should_send_property(self, key, value):
281 def _should_send_property(self, key, value):
282 """Check the property lock (property_lock)"""
282 """Check the property lock (property_lock)"""
283 if (key == self._property_lock[0] and value == self._property_lock[1]):
283 to_json = self.trait_metadata(key, 'to_json', self._trait_to_json)
284 if (key == self._property_lock[0]
285 and to_json(value) == self._property_lock[1]):
284 return False
286 return False
285 elif self._send_state_lock > 0:
287 elif self._send_state_lock > 0:
286 self._states_to_send.add(key)
288 self._states_to_send.add(key)
@@ -311,12 +313,10 b' class Widget(LoggingConfigurable):'
311 """Called when a state is received from the front-end."""
313 """Called when a state is received from the front-end."""
312 for name in self.keys:
314 for name in self.keys:
313 if name in sync_data:
315 if name in sync_data:
314 f = self.trait_metadata(name, 'from_json')
316 json_value = sync_data[name]
315 if f is None:
317 from_json = self.trait_metadata(name, 'from_json', self._trait_from_json)
316 f = self._trait_from_json
318 with self._lock_property(name, json_value):
317 value = f(sync_data[name])
319 setattr(self, name, from_json(json_value))
318 with self._lock_property(name, value):
319 setattr(self, name, value)
320
320
321 def _handle_custom_msg(self, content):
321 def _handle_custom_msg(self, content):
322 """Called when a custom msg is received."""
322 """Called when a custom msg is received."""
General Comments 0
You need to be logged in to leave comments. Login now