Clean up config file format, modify how projects are launched, and add broken theme setting handling
This commit is contained in:
+2
-2
@@ -113,7 +113,7 @@ def tmpConf(tmpPath):
|
||||
theConf = Config()
|
||||
theConf.initConfig(tmpPath, tmpPath)
|
||||
theConf.setLastPath(tmpPath)
|
||||
theConf.guiLang = "en_GB"
|
||||
theConf.guiLocale = "en_GB"
|
||||
return theConf
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ def fncConf(fncPath):
|
||||
theConf = Config()
|
||||
theConf.initConfig(fncPath, fncPath)
|
||||
theConf.setLastPath(fncPath)
|
||||
theConf.guiLang = "en_GB"
|
||||
theConf.guiLocale = "en_GB"
|
||||
return theConf
|
||||
|
||||
|
||||
|
||||
+3
-1
@@ -35,6 +35,7 @@ class MockGuiMain(QObject):
|
||||
self.hasProject = True
|
||||
self.theProject = None
|
||||
self.mainStatus = MockStatusBar()
|
||||
self.projPath = ""
|
||||
|
||||
# Test Variables
|
||||
self.askResponse = True
|
||||
@@ -43,7 +44,7 @@ class MockGuiMain(QObject):
|
||||
|
||||
return
|
||||
|
||||
def releaseNotes(self):
|
||||
def postLaunchTasks(self, cmdOpen):
|
||||
return
|
||||
|
||||
def makeAlert(self, message, level=0, exception=None):
|
||||
@@ -61,6 +62,7 @@ class MockGuiMain(QObject):
|
||||
return
|
||||
|
||||
def openProject(self, projPath):
|
||||
self.projPath = projPath
|
||||
return
|
||||
|
||||
def rebuildIndex(self):
|
||||
|
||||
@@ -1,27 +1,32 @@
|
||||
[Meta]
|
||||
timestamp = 2022-11-10 11:10:10
|
||||
|
||||
[Main]
|
||||
timestamp = 2022-10-26 11:19:49
|
||||
theme = default
|
||||
syntax = default_light
|
||||
guifont =
|
||||
guifontsize = 11
|
||||
lastnotes = 0x0
|
||||
guilang = en_GB
|
||||
font =
|
||||
fontsize = 11
|
||||
localisation = en_GB
|
||||
hidevscroll = False
|
||||
hidehscroll = False
|
||||
lastnotes = 0x0
|
||||
lastpath = /home/vkbo
|
||||
|
||||
[Sizes]
|
||||
geometry = 1200, 650
|
||||
mainwindow = 1200, 650
|
||||
preferences = 700, 615
|
||||
projcols = 200, 60, 140
|
||||
projloadcols = 280, 60, 160
|
||||
mainpane = 300, 800
|
||||
viewpane = 500, 150
|
||||
outlinepane = 500, 150
|
||||
fullscreen = False
|
||||
|
||||
[Project]
|
||||
autosaveproject = 60
|
||||
autosavedoc = 30
|
||||
emphlabels = True
|
||||
backuppath =
|
||||
backuponclose = False
|
||||
askbeforebackup = True
|
||||
|
||||
[Editor]
|
||||
textfont = None
|
||||
@@ -61,12 +66,8 @@ highlightemph = True
|
||||
stopwhenidle = True
|
||||
useridletime = 300
|
||||
|
||||
[Backup]
|
||||
backuppath =
|
||||
backuponclose = False
|
||||
askbeforebackup = True
|
||||
|
||||
[State]
|
||||
fullscreen = False
|
||||
showrefpanel = True
|
||||
viewcomments = True
|
||||
viewsynopsis = True
|
||||
@@ -77,6 +78,3 @@ searchloop = False
|
||||
searchnextfile = False
|
||||
searchmatchcap = False
|
||||
|
||||
[Path]
|
||||
lastpath =
|
||||
|
||||
|
||||
@@ -1,27 +1,32 @@
|
||||
[Meta]
|
||||
timestamp = 2022-11-10 11:10:13
|
||||
|
||||
[Main]
|
||||
timestamp = 2022-10-26 11:19:51
|
||||
theme = default
|
||||
syntax = default_light
|
||||
guifont = Cantarell
|
||||
guifontsize = 12
|
||||
lastnotes = 0x0
|
||||
guilang = en_GB
|
||||
font = Cantarell
|
||||
fontsize = 12
|
||||
localisation = en_GB
|
||||
hidevscroll = True
|
||||
hidehscroll = True
|
||||
lastnotes = 0x0
|
||||
lastpath = /home/vkbo/Code/novelWriter/Source/tests/temp/function
|
||||
|
||||
[Sizes]
|
||||
geometry = 1200, 650
|
||||
mainwindow = 1200, 650
|
||||
preferences = 699, 614
|
||||
projcols = 200, 60, 140
|
||||
projloadcols = 280, 60, 160
|
||||
mainpane = 300, 800
|
||||
viewpane = 500, 150
|
||||
outlinepane = 500, 150
|
||||
fullscreen = False
|
||||
|
||||
[Project]
|
||||
autosaveproject = 40
|
||||
autosavedoc = 20
|
||||
emphlabels = True
|
||||
backuppath = some/dir
|
||||
backuponclose = True
|
||||
askbeforebackup = True
|
||||
|
||||
[Editor]
|
||||
textfont = None
|
||||
@@ -61,12 +66,8 @@ highlightemph = False
|
||||
stopwhenidle = True
|
||||
useridletime = 300
|
||||
|
||||
[Backup]
|
||||
backuppath = some/dir
|
||||
backuponclose = True
|
||||
askbeforebackup = True
|
||||
|
||||
[State]
|
||||
fullscreen = False
|
||||
showrefpanel = True
|
||||
viewcomments = True
|
||||
viewsynopsis = True
|
||||
@@ -77,6 +78,3 @@ searchloop = False
|
||||
searchnextfile = False
|
||||
searchmatchcap = False
|
||||
|
||||
[Path]
|
||||
lastpath =
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ def testBaseConfig_Localisation(fncPath, tstPaths):
|
||||
|
||||
i18nDir = fncPath / "i18n"
|
||||
i18nDir.mkdir()
|
||||
tstConf._nwLangPath = i18nDir
|
||||
tstConf._nwLangPath = str(i18nDir)
|
||||
|
||||
copyfile(tstPaths.filesDir / "nw_en_GB.qm", i18nDir / "nw_en_GB.qm")
|
||||
writeFile(i18nDir / "nw_en_GB.ts", "")
|
||||
@@ -254,17 +254,17 @@ def testBaseConfig_SettersGetters(tmpConf):
|
||||
# Window Size
|
||||
tmpConf.guiScale = 1.0
|
||||
tmpConf.setMainWinSize(1205, 655)
|
||||
assert tmpConf._confChanged is False
|
||||
assert tmpConf.mainWinSize == [1200, 650]
|
||||
|
||||
tmpConf.guiScale = 2.0
|
||||
tmpConf.setMainWinSize(70, 70)
|
||||
assert tmpConf.mainWinSize == [70, 70]
|
||||
assert tmpConf._winGeometry == [35, 35]
|
||||
assert tmpConf._mainWinSize == [35, 35]
|
||||
|
||||
tmpConf.guiScale = 1.0
|
||||
tmpConf.setMainWinSize(70, 70)
|
||||
assert tmpConf.mainWinSize == [70, 70]
|
||||
assert tmpConf._winGeometry == [70, 70]
|
||||
assert tmpConf._mainWinSize == [70, 70]
|
||||
|
||||
tmpConf.setMainWinSize(1200, 650)
|
||||
|
||||
@@ -272,12 +272,12 @@ def testBaseConfig_SettersGetters(tmpConf):
|
||||
tmpConf.guiScale = 2.0
|
||||
tmpConf.setPreferencesWinSize(70, 70)
|
||||
assert tmpConf.preferencesWinSize == [70, 70]
|
||||
assert tmpConf._prefGeometry == [35, 35]
|
||||
assert tmpConf._prefsWinSize == [35, 35]
|
||||
|
||||
tmpConf.guiScale = 1.0
|
||||
tmpConf.setPreferencesWinSize(70, 70)
|
||||
assert tmpConf.preferencesWinSize == [70, 70]
|
||||
assert tmpConf._prefGeometry == [70, 70]
|
||||
assert tmpConf._prefsWinSize == [70, 70]
|
||||
|
||||
tmpConf.setPreferencesWinSize(700, 615)
|
||||
|
||||
@@ -285,12 +285,12 @@ def testBaseConfig_SettersGetters(tmpConf):
|
||||
tmpConf.guiScale = 2.0
|
||||
tmpConf.setProjLoadColWidths([10, 20, 30])
|
||||
assert tmpConf.projLoadColWidths == [10, 20, 30]
|
||||
assert tmpConf._projColWidth == [5, 10, 15]
|
||||
assert tmpConf._projLoadCols == [5, 10, 15]
|
||||
|
||||
tmpConf.guiScale = 1.0
|
||||
tmpConf.setProjLoadColWidths([10, 20, 30])
|
||||
assert tmpConf.projLoadColWidths == [10, 20, 30]
|
||||
assert tmpConf._projColWidth == [10, 20, 30]
|
||||
assert tmpConf._projLoadCols == [10, 20, 30]
|
||||
|
||||
tmpConf.setProjLoadColWidths([200, 60, 140])
|
||||
|
||||
@@ -348,24 +348,6 @@ def testBaseConfig_SettersGetters(tmpConf):
|
||||
assert tmpConf.getTextMargin() == 80
|
||||
assert tmpConf.getTabWidth() == 80
|
||||
|
||||
# Flag Setters
|
||||
# ============
|
||||
|
||||
tmpConf.setShowRefPanel(False)
|
||||
assert tmpConf.showRefPanel is False
|
||||
tmpConf.setShowRefPanel(True)
|
||||
assert tmpConf.showRefPanel is True
|
||||
|
||||
tmpConf.setViewComments(False)
|
||||
assert tmpConf.viewComments is False
|
||||
tmpConf.setViewComments(True)
|
||||
assert tmpConf.viewComments is True
|
||||
|
||||
tmpConf.setViewSynopsis(False)
|
||||
assert tmpConf.viewSynopsis is False
|
||||
tmpConf.setViewSynopsis(True)
|
||||
assert tmpConf.viewSynopsis is True
|
||||
|
||||
# END Test testBaseConfig_SettersGetters
|
||||
|
||||
|
||||
|
||||
@@ -138,7 +138,6 @@ def testBaseInit_Options(monkeypatch, tmpPath):
|
||||
nwGUI = novelwriter.main(
|
||||
["--testmode", f"--config={tmpPath}", f"--data={tmpPath}", "sample/"]
|
||||
)
|
||||
assert novelwriter.CONFIG.cmdOpen == "sample/"
|
||||
assert nwGUI.closeMain() == "closeMain"
|
||||
|
||||
# END Test testBaseInit_Options
|
||||
|
||||
@@ -215,8 +215,6 @@ def testDlgPreferences_Main(qtbot, monkeypatch, nwGUI, fncPath, tstPaths):
|
||||
qtbot.mouseClick(nwPrefs.buttonBox.button(QDialogButtonBox.Ok), Qt.LeftButton)
|
||||
nwPrefs._doClose()
|
||||
|
||||
assert theConf._confChanged is True
|
||||
|
||||
assert nwGUI.mainConf.saveConfig()
|
||||
projFile = fncPath / "novelwriter.conf"
|
||||
testFile = tstPaths.outDir / "guiPreferences_novelwriter.conf"
|
||||
|
||||
@@ -21,15 +21,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
|
||||
from tools import C, cmpFiles, buildTestProject, XML_IGNORE, writeFile
|
||||
from shutil import copyfile
|
||||
|
||||
from tools import (
|
||||
C, cmpFiles, buildTestProject, XML_IGNORE, getGuiItem, writeFile
|
||||
)
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QMessageBox, QInputDialog
|
||||
from PyQt5.QtWidgets import QDialog, QMessageBox, QInputDialog
|
||||
|
||||
from novelwriter.enum import nwItemType, nwView, nwWidget
|
||||
from novelwriter.tools import GuiProjectWizard
|
||||
from novelwriter.dialogs import GuiEditLabel
|
||||
from novelwriter.dialogs import GuiEditLabel, GuiAbout, GuiProjectLoad
|
||||
from novelwriter.constants import nwFiles
|
||||
from novelwriter.gui.outline import GuiOutlineView
|
||||
from novelwriter.gui.projtree import GuiProjectTree
|
||||
@@ -62,7 +65,39 @@ def testGuiMain_ProjectBlocker(nwGUI):
|
||||
assert nwGUI.showProjectWordListDialog() is False
|
||||
assert nwGUI.showWritingStatsDialog() is False
|
||||
|
||||
# END Test testGuiMain_NoProject
|
||||
# END Test testGuiMain_ProjectBlocker
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiMain_Launch(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
"""Test the handling of launch tasks.
|
||||
"""
|
||||
monkeypatch.setattr(GuiProjectLoad, "exec_", lambda *a: None)
|
||||
monkeypatch.setattr(GuiProjectLoad, "result", lambda *a: QDialog.Accepted)
|
||||
nwGUI.mainConf.lastNotes = "0x0"
|
||||
|
||||
# Open Lipsum project
|
||||
nwGUI.postLaunchTasks(prjLipsum)
|
||||
nwGUI.closeProject()
|
||||
|
||||
# Check that release notes opened
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiAbout") is not None, timeout=1000)
|
||||
msgAbout = getGuiItem("GuiAbout")
|
||||
assert isinstance(msgAbout, GuiAbout)
|
||||
assert msgAbout.tabBox.currentWidget() == msgAbout.pageNotes
|
||||
msgAbout.accept()
|
||||
|
||||
# Check that project open dialog launches
|
||||
nwGUI.postLaunchTasks(None)
|
||||
qtbot.waitUntil(lambda: getGuiItem("GuiProjectLoad") is not None, timeout=1000)
|
||||
nwLoad = getGuiItem("GuiProjectLoad")
|
||||
assert isinstance(nwLoad, GuiProjectLoad)
|
||||
nwLoad.show()
|
||||
nwLoad.reject()
|
||||
|
||||
# qtbot.stop()
|
||||
|
||||
# END Test testGuiMain_Launch
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
|
||||
@@ -150,7 +150,10 @@ def testGuiTheme_Theme(qtbot, monkeypatch, nwGUI, fncPath):
|
||||
|
||||
# Check handling of broken theme settings
|
||||
mainConf.guiTheme = "not_a_theme"
|
||||
availThemes = mainTheme._availThemes
|
||||
mainTheme._availThemes = {}
|
||||
assert mainTheme.loadTheme() is False
|
||||
mainTheme._availThemes = availThemes
|
||||
|
||||
# Check handling of unreadable file
|
||||
mainConf.guiTheme = "default"
|
||||
@@ -216,8 +219,11 @@ def testGuiTheme_Syntax(qtbot, monkeypatch, nwGUI, fncPath):
|
||||
assert mainTheme.listSyntax() == mainTheme._syntaxList
|
||||
|
||||
# Check handling of broken theme settings
|
||||
availSyntax = mainTheme._availSyntax
|
||||
mainTheme._availSyntax = {}
|
||||
mainConf.guiSyntax = "not_a_syntax"
|
||||
assert mainTheme.loadSyntax() is False
|
||||
mainTheme._availSyntax = availSyntax
|
||||
|
||||
# Check handling of unreadable file
|
||||
mainConf.guiSyntax = "default_light"
|
||||
|
||||
Reference in New Issue
Block a user