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