Stop calling _register automatically for StyleSheetObservers

This commit is contained in:
Jay Kamat 2017-11-13 12:04:31 -05:00
parent e00a072d15
commit 0f17e6633d
No known key found for this signature in database
GPG Key ID: 5D2E399600F4F7B5

View File

@ -483,7 +483,8 @@ def set_register_stylesheet(obj, *, stylesheet=None, update=True):
stylesheet: The stylesheet to use. stylesheet: The stylesheet to use.
update: Whether to update the stylesheet on config changes. update: Whether to update the stylesheet on config changes.
""" """
StyleSheetObserver(obj, stylesheet, update) observer = StyleSheetObserver(obj, stylesheet, update)
observer.register()
@functools.lru_cache() @functools.lru_cache()
@ -506,16 +507,15 @@ class StyleSheetObserver(QObject):
def __init__(self, obj, stylesheet, update): def __init__(self, obj, stylesheet, update):
super().__init__() super().__init__()
self._obj = obj self._obj = obj
self.update = update self._update = update
# We only need to hang around if we are asked to update. # We only need to hang around if we are asked to update.
if self.update: if self._update:
self.setParent(self._obj) self.setParent(self._obj)
if stylesheet is None: if stylesheet is None:
self._stylesheet = obj.STYLESHEET self._stylesheet = obj.STYLESHEET
else: else:
self._stylesheet = stylesheet self._stylesheet = stylesheet
self._register()
def _get_stylesheet(self): def _get_stylesheet(self):
"""Format a stylesheet based on a template. """Format a stylesheet based on a template.
@ -530,7 +530,7 @@ class StyleSheetObserver(QObject):
"""Update the stylesheet for obj.""" """Update the stylesheet for obj."""
self._obj.setStyleSheet(self._get_stylesheet()) self._obj.setStyleSheet(self._get_stylesheet())
def _register(self): def register(self):
"""Do a first update and listen for more. """Do a first update and listen for more.
Args: Args:
@ -540,5 +540,5 @@ class StyleSheetObserver(QObject):
log.config.vdebug("stylesheet for {}: {}".format( log.config.vdebug("stylesheet for {}: {}".format(
self._obj.__class__.__name__, qss)) self._obj.__class__.__name__, qss))
self._obj.setStyleSheet(qss) self._obj.setStyleSheet(qss)
if self.update: if self._update:
instance.changed.connect(self._update_stylesheet) instance.changed.connect(self._update_stylesheet)