Repository: spyder-ide/spyder

Issue:
Switching to light/dark themes is not working as expected
## Problem Description
Note: Third party plugins are using a new API (Spyder == 5.0.x)

When I change the style in Tools -> Preferences from Light to Dark I get part of the dark interface and the other part light (third party plugin)


When I'm in Dark mode and switch to light mode (Tools -> Preferences -> Appearance -> Spyder -> Ok ) everything works fine:
![dark](https://user-images.githubusercontent.com/61120620/122650482-a2bae400-d109-11eb-9e43-f57525454b73.png)
![dark2](https://user-images.githubusercontent.com/61120620/122650483-a3537a80-d109-11eb-817d-79ef86a63b9d.png)
![dark3](https://user-images.githubusercontent.com/61120620/122650484-a3ec1100-d109-11eb-9f77-ea162e00be09.png)
![ligth](https://user-images.githubusercontent.com/61120620/122650485-a484a780-d109-11eb-894f-47f858a66e87.png)





When I am in light mode and switch to dark mode (Tools -> Preferences -> Appearance -> Spyder Dark -> Ok) it works with a light part and a dark part:
![ligth](https://user-images.githubusercontent.com/61120620/122650782-245f4180-d10b-11eb-9121-7a308fade314.png)
![ligth2](https://user-images.githubusercontent.com/61120620/122650783-24f7d800-d10b-11eb-9e64-33d167a9d2cc.png)
![ligth3](https://user-images.githubusercontent.com/61120620/122650784-25906e80-d10b-11eb-9d6b-e7b1f93aa11f.png)
![ligth4](https://user-images.githubusercontent.com/61120620/122650785-26290500-d10b-11eb-8ce5-2ff91ce4f588.png)
![ligth5](https://user-images.githubusercontent.com/61120620/122650787-26290500-d10b-11eb-9f29-4d9f1d137c31.png)


### What steps reproduce the problem?

(Tools -> Preferences -> Appearance -> Spyder -> Ok - Yes )  and
(Tools -> Preferences -> Appearance -> Spyder Dark-> Ok ) 

## Versions
Spyder version: 5.0.1
Python version: 3.8
Qt version: 5.12.9
PyQt5 version: 5.12.3
Operating System: Linux Mint 20.


### Dependencies
```
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       1_gnu    conda-forge
alabaster                 0.7.12                     py_0    conda-forge
alsa-lib                  1.2.3                h516909a_0    conda-forge
appdirs                   1.4.4              pyh9f0ad1d_0    conda-forge
argh                      0.26.2          pyh9f0ad1d_1002    conda-forge
arpeggio                  1.10.1                   pypi_0    pypi
arrow                     1.1.0            py38h578d9bd_0    conda-forge
astroid                   2.5.6            py38h578d9bd_0    conda-forge
async_generator           1.10                       py_0    conda-forge
atomicwrites              1.4.0              pyh9f0ad1d_0    conda-forge
attrs                     20.3.0             pyhd3deb0d_0    conda-forge
autopep8                  1.5.5                    pypi_0    pypi
babel                     2.9.0              pyhd3deb0d_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
binaryornot               0.4.4                      py_1    conda-forge
black                     21.4b2             pyhd8ed1ab_0    conda-forge
bleach                    3.3.0              pyh44b312d_0    conda-forge
brotlipy                  0.7.0           py38h497a2fe_1001    conda-forge
c-ares                    1.17.1               h7f98852_1    conda-forge
ca-certificates           2020.12.5            ha878542_0    conda-forge
certifi                   2020.12.5        py38h578d9bd_1    conda-forge
cffi                      1.14.5           py38ha65f79e_0    conda-forge
cfgv                      3.2.0                    pypi_0    pypi
chardet                   4.0.0            py38h578d9bd_1    conda-forge
click                     7.1.2              pyh9f0ad1d_0    conda-forge
cloudpickle               1.6.0                      py_0    conda-forge
colorama                  0.4.4              pyh9f0ad1d_0    conda-forge
comtypes                  1.1.9                    pypi_0    pypi
cookiecutter              1.7.2              pyh9f0ad1d_0    conda-forge
cryptography              3.4.7            py38ha5dfef3_0    conda-forge
curl                      7.76.1               h979ede3_1    conda-forge
cycler                    0.10.0                   pypi_0    pypi
dataclasses               0.8                pyhc8e2a94_1    conda-forge
dbus                      1.13.6               h48d8840_2    conda-forge
decorator                 5.0.7              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
diff-match-patch          20200713           pyh9f0ad1d_0    conda-forge
distlib                   0.3.1                    pypi_0    pypi
docformatter              1.4                      pypi_0    pypi
docutils                  0.17.1           py38h578d9bd_0    conda-forge
entrypoints               0.3             pyhd8ed1ab_1003    conda-forge
eradicate                 2.0.0                    pypi_0    pypi
expat                     2.3.0                h9c3ff4c_0    conda-forge
filelock                  3.0.12                   pypi_0    pypi
flake8                    3.8.4                      py_0    conda-forge
fontconfig                2.13.1            hba837de_1005    conda-forge
freetype                  2.10.4               h0708190_1    conda-forge
future                    0.18.2           py38h578d9bd_3    conda-forge
gettext                   0.19.8.1          h0b5b191_1005    conda-forge
git                       2.30.2          pl5320h24fefe6_1    conda-forge
glib                      2.68.1               h9c3ff4c_0    conda-forge
glib-tools                2.68.1               h9c3ff4c_0    conda-forge
gst-plugins-base          1.18.4               hf529b03_2    conda-forge
gstreamer                 1.18.4               h76c114f_2    conda-forge
icu                       68.1                 h58526e2_0    conda-forge
identify                  2.2.3                    pypi_0    pypi
idna                      2.10               pyh9f0ad1d_0    conda-forge
imagesize                 1.2.0                      py_0    conda-forge
importlib-metadata        4.0.1            py38h578d9bd_0    conda-forge
importlib_metadata        4.0.1                hd8ed1ab_0    conda-forge
inflection                0.5.1       pyh9f0ad1d_0    conda-forge
intervaltree              3.0.2                      py_0    conda-forge
ipykernel                 5.5.3            py38hd0cf306_0    conda-forge
ipython                   7.22.0           py38hd0cf306_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
isort                     5.8.0              pyhd8ed1ab_0    conda-forge
jedi                      0.17.2           py38h578d9bd_1    conda-forge
jeepney                   0.6.0              pyhd8ed1ab_0    conda-forge
jinja2                    2.11.3             pyh44b312d_0    conda-forge
jinja2-time               0.2.0                      py_2    conda-forge
jpeg                      9d                   h36c2ea0_0    conda-forge
jsonschema                3.2.0              pyhd8ed1ab_3    conda-forge
jupyter_client            6.1.12             pyhd8ed1ab_0    conda-forge
jupyter_core              4.7.1            py38h578d9bd_0    conda-forge
jupyterlab_pygments       0.1.2              pyh9f0ad1d_0    conda-forge
keyring                   23.0.1           py38h578d9bd_0    conda-forge
kiwisolver                1.3.1                    pypi_0    pypi
krb5                      1.17.2               h926e7f8_0    conda-forge
lazy-object-proxy         1.6.0            py38h497a2fe_0    conda-forge
ld_impl_linux-64          2.35.1               hea4e1c9_2    conda-forge
libclang                  11.1.0          default_ha53f305_0    conda-forge
libcurl                   7.76.1               hc4aaa36_1    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 h516909a_1    conda-forge
libevent                  2.1.10               hcdb4288_3    conda-forge
libffi                    3.3                  h58526e2_2    conda-forge
libgcc-ng                 9.3.0               h2828fa1_19    conda-forge
libglib                   2.68.1               h3e27bee_0    conda-forge
libgomp                   9.3.0               h2828fa1_19    conda-forge
libiconv                  1.16                 h516909a_0    conda-forge
libllvm11                 11.1.0               hf817b99_2    conda-forge
libnghttp2                1.43.0               h812cca2_0    conda-forge
libogg                    1.3.4                h7f98852_1    conda-forge
libopus                   1.3.1                h7f98852_1    conda-forge
libpng                    1.6.37               h21135ba_2    conda-forge
libpq                     13.2                 hfd2b0eb_2    conda-forge
libsodium                 1.0.18               h36c2ea0_1    conda-forge
libspatialindex           1.9.3                h9c3ff4c_3    conda-forge
libssh2                   1.9.0                ha56f1ee_6    conda-forge
libstdcxx-ng              9.3.0               h6de172a_19    conda-forge
libuuid                   2.32.1            h7f98852_1000    conda-forge
libvorbis                 1.3.7                h9c3ff4c_0    conda-forge
libxcb                    1.13              h7f98852_1003    conda-forge
libxkbcommon              1.0.3                he3ba5ed_0    conda-forge
libxml2                   2.9.10               h72842e0_4    conda-forge
lz4-c                     1.9.3                h9c3ff4c_0    conda-forge
markupsafe                1.1.1            py38h497a2fe_3    conda-forge
matplotlib                3.4.1                    pypi_0    pypi
mccabe                    0.6.1                      py_1    conda-forge
mistune                   0.8.4           py38h497a2fe_1003    conda-forge
mpmath                    1.2.1                    pypi_0    pypi
mypy_extensions           0.4.3            py38h578d9bd_3    conda-forge
mysql-common              8.0.23               ha770c72_1    conda-forge
mysql-libs                8.0.23               h935591d_1    conda-forge
nbclient                  0.5.3              pyhd8ed1ab_0    conda-forge
nbconvert                 6.0.7            py38h578d9bd_3    conda-forge
nbformat                  5.1.3              pyhd8ed1ab_0    conda-forge
ncurses                   6.2                  h58526e2_4    conda-forge
nest-asyncio              1.5.1              pyhd8ed1ab_0    conda-forge
nodeenv                   1.6.0                    pypi_0    pypi
nspr                      4.30                 h9c3ff4c_0    conda-forge
nss                       3.64                 hb5efdd6_0    conda-forge
numpydoc                  1.1.0                      py_1    conda-forge
openssl                   1.1.1k               h7f98852_0    conda-forge
packaging                 20.9               pyh44b312d_0    conda-forge
pandoc                    2.12                 h7f98852_0    conda-forge
pandocfilters             1.4.2                      py_1    conda-forge
parso                     0.7.0              pyh9f0ad1d_0    conda-forge
pathspec                  0.8.1              pyhd3deb0d_0    conda-forge
pcre                      8.44                 he1b5a44_0    conda-forge
perl                      5.32.0               h36c2ea0_0    conda-forge
pexpect                   4.8.0              pyh9f0ad1d_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    8.2.0                    pypi_0    pypi
pip                       21.1               pyhd8ed1ab_0    conda-forge
pipdeptree                2.0.0                    pypi_0    pypi
pkginfo                   1.7.0                    pypi_0    pypi
pluggy                    0.13.1           py38h578d9bd_4    conda-forge
poyo                      0.5.0                      py_0    conda-forge
pre-commit                2.12.0                   pypi_0    pypi
prescription              0.3.dev0                  dev_0    <develop>
prompt-toolkit            3.0.18             pyha770c72_0    conda-forge
psutil                    5.8.0            py38h497a2fe_1    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
py                        1.10.0                   pypi_0    pypi
pycodestyle               2.6.0              pyh9f0ad1d_0    conda-forge
pycparser                 2.20               pyh9f0ad1d_2    conda-forge
pydicom                   2.1.2                    pypi_0    pypi
pydocstyle                6.0.0              pyhd8ed1ab_0    conda-forge
pyflakes                  2.2.0              pyh9f0ad1d_0    conda-forge
pyftpdlib                 1.5.6                    pypi_0    pypi
pygls                     0.9.1                    pypi_0    pypi
pygments                  2.8.1              pyhd8ed1ab_0    conda-forge
pylint                    2.7.2            py38h578d9bd_0    conda-forge
pyls-black                0.4.6              pyh9f0ad1d_0    conda-forge
pyls-spyder               0.3.2              pyhd8ed1ab_0    conda-forge
pynacl                    1.4.0            py38h497a2fe_2    conda-forge
pyopenssl                 20.0.1             pyhd8ed1ab_0    conda-forge
pyparsing                 2.4.7              pyh9f0ad1d_0    conda-forge
pypatch                   1.0.1                    pypi_0    pypi
pyqt                      5.12.3           py38h578d9bd_7    conda-forge
pyqt-impl                 5.12.3           py38h7400c14_7    conda-forge
pyqt3d                    5.12.0                   pypi_0    pypi
pyqt5-sip                 4.19.18          py38h709712a_7    conda-forge
pyqtchart                 5.12             py38h7400c14_7    conda-forge
pyqtwebengine             5.12.1           py38h7400c14_7    conda-forge
pyrsistent                0.17.3           py38h497a2fe_2    conda-forge
pysocks                   1.7.1            py38h578d9bd_3    conda-forge
python                    3.8.8           hffdb5ce_0_cpython    conda-forge
python-dateutil           2.8.1                      py_0    conda-forge
python-jsonrpc-server     0.4.0              pyh9f0ad1d_0    conda-forge
python-language-server    0.36.2             pyhd8ed1ab_0    conda-forge
python-slugify            4.0.1              pyh9f0ad1d_0    conda-forge
python_abi                3.8                      1_cp38    conda-forge
pytz                      2021.1             pyhd8ed1ab_0    conda-forge
pyusb                     1.1.1                    pypi_0    pypi
pyxdg                     0.27                     pypi_0    pypi
pyyaml                    5.4.1                    pypi_0    pypi
pyzmq                     22.0.3           py38h2035c66_1    conda-forge
qdarkstyle                3.0.2              pyhd8ed1ab_0    conda-forge
qstylizer                 0.2.0              pyhd8ed1ab_1    conda-forge
qt                        5.12.9               hda022c4_4    conda-forge
qtawesome                 1.0.2              pyhd8ed1ab_0    conda-forge
qtconsole                 5.0.3              pyhd8ed1ab_0    conda-forge
qtpy                      1.9.0                      py_0    conda-forge
readline                  8.1                  h46c0cb4_0    conda-forge
readme-renderer           29.0                     pypi_0    pypi
regex                     2021.4.4         py38h497a2fe_0    conda-forge
requests                  2.25.1             pyhd3deb0d_0    conda-forge
requests-toolbelt         0.9.1                    pypi_0    pypi
rfc3986                   1.4.0                    pypi_0    pypi
rope                      0.18.0             pyhd3deb0d_0    conda-forge
rtree                     0.9.7            py38h02d302b_1    conda-forge
scspell3k                 2.2                      pypi_0    pypi
secretstorage             3.3.1            py38h578d9bd_0    conda-forge
setuptools                49.6.0           py38h578d9bd_3    conda-forge
six                       1.15.0             pyh9f0ad1d_0    conda-forge
snowballstemmer           2.1.0              pyhd8ed1ab_0    conda-forge
sortedcontainers          2.3.0              pyhd8ed1ab_0    conda-forge
sphinx                    3.5.3              pyhd8ed1ab_0    conda-forge
sphinxcontrib-applehelp   1.0.2                      py_0    conda-forge
sphinxcontrib-devhelp     1.0.2                      py_0    conda-forge
sphinxcontrib-htmlhelp    1.0.3                      py_0    conda-forge
sphinxcontrib-jsmath      1.0.1                      py_0    conda-forge
sphinxcontrib-qthelp      1.0.3                      py_0    conda-forge
sphinxcontrib-serializinghtml 1.1.4                      py_0    conda-forge
spyder                    5.0.1            py38h578d9bd_0    conda-forge
spyder-kernels            2.0.1            py38h578d9bd_0    conda-forge
sqlite                    3.35.5               h74cdb3f_0    conda-forge
sympy                     1.8                      pypi_0    pypi
testpath                  0.4.4                      py_0    conda-forge
text-unidecode            1.3                        py_0    conda-forge
textdistance              4.2.1              pyhd8ed1ab_0    conda-forge
textx                     2.3.0                    pypi_0    pypi
three-merge               0.1.1              pyh9f0ad1d_0    conda-forge
tinycss2                  1.1.0              pyhd8ed1ab_0    conda-forge
tk                        8.6.10               h21135ba_1    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
torm-console              2.3.dev0                  dev_0    <develop>
tornado                   6.1              py38h497a2fe_1    conda-forge
tox                       3.23.0                   pypi_0    pypi
tqdm                      4.60.0                   pypi_0    pypi
traitlets                 5.0.5                      py_0    conda-forge
twine                     3.4.1                    pypi_0    pypi
typed-ast                 1.4.3            py38h497a2fe_0    conda-forge
typing_extensions         3.7.4.3                    py_0    conda-forge
ujson                     4.0.2            py38h709712a_0    conda-forge
unidecode                 1.2.0              pyhd8ed1ab_0    conda-forge
untokenize                0.1.1                    pypi_0    pypi
urllib3                   1.26.4             pyhd8ed1ab_0    conda-forge
virtualenv                20.4.3                   pypi_0    pypi
watchdog                  1.0.2            py38h578d9bd_1    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.36.2             pyhd3deb0d_0    conda-forge
whichcraft                0.6.1                      py_0    conda-forge
wrapt                     1.12.1           py38h497a2fe_3    conda-forge
wurlitzer                 2.1.0            py38h578d9bd_0    conda-forge
xorg-libxau               1.0.9                h7f98852_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xz                        5.2.5                h516909a_1    conda-forge
yaml                      0.2.5                h516909a_0    conda-forge
yapf                      0.31.0             pyhd8ed1ab_0    conda-forge
zeromq                    4.3.4                h9c3ff4c_0    conda-forge
zipp                      3.4.1              pyhd8ed1ab_0    conda-forge
zlib                      1.2.11            h516909a_1010    conda-forge
zstd                      1.4.9                ha95c52a_0    conda-forge
```



Discussion:
I tried to configure the function below the new API, but didn't fix the error. Would you have an example of using this function or another way to fix this error?

def update_style(self):        
      """  This must be reimplemented by plugins that need to adjust their style. """        
      pass
Hey @dan123456-eng, thanks for reporting. So you're saying that when moving from the light to dark theme, the theme is not applied? 
That's right, when moving from light to dark the theme is not applied.

Resolving patch:
diff --git a/spyder/config/gui.py b/spyder/config/gui.py
--- a/spyder/config/gui.py
+++ b/spyder/config/gui.py
@@ -18,6 +18,7 @@
 from collections import namedtuple
 
 # Third party imports
+from qtconsole.styles import dark_color
 from qtpy import PYQT_VERSION
 from qtpy.QtCore import Qt
 from qtpy.QtGui import QFont, QFontDatabase, QKeySequence
@@ -29,8 +30,6 @@
 from spyder.utils import programs
 from spyder.utils import syntaxhighlighters as sh
 
-# Third-party imports
-from qtconsole.styles import dark_color
 
 # To save metadata about widget shortcuts (needed to build our
 # preferences page)
diff --git a/spyder/plugins/appearance/confpage.py b/spyder/plugins/appearance/confpage.py
--- a/spyder/plugins/appearance/confpage.py
+++ b/spyder/plugins/appearance/confpage.py
@@ -6,6 +6,7 @@
 
 """Appearance entry in Preferences."""
 
+from qtconsole.styles import dark_color
 from qtpy.QtCore import Slot
 from qtpy.QtWidgets import (QApplication, QDialog, QFontComboBox,
                             QGridLayout, QGroupBox, QMessageBox,
@@ -19,6 +20,7 @@
 from spyder.config.utils import is_gtk_desktop
 from spyder.plugins.appearance.widgets import SchemeEditor
 from spyder.utils import syntaxhighlighters
+from spyder.utils.palette import QStylePalette
 from spyder.widgets.simplecodeeditor import SimpleCodeEditor
 
 # Localization
@@ -172,11 +174,14 @@ def set_font(self, font, option):
     def apply_settings(self):
         self.set_option('selected', self.current_scheme)
         color_scheme = self.get_option('selected')
+
+        # A dark color scheme is characterized by a light font and viceversa
+        is_dark_color_scheme = not is_dark_font_color(color_scheme)
         ui_theme = self.get_option('ui_theme')
-        style_sheet = self.main.styleSheet()
+
         if ui_theme == 'automatic':
-            if ((not is_dark_font_color(color_scheme) and not style_sheet)
-                    or (is_dark_font_color(color_scheme) and style_sheet)):
+            if ((self.is_dark_interface() and not is_dark_color_scheme) or
+                    (not self.is_dark_interface() and is_dark_color_scheme)):
                 self.changed_options.add('ui_theme')
             elif 'ui_theme' in self.changed_options:
                 self.changed_options.remove('ui_theme')
@@ -199,8 +204,8 @@ def apply_settings(self):
                 self.update_preview()
         else:
             if 'ui_theme' in self.changed_options:
-                if (style_sheet and ui_theme == 'dark' or
-                        not style_sheet and ui_theme == 'light'):
+                if ((self.is_dark_interface() and ui_theme == 'dark') or
+                    (not self.is_dark_interface() and ui_theme == 'light')):
                     self.changed_options.remove('ui_theme')
 
             if 'ui_theme' not in self.changed_options:
@@ -425,3 +430,13 @@ def reset_to_default(self):
                 self.set_option(option, value)
 
             self.load_from_conf()
+
+    def is_dark_interface(self):
+        """
+        Check if our interface is dark independently from our config
+        system.
+
+        We need to do this because when applying settings we can't
+        detect correctly the current theme.
+        """
+        return dark_color(QStylePalette.COLOR_BACKGROUND_1)


Test patch: