_set_stylesheet fails if passed a dictionary
def _set_stylesheet(self, css):
if not isinstance(css, CSS):
css = CSS(**css) # <<-- Lacks a target argument
self._style = css
css.apply_recursive(self)
Not sure what an appropriate substitute key would be here, though maybe self.key is workable?
Or we could raise TypeError if not passed a CSS instance.
Does this fail for a case like this?
dummy = {'backgroundColor': 'red', 'width': 200}
Button(style=dummy)
That one fails, but this works:
dummy = {'backgroundColor': (1,0,0), 'width': 200}
Button(css=dummy)
its really just the Styled.stylesheet property that causes the issue, at it tries to create a CSS instance from the dict. Which fails because CSS expects a target param in addition to the usual style kwargs.
But after that everything just treats the _style attribute as a mapping.
The only circumstance I could see that would fail would be:
with VerticalForm(css={'backgroundColor': (1,0,0), 'width': 200}) as f:
for i in xrange(5):
Button()
f.stylesheet.apply_recursive(f)
Which will fail with:
# AttributeError: 'dict' object has no attribute 'apply_recursive' #
What is the use-case for specifying a dictionary outside of css={} ? I'm noticing that the apply_recursive method in _set_stylesheet does not apply the style to the controls defined. For example:
style = styles.CSS('_', backgroundColor = (1,0,0), width = 200)
with VerticalForm() as f:
for i in xrange(5):
Button()
f.stylesheet = style
Let me know if this is intended behavior.
Maybe we just give it an empty, like this:
def _set_stylesheet(self, css):
css = css or {}
if not isinstance(css, CSS):
css = CSS(**css) # <<-- Lacks a target argument
self._style = css
It's just syntax sugar for users, since there are a lot of use cases where you just want to say 'use these options' and the more elaborate stuff is not on your radar
Doh, we could just target Control when we make the fake CSS....
def _set_stylesheet(self, css): if not isinstance(css, CSS): css = CSS(gui.Control, **css) self._style = css css.apply_recursive(self)
self.key would apply it only to this instance, control would do it to anything under this instance. I'm not sure which would be a commoner case. Maybe self.key is better because it prevents outflows from this non-standard syntax. Thoughts?