Add remaining missing coverage and revert loadTheme return type
This commit is contained in:
@@ -270,8 +270,10 @@ class GuiTheme:
|
|||||||
return QColor(*result)
|
return QColor(*result)
|
||||||
return default
|
return default
|
||||||
|
|
||||||
def loadTheme(self, force: bool = False) -> None:
|
def loadTheme(self, force: bool = False) -> bool:
|
||||||
"""Load the currently specified GUI theme."""
|
"""Load the currently specified GUI theme. The boolean return
|
||||||
|
can be used to determine if the GUI needs refreshing.
|
||||||
|
"""
|
||||||
match CONFIG.themeMode:
|
match CONFIG.themeMode:
|
||||||
case nwTheme.LIGHT:
|
case nwTheme.LIGHT:
|
||||||
darkMode = False
|
darkMode = False
|
||||||
@@ -292,12 +294,12 @@ class GuiTheme:
|
|||||||
|
|
||||||
if theme == self._currentTheme and not force:
|
if theme == self._currentTheme and not force:
|
||||||
logger.info("Theme '%s' is already loaded", theme)
|
logger.info("Theme '%s' is already loaded", theme)
|
||||||
return
|
return False
|
||||||
|
|
||||||
entry = self._allThemes.get(theme)
|
entry = self._allThemes.get(theme)
|
||||||
if not entry:
|
if not entry:
|
||||||
logger.error("Could not load GUI theme")
|
logger.error("Could not load GUI theme")
|
||||||
return
|
return False
|
||||||
|
|
||||||
CONFIG.splashMessage(f"Loading colour theme: {entry.name}")
|
CONFIG.splashMessage(f"Loading colour theme: {entry.name}")
|
||||||
logger.info("Loading GUI theme '%s'", theme)
|
logger.info("Loading GUI theme '%s'", theme)
|
||||||
@@ -307,7 +309,7 @@ class GuiTheme:
|
|||||||
except Exception:
|
except Exception:
|
||||||
logger.error("Could not read file: %s", entry.path)
|
logger.error("Could not read file: %s", entry.path)
|
||||||
logException()
|
logException()
|
||||||
return
|
return False
|
||||||
|
|
||||||
# Reset Palette
|
# Reset Palette
|
||||||
self._resetTheme()
|
self._resetTheme()
|
||||||
@@ -477,7 +479,7 @@ class GuiTheme:
|
|||||||
QApplication.setPalette(self._guiPalette)
|
QApplication.setPalette(self._guiPalette)
|
||||||
self._buildStyleSheets(self._guiPalette)
|
self._buildStyleSheets(self._guiPalette)
|
||||||
|
|
||||||
return
|
return True
|
||||||
|
|
||||||
def getStyleSheet(self, name: str) -> str:
|
def getStyleSheet(self, name: str) -> str:
|
||||||
"""Load a standard style sheet."""
|
"""Load a standard style sheet."""
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ from novelwriter.common import (
|
|||||||
readTextFile, simplified, transferCase, uniqueCompact, xmlElement,
|
readTextFile, simplified, transferCase, uniqueCompact, xmlElement,
|
||||||
xmlIndent, xmlSubElem, yesNo
|
xmlIndent, xmlSubElem, yesNo
|
||||||
)
|
)
|
||||||
|
from novelwriter.enum import nwItemClass
|
||||||
|
|
||||||
from tests.mocked import causeOSError
|
from tests.mocked import causeOSError
|
||||||
from tests.tools import writeFile
|
from tests.tools import writeFile
|
||||||
@@ -804,6 +805,7 @@ def testBaseCommon_NWConfigParser(fncPath):
|
|||||||
"list1 = a, b, c\n"
|
"list1 = a, b, c\n"
|
||||||
"list2 = 17, 18, 19\n"
|
"list2 = 17, 18, 19\n"
|
||||||
"float1 = 4.2\n"
|
"float1 = 4.2\n"
|
||||||
|
"enum1 = NOVEL\n"
|
||||||
f"path1 = {fncPath}\n"
|
f"path1 = {fncPath}\n"
|
||||||
))
|
))
|
||||||
|
|
||||||
@@ -875,3 +877,7 @@ def testBaseCommon_NWConfigParser(fncPath):
|
|||||||
|
|
||||||
assert cfgParser.rdIntList("nope", "list2", [1]) == [1]
|
assert cfgParser.rdIntList("nope", "list2", [1]) == [1]
|
||||||
assert cfgParser.rdIntList("main", "blabla", [1]) == [1]
|
assert cfgParser.rdIntList("main", "blabla", [1]) == [1]
|
||||||
|
|
||||||
|
# Read Enum
|
||||||
|
assert cfgParser.rdEnum("main", "enum1", nwItemClass.NO_CLASS) == nwItemClass.NOVEL
|
||||||
|
assert cfgParser.rdEnum("main", "blabla", nwItemClass.NO_CLASS) == nwItemClass.NO_CLASS
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import shutil
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
from unittest.mock import Mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ from PyQt6.QtGui import QPalette
|
|||||||
from PyQt6.QtWidgets import QInputDialog, QMessageBox
|
from PyQt6.QtWidgets import QInputDialog, QMessageBox
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
|
from novelwriter.config import DEF_GUI_DARK, DEF_GUI_LIGHT
|
||||||
from novelwriter.constants import nwFiles
|
from novelwriter.constants import nwFiles
|
||||||
from novelwriter.dialogs.editlabel import GuiEditLabel
|
from novelwriter.dialogs.editlabel import GuiEditLabel
|
||||||
from novelwriter.enum import nwDocAction, nwDocMode, nwFocus, nwItemType, nwTheme, nwView
|
from novelwriter.enum import nwDocAction, nwDocMode, nwFocus, nwItemType, nwTheme, nwView
|
||||||
@@ -179,22 +181,35 @@ def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
|||||||
@pytest.mark.gui
|
@pytest.mark.gui
|
||||||
def testGuiMain_UpdateTheme(qtbot, nwGUI):
|
def testGuiMain_UpdateTheme(qtbot, nwGUI):
|
||||||
"""Test updating the theme in the GUI."""
|
"""Test updating the theme in the GUI."""
|
||||||
mainTheme = SHARED.theme
|
theme = SHARED.theme
|
||||||
CONFIG.themeMode = nwTheme.DARK
|
CONFIG.themeMode = nwTheme.DARK
|
||||||
CONFIG.darkTheme = "default_dark"
|
CONFIG.darkTheme = DEF_GUI_DARK
|
||||||
CONFIG.lightTheme = "default_light"
|
CONFIG.lightTheme = DEF_GUI_LIGHT
|
||||||
mainTheme.loadTheme()
|
theme.loadTheme()
|
||||||
|
assert theme.isDarkTheme is True
|
||||||
|
|
||||||
nwGUI._processConfigChanges(False, True, False, False)
|
nwGUI._processConfigChanges(False, True, False, False)
|
||||||
nwGUI._processConfigChanges(True, True, True, True)
|
nwGUI._processConfigChanges(True, True, True, True)
|
||||||
|
|
||||||
|
# Check editor syntax
|
||||||
syntax = SHARED.theme.syntaxTheme
|
syntax = SHARED.theme.syntaxTheme
|
||||||
|
|
||||||
assert nwGUI.docEditor.palette().color(QPalette.ColorRole.Window) == syntax.back
|
assert nwGUI.docEditor.palette().color(QPalette.ColorRole.Window) == syntax.back
|
||||||
assert nwGUI.docEditor.docHeader.palette().color(QPalette.ColorRole.Window) == syntax.back
|
assert nwGUI.docEditor.docHeader.palette().color(QPalette.ColorRole.Window) == syntax.back
|
||||||
assert nwGUI.docViewer.palette().color(QPalette.ColorRole.Window) == syntax.back
|
assert nwGUI.docViewer.palette().color(QPalette.ColorRole.Window) == syntax.back
|
||||||
assert nwGUI.docViewer.docHeader.palette().color(QPalette.ColorRole.Window) == syntax.back
|
assert nwGUI.docViewer.docHeader.palette().color(QPalette.ColorRole.Window) == syntax.back
|
||||||
|
|
||||||
|
# Update by check
|
||||||
|
CONFIG.themeMode = nwTheme.LIGHT
|
||||||
|
nwGUI.checkThemeUpdate()
|
||||||
|
assert theme.isDarkTheme is False
|
||||||
|
|
||||||
|
# Through change event
|
||||||
|
event = Mock()
|
||||||
|
event.type.return_value = 210
|
||||||
|
CONFIG.themeMode = nwTheme.DARK
|
||||||
|
nwGUI.changeEvent(event)
|
||||||
|
assert theme.isDarkTheme is True
|
||||||
|
|
||||||
# qtbot.stop()
|
# qtbot.stop()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user