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)
|
||||
|
||||
sys.exit(nwApp.exec())
|
||||
|
||||
return None
|
||||
|
||||
@@ -39,7 +39,7 @@ from PyQt5.QtCore import (
|
||||
from PyQt5.QtGui import QFont, QFontDatabase
|
||||
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.error import formatException, logException
|
||||
|
||||
@@ -109,7 +109,7 @@ class Config:
|
||||
self.guiLocale = self._qLocale.name()
|
||||
self.guiTheme = "default" # GUI 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.hideVScroll = False # Hide vertical scroll bars on main widgets
|
||||
self.hideHScroll = False # Hide horizontal scroll bars on main widgets
|
||||
@@ -377,6 +377,7 @@ class Config:
|
||||
else:
|
||||
font = fontDB.systemFont(QFontDatabase.SystemFont.GeneralFont)
|
||||
self.guiFont = font
|
||||
logger.debug("GUI font set to: %s", describeFont(font))
|
||||
|
||||
QApplication.setFont(self.guiFont)
|
||||
|
||||
@@ -405,6 +406,7 @@ class Config:
|
||||
else:
|
||||
font = fontDB.systemFont(QFontDatabase.SystemFont.GeneralFont)
|
||||
self.textFont = font
|
||||
logger.debug("Text font set to: %s", describeFont(font))
|
||||
return
|
||||
|
||||
##
|
||||
@@ -571,8 +573,9 @@ class Config:
|
||||
|
||||
if not cnfPath.exists():
|
||||
# Initial file, so we just create one from defaults
|
||||
self.saveConfig()
|
||||
self.setGuiFont(None)
|
||||
self.setTextFont(None)
|
||||
self.saveConfig()
|
||||
return True
|
||||
|
||||
try:
|
||||
|
||||
@@ -28,16 +28,16 @@ from xml.etree import ElementTree as ET
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtCore import QUrl
|
||||
from PyQt5.QtGui import QColor, QDesktopServices
|
||||
from PyQt5.QtGui import QColor, QDesktopServices, QFontDatabase
|
||||
|
||||
from novelwriter.common import (
|
||||
NWConfigParser, checkBool, checkFloat, checkInt, checkIntTuple, checkPath,
|
||||
checkString, checkStringNone, checkUuid, cssCol, elide, formatFileFilter,
|
||||
formatInt, formatTime, formatTimeStamp, formatVersion, fuzzyTime,
|
||||
getFileSize, hexToInt, isHandle, isItemClass, isItemLayout, isItemType,
|
||||
isListInstance, isTitleTag, jsonEncode, makeFileNameSafe, minmax,
|
||||
numberToRoman, openExternalPath, readTextFile, simplified, transferCase,
|
||||
xmlIndent, yesNo
|
||||
checkString, checkStringNone, checkUuid, cssCol, describeFont, elide,
|
||||
formatFileFilter, formatInt, formatTime, formatTimeStamp, formatVersion,
|
||||
fuzzyTime, getFileSize, hexToInt, isHandle, isItemClass, isItemLayout,
|
||||
isItemType, isListInstance, isTitleTag, jsonEncode, makeFileNameSafe,
|
||||
minmax, numberToRoman, openExternalPath, readTextFile, simplified,
|
||||
transferCase, xmlIndent, yesNo
|
||||
)
|
||||
|
||||
from tests.mocked import causeOSError
|
||||
@@ -487,6 +487,15 @@ def testBaseCommon_cssCol():
|
||||
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
|
||||
def testBaseCommon_jsonEncode():
|
||||
"""Test the jsonEncode function."""
|
||||
|
||||
Reference in New Issue
Block a user