Add font initialisation, and update tests
This commit is contained in:
@@ -241,5 +241,3 @@ def main(sysArgs: list | None = None) -> GuiMain | None:
|
|||||||
nwGUI.postLaunchTasks(cmdOpen)
|
nwGUI.postLaunchTasks(cmdOpen)
|
||||||
|
|
||||||
sys.exit(nwApp.exec())
|
sys.exit(nwApp.exec())
|
||||||
|
|
||||||
return None
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ from PyQt5.QtCore import (
|
|||||||
from PyQt5.QtGui import QFont, QFontDatabase
|
from PyQt5.QtGui import QFont, QFontDatabase
|
||||||
from PyQt5.QtWidgets import QApplication
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
|
||||||
from novelwriter.common import NWConfigParser, checkInt, checkPath, formatTimeStamp
|
from novelwriter.common import NWConfigParser, checkInt, checkPath, describeFont, formatTimeStamp
|
||||||
from novelwriter.constants import nwFiles, nwUnicode
|
from novelwriter.constants import nwFiles, nwUnicode
|
||||||
from novelwriter.error import formatException, logException
|
from novelwriter.error import formatException, logException
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ class Config:
|
|||||||
self.guiLocale = self._qLocale.name()
|
self.guiLocale = self._qLocale.name()
|
||||||
self.guiTheme = "default" # GUI theme
|
self.guiTheme = "default" # GUI theme
|
||||||
self.guiSyntax = "default_light" # Syntax theme
|
self.guiSyntax = "default_light" # Syntax theme
|
||||||
self.guiFont = QFont() # Defaults to system default font in theme class
|
self.guiFont = QFont() # Main GUI font
|
||||||
self.guiScale = 1.0 # Set automatically by Theme class
|
self.guiScale = 1.0 # Set automatically by Theme class
|
||||||
self.hideVScroll = False # Hide vertical scroll bars on main widgets
|
self.hideVScroll = False # Hide vertical scroll bars on main widgets
|
||||||
self.hideHScroll = False # Hide horizontal scroll bars on main widgets
|
self.hideHScroll = False # Hide horizontal scroll bars on main widgets
|
||||||
@@ -377,6 +377,7 @@ class Config:
|
|||||||
else:
|
else:
|
||||||
font = fontDB.systemFont(QFontDatabase.SystemFont.GeneralFont)
|
font = fontDB.systemFont(QFontDatabase.SystemFont.GeneralFont)
|
||||||
self.guiFont = font
|
self.guiFont = font
|
||||||
|
logger.debug("GUI font set to: %s", describeFont(font))
|
||||||
|
|
||||||
QApplication.setFont(self.guiFont)
|
QApplication.setFont(self.guiFont)
|
||||||
|
|
||||||
@@ -405,6 +406,7 @@ class Config:
|
|||||||
else:
|
else:
|
||||||
font = fontDB.systemFont(QFontDatabase.SystemFont.GeneralFont)
|
font = fontDB.systemFont(QFontDatabase.SystemFont.GeneralFont)
|
||||||
self.textFont = font
|
self.textFont = font
|
||||||
|
logger.debug("Text font set to: %s", describeFont(font))
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -571,8 +573,9 @@ class Config:
|
|||||||
|
|
||||||
if not cnfPath.exists():
|
if not cnfPath.exists():
|
||||||
# Initial file, so we just create one from defaults
|
# Initial file, so we just create one from defaults
|
||||||
self.saveConfig()
|
|
||||||
self.setGuiFont(None)
|
self.setGuiFont(None)
|
||||||
|
self.setTextFont(None)
|
||||||
|
self.saveConfig()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -28,16 +28,16 @@ from xml.etree import ElementTree as ET
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PyQt5.QtCore import QUrl
|
from PyQt5.QtCore import QUrl
|
||||||
from PyQt5.QtGui import QColor, QDesktopServices
|
from PyQt5.QtGui import QColor, QDesktopServices, QFontDatabase
|
||||||
|
|
||||||
from novelwriter.common import (
|
from novelwriter.common import (
|
||||||
NWConfigParser, checkBool, checkFloat, checkInt, checkIntTuple, checkPath,
|
NWConfigParser, checkBool, checkFloat, checkInt, checkIntTuple, checkPath,
|
||||||
checkString, checkStringNone, checkUuid, cssCol, elide, formatFileFilter,
|
checkString, checkStringNone, checkUuid, cssCol, describeFont, elide,
|
||||||
formatInt, formatTime, formatTimeStamp, formatVersion, fuzzyTime,
|
formatFileFilter, formatInt, formatTime, formatTimeStamp, formatVersion,
|
||||||
getFileSize, hexToInt, isHandle, isItemClass, isItemLayout, isItemType,
|
fuzzyTime, getFileSize, hexToInt, isHandle, isItemClass, isItemLayout,
|
||||||
isListInstance, isTitleTag, jsonEncode, makeFileNameSafe, minmax,
|
isItemType, isListInstance, isTitleTag, jsonEncode, makeFileNameSafe,
|
||||||
numberToRoman, openExternalPath, readTextFile, simplified, transferCase,
|
minmax, numberToRoman, openExternalPath, readTextFile, simplified,
|
||||||
xmlIndent, yesNo
|
transferCase, xmlIndent, yesNo
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests.mocked import causeOSError
|
from tests.mocked import causeOSError
|
||||||
@@ -487,6 +487,15 @@ def testBaseCommon_cssCol():
|
|||||||
assert cssCol(QColor(10, 20, 30, 40)) == "rgba(10, 20, 30, 40)"
|
assert cssCol(QColor(10, 20, 30, 40)) == "rgba(10, 20, 30, 40)"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.base
|
||||||
|
def testBaseCommon_describeFont():
|
||||||
|
"""Test the describeFont function."""
|
||||||
|
fontDB = QFontDatabase()
|
||||||
|
font = fontDB.systemFont(QFontDatabase.SystemFont.GeneralFont)
|
||||||
|
assert font.family() in describeFont(font)
|
||||||
|
assert describeFont(None) == "Error" # type: ignore
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.base
|
@pytest.mark.base
|
||||||
def testBaseCommon_jsonEncode():
|
def testBaseCommon_jsonEncode():
|
||||||
"""Test the jsonEncode function."""
|
"""Test the jsonEncode function."""
|
||||||
|
|||||||
Reference in New Issue
Block a user