def _invalidate_style_cache(self, change): """ An observer which invalidates the style sheet cache. """ if change['type'] == 'update': from enaml.styling import StyleCache StyleCache._app_sheet_changed()
def test_element_selector(): from enaml.styling import StyleCache source = dedent("""\ from enaml.widgets.api import Window, Container, PushButton, Field from enaml.styling import StyleSheet, Style, Setter enamldef Sheet(StyleSheet): Style: element = 'PushButton' Setter: field = 'background' value = 'blue' enamldef SubButton(PushButton): pass enamldef Main(Window): alias button alias subbutton alias field Sheet: pass Container: PushButton: button: pass SubButton: subbutton: pass Field: field: pass """) main = compile_source(source, 'Main')() assert len(StyleCache.styles(main.button)) == 1 assert len(StyleCache.styles(main.subbutton)) == 1 assert len(StyleCache.styles(main.field)) == 0
def test_name_selector(): from enaml.styling import StyleCache source = dedent("""\ from enaml.widgets.api import Window, Container, PushButton from enaml.styling import StyleSheet, Style, Setter enamldef Sheet(StyleSheet): Style: object_name = 'button' Setter: field = 'background' value = 'blue' enamldef Main(Window): alias button alias other Sheet: pass Container: PushButton: button: name = 'button' PushButton: other: style_class = 'button' """) main = compile_source(source, 'Main')() assert len(StyleCache.styles(main.button)) == 1 assert len(StyleCache.styles(main.other)) == 0
def _translate_style_body(style): translated = [] for setter in style.setters(): tks = StyleCache.toolkit_setter(setter, _translate_setter) if tks is not None: translated.append(tks) return '\n'.join(translated)
def test_cache_1(): from enaml.application import Application from enaml.styling import StyleCache source = dedent("""\ from enaml.widgets.api import Window, Container, PushButton from enaml.styling import StyleSheet, Style, Setter enamldef Sheet(StyleSheet): Style: element = 'PushButton' Setter: field = 'background' value = 'blue' enamldef Main(Window): alias button Sheet: pass Container: PushButton: button: pass """) _clear_cache() app = Application.instance() if app is not None: app.style_sheet = None main = compile_source(source, 'Main')() styles = StyleCache.styles(main.button) assert len(styles) == 1 assert not _cache_items_empty() assert not _cache_styles_empty() main.destroy() assert _cache_items_empty() assert _cache_styles_empty()
def _translate_style_body(style): translated = [] for setter in style.setters(): tks = StyleCache.toolkit_setter(setter, _translate_setter) if tks is not None: translated.append(tks) return u'\n'.join(translated)
def _assert_setters(item, values): from enaml.styling import StyleCache styles = StyleCache.styles(item) setters = [s.setters() for s in styles] setters = sum(setters, []) assert len(setters) == len(values) for setter, (field, value) in zip(setters, values): assert setter.field == field assert setter.value == value
def refresh_style_sheet(self): """ Refresh the widget style sheet with the current style data. """ parts = [] name = self.widget.objectName() for style in StyleCache.styles(self.declaration): t = translate_style(name, style) if t: parts.append(t) if len(parts) > 0: stylesheet = u'\n\n'.join(parts) else: stylesheet = u'' self.widget.setStyleSheet(stylesheet)
def refresh_style_sheet(self): """ A reimplemented styling method. The dock item uses custom stylesheet processing. """ parts = [] name = self.widget.objectName() for style in StyleCache.styles(self.declaration): t = translate_dock_item_style(name, style) if t: parts.append(t) if len(parts) > 0: stylesheet = u'\n\n'.join(parts) else: stylesheet = u'' self.widget.setStyleSheet(stylesheet)
def refresh_style_sheet(self): """ Refresh the widget style sheet with the current style data. """ #print("{}.refresh_style_sheet() not implemented".format(self)) return parts = [] name = self.widget.id for style in StyleCache.styles(self.declaration): t = translate_style(name, style) if t: parts.append(t) if len(parts) > 0: stylesheet = u'\n\n'.join(parts) else: stylesheet = u'' self.widget.setStyleSheet(stylesheet)
def refresh_style_sheet(self): """ A reimplemented styling method. The dock area uses custom stylesheet processing. """ # workaround win-7 sizing bug parts = [u'QDockTabWidget::pane {}'] name = self.widget.objectName() for style in StyleCache.styles(self.declaration): t = translate_dock_area_style(name, style) if t: parts.append(t) if len(parts) > 1: stylesheet = u'\n\n'.join(parts) else: stylesheet = u'' self.widget.setStyleSheet(stylesheet)