Skip to content

Commit

Permalink
Stylesheet: Don't compute stylesheets when importing the module
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Jun 13, 2021
1 parent bffe571 commit ba08250
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions spyder/utils/stylesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ class SpyderStyleSheet:

def __init__(self):
self._stylesheet = qstylizer.style.StyleSheet()
self.set_stylesheet()
self._stylesheet_as_string = None

def get_stylesheet(self):
return self._stylesheet

def to_string(self):
return self._stylesheet.toString()
"Save stylesheet as a string for quick access."
if self._stylesheet_as_string is None:
# Leave this line here so that stylesheets are computed when
# used and not when importing this module.
self.set_stylesheet()

# Cache stylesheet string
self._stylesheet_as_string = self._stylesheet.toString()
return self._stylesheet_as_string

def get_copy(self):
"""
Expand All @@ -50,10 +58,14 @@ def get_copy(self):
def set_stylesheet(self):
raise NotImplementedError(
"Subclasses need to implement this method to set the _stylesheet "
"attribute as a Qstylizer StyleSheet object"
"attribute as a Qstylizer StyleSheet object."
)

def __str__(self):
"""
Get a string representation of the stylesheet object this class
holds.
"""
return self.to_string()


Expand All @@ -66,16 +78,6 @@ class AppStylesheet(SpyderStyleSheet):
application.
"""

def __init__(self):
super().__init__()
self._stylesheet_as_string = None

def to_string(self):
"Save stylesheet as a string for quick access."
if self._stylesheet_as_string is None:
self._stylesheet_as_string = self._stylesheet.toString()
return self._stylesheet_as_string

def set_stylesheet(self):
"""
This takes the stylesheet from QDarkstyle and applies our
Expand Down Expand Up @@ -335,6 +337,7 @@ def set_stylesheet(self):
)

def to_string(self):
super().to_string()
css_string = self._stylesheet.toString()

# TODO: We need to fix this in qstylizer
Expand Down

0 comments on commit ba08250

Please sign in to comment.