##// END OF EJS Templates
Get rid of keys magic; make the keys very explicit
Jason Grout -
Show More
@@ -34,10 +34,10 b' from IPython.utils.py3compat import string_types'
34 34 class BaseWidget(LoggingConfigurable):
35 35
36 36 # Shared declarations (Class level)
37 _keys = List(Unicode, default_value = [],
38 help="List of keys comprising the state of the model.", allow_none=False)
39 37 widget_construction_callback = None
40 38
39 keys = ['default_view_name']
40
41 41 def on_widget_constructed(callback):
42 42 """Class method, registers a callback to be called when a widget is
43 43 constructed. The callback must have the following signature:
@@ -84,22 +84,6 b' class BaseWidget(LoggingConfigurable):'
84 84 removed from the frontend."""
85 85 self._close_communication()
86 86
87 _keys = ['default_view_name']
88
89 # Properties
90 @property
91 def keys(self):
92 """Lazily accumulate _keys from all superclasses and cache them in this class"""
93 keys=[]
94 for c in self.__class__.mro():
95 if hasattr(c, '_keys'):
96 keys.extend(getattr(c,'_keys'))
97 else:
98 break
99 # cache so future lookups are fast
100 self.__class__.x = keys
101 return keys
102
103 87 @property
104 88 def comm(self):
105 89 if self._comm is None:
@@ -151,8 +135,7 b' class BaseWidget(LoggingConfigurable):'
151 135
152 136 def _handle_recieve_state(self, sync_data):
153 137 """Called when a state is recieved from the frontend."""
154 # Use _keys instead of keys - Don't get retrieve the css from the client side.
155 for name in self._keys:
138 for name in self.keys:
156 139 if name in sync_data:
157 140 try:
158 141 self._property_lock = (name, sync_data[name])
@@ -354,7 +337,7 b' class Widget(BaseWidget):'
354 337 # Private/protected declarations
355 338 _css = Dict() # Internal CSS property dict
356 339
357 _keys = ['visible', '_css']
340 keys = ['visible', '_css'] + BaseWidget.keys
358 341
359 342 def get_css(self, key, selector=""):
360 343 """Get a CSS property of the widget. Note, this function does not
General Comments 0
You need to be logged in to leave comments. Login now