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