##// END OF EJS Templates
Updated set_css so it can handle a dictionary of keys and values.
Jonathan Frederic -
Show More
@@ -183,8 +183,9 b' class Widget(LoggingConfigurable):'
183
183
184
184
185 def get_css(self, key, selector=""):
185 def get_css(self, key, selector=""):
186 """Get a CSS property of the widget views (shared among all of the
186 """Get a CSS property of the widget. Note, this function does not
187 views)
187 actually request the CSS from the front-end; Only properties that have
188 been set with set_css can be read.
188
189
189 Parameters
190 Parameters
190 ----------
191 ----------
@@ -199,12 +200,16 b' class Widget(LoggingConfigurable):'
199 return None
200 return None
200
201
201
202
202 def set_css(self, key, value, selector=""):
203 def set_css(self, *args, **kwargs):
203 """Set a CSS property of the widget views (shared among all of the
204 """Set one or more CSS properties of the widget (shared among all of the
204 views)
205 views). This function has two signatures:
206 - set_css(css_dict, [selector=''])
207 - set_css(key, value, [selector=''])
205
208
206 Parameters
209 Parameters
207 ----------
210 ----------
211 css_dict : dict
212 CSS key/value pairs to apply
208 key: unicode
213 key: unicode
209 CSS key
214 CSS key
210 value
215 value
@@ -212,13 +217,33 b' class Widget(LoggingConfigurable):'
212 selector: unicode (optional)
217 selector: unicode (optional)
213 JQuery selector to use to apply the CSS key/value.
218 JQuery selector to use to apply the CSS key/value.
214 """
219 """
215 if selector not in self._css:
220 selector = kwargs.get('selector', '')
216 self._css[selector] = {}
221
217
222 # Signature 1: set_css(css_dict, [selector=''])
218 # Only update the property if it has changed.
223 if len(args) == 1:
219 if not (key in self._css[selector] and value in self._css[selector][key]):
224 if isinstance(args[0], dict):
220 self._css[selector][key] = value
225 for (key, value) in args[0].items():
221 self.send_state('_css') # Send new state to client.
226 self.set_css(key, value, selector=selector)
227 else:
228 raise Exception('css_dict must be a dict.')
229
230 # Signature 2: set_css(key, value, [selector=''])
231 elif len(args) == 2 or len(args) == 3:
232
233 # Selector can be a positional arg if it's the 3rd value
234 if len(args) == 3:
235 selector = args[2]
236 if selector not in self._css:
237 self._css[selector] = {}
238
239 # Only update the property if it has changed.
240 key = args[0]
241 value = args[1]
242 if not (key in self._css[selector] and value in self._css[selector][key]):
243 self._css[selector][key] = value
244 self.send_state('_css') # Send new state to client.
245 else:
246 raise Exception('set_css only accepts 1-3 arguments')
222
247
223
248
224 def add_class(self, class_name, selector=""):
249 def add_class(self, class_name, selector=""):
General Comments 0
You need to be logged in to leave comments. Login now