From 692159219ee50ec4ebb846785335968d30bacfa6 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Fri, 15 Jan 2021 10:40:19 +0100 Subject: [PATCH 1/4] Fix an issue with generated files in test projects in the test suite --- tests/conftest.py | 84 +++++++++++++++++++++++++---------------------- tests/tools.py | 24 ++++++++++++++ 2 files changed, 68 insertions(+), 40 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index bab0d4f6..670085d5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,6 +8,7 @@ import shutil import os from dummy import DummyMain +from tools import cleanProject sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) @@ -129,21 +130,20 @@ def nwGUI(qtbot, fncDir): def nwMinimal(tmpDir): """A minimal novelWriter example project. """ - testDir = os.path.dirname(__file__) - minimalStore = os.path.join(testDir, "minimal") - minimalDir = os.path.join(tmpDir, "minimal") - if os.path.isdir(minimalDir): - shutil.rmtree(minimalDir) - shutil.copytree(minimalStore, minimalDir) - cacheDir = os.path.join(minimalDir, "cache") - if os.path.isdir(cacheDir): - shutil.rmtree(cacheDir) - metaDir = os.path.join(minimalDir, "meta") - if os.path.isdir(metaDir): - shutil.rmtree(metaDir) - yield minimalDir - if os.path.isdir(minimalDir): - shutil.rmtree(minimalDir) + tstDir = os.path.dirname(__file__) + srcDir = os.path.join(tstDir, "minimal") + dstDir = os.path.join(tmpDir, "minimal") + if os.path.isdir(dstDir): + shutil.rmtree(dstDir) + + shutil.copytree(srcDir, dstDir) + cleanProject(dstDir) + + yield dstDir + + if os.path.isdir(dstDir): + shutil.rmtree(dstDir) + return @pytest.fixture(scope="function") @@ -151,34 +151,38 @@ def nwLipsum(tmpDir): """A medium sized novelWriter example project with a lot of Lorem Ipsum dummy text. """ - testDir = os.path.dirname(__file__) - lipsumStore = os.path.join(testDir, "lipsum") - lipsumDir = os.path.join(tmpDir, "lipsum") - if os.path.isdir(lipsumDir): - shutil.rmtree(lipsumDir) - shutil.copytree(lipsumStore, lipsumDir) - cacheDir = os.path.join(lipsumDir, "cache") - if os.path.isdir(cacheDir): - shutil.rmtree(cacheDir) - metaDir = os.path.join(lipsumDir, "meta") - if os.path.isdir(metaDir): - shutil.rmtree(metaDir) - yield lipsumDir - if os.path.isdir(lipsumDir): - shutil.rmtree(lipsumDir) + tstDir = os.path.dirname(__file__) + srcDir = os.path.join(tstDir, "lipsum") + dstDir = os.path.join(tmpDir, "lipsum") + if os.path.isdir(dstDir): + shutil.rmtree(dstDir) + + shutil.copytree(srcDir, dstDir) + cleanProject(dstDir) + + yield dstDir + + if os.path.isdir(dstDir): + shutil.rmtree(dstDir) + return @pytest.fixture(scope="function") def nwOldProj(tmpDir): - """A minimal movelWriter project using the old folder structure. + """A minimal movelWriter project using the old folder structure used + for storage versions < 1.2. """ - testDir = os.path.dirname(__file__) - oldProjStore = os.path.join(testDir, "oldproj") - oldProjDir = os.path.join(tmpDir, "oldproj") - if os.path.isdir(oldProjDir): - shutil.rmtree(oldProjDir) - shutil.copytree(oldProjStore, oldProjDir) - yield oldProjDir - if os.path.isdir(oldProjDir): - shutil.rmtree(oldProjDir) + tstDir = os.path.dirname(__file__) + srcDir = os.path.join(tstDir, "oldproj") + dstDir = os.path.join(tmpDir, "oldproj") + if os.path.isdir(dstDir): + shutil.rmtree(dstDir) + + shutil.copytree(srcDir, dstDir) + + yield dstDir + + if os.path.isdir(dstDir): + shutil.rmtree(dstDir) + return diff --git a/tests/tools.py b/tests/tools.py index 185a9fa0..d55a1e4e 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -2,6 +2,9 @@ """novelWriter Test Tools """ +import os +import shutil + from itertools import chain from PyQt5.QtWidgets import qApp @@ -82,3 +85,24 @@ def writeFile(fileName, fileData): """ with open(fileName, mode="w", encoding="utf8") as outFile: outFile.write(fileData) + +def cleanProject(projPath): + """Delete all generated files in a project. + """ + cacheDir = os.path.join(projPath, "cache") + if os.path.isdir(cacheDir): + shutil.rmtree(cacheDir) + + metaDir = os.path.join(projPath, "meta") + if os.path.isdir(metaDir): + shutil.rmtree(metaDir) + + bakFile = os.path.join(projPath, "nwProject.bak") + if os.path.isfile(bakFile): + os.unlink(bakFile) + + tocFile = os.path.join(projPath, "ToC.txt") + if os.path.isfile(tocFile): + os.unlink(tocFile) + + return From bde2810c088295de5e5bdc4bfb52d037a133d037 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Fri, 15 Jan 2021 10:40:41 +0100 Subject: [PATCH 2/4] Clear window title when closing a project --- nw/guimain.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nw/guimain.py b/nw/guimain.py index 70879986..49d2d2bb 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -90,7 +90,7 @@ class GuiMain(QMainWindow): # Prepare Main Window self.resize(*self.mainConf.getWinSize()) - self._setWindowTitle() + self._updateWindowTitle() self.setWindowIcon(QIcon(self.mainConf.appIcon)) # Build the GUI @@ -259,9 +259,11 @@ class GuiMain(QMainWindow): # Work Area self.docEditor.clearEditor() self.closeDocViewer() + self.projMeta.clearDetails() # General self.statusBar.clearStatus() + self._updateWindowTitle() return True @@ -357,7 +359,6 @@ class GuiMain(QMainWindow): self.closeDocument() self.docViewer.clearNavHistory() self.projView.closeOutline() - self.projMeta.clearDetails() self.theProject.closeProject() self.theIndex.clearIndex() self.clearGUI() @@ -429,7 +430,7 @@ class GuiMain(QMainWindow): self.theIndex.loadIndex() # Update GUI - self._setWindowTitle(self.theProject.projName) + self._updateWindowTitle(self.theProject.projName) self.rebuildTree() self.docEditor.setDictionaries() self.docEditor.setSpellCheck(self.theProject.spellCheck) @@ -899,7 +900,7 @@ class GuiMain(QMainWindow): if dlgProj.result() == QDialog.Accepted: logger.debug("Applying new project settings") self.docEditor.setDictionaries() - self._setWindowTitle(self.theProject.projName) + self._updateWindowTitle(self.theProject.projName) return @@ -1208,7 +1209,7 @@ class GuiMain(QMainWindow): return True - def _setWindowTitle(self, projName=None): + def _updateWindowTitle(self, projName=None): """Set the window title and add the project's working title. """ winTitle = self.mainConf.appName From 053c2eb379274adead5f75be8b48d83bc667af6e Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Fri, 15 Jan 2021 10:47:50 +0100 Subject: [PATCH 3/4] Set window title after new project is created, and also automatically call close if a project is open. --- nw/guimain.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/nw/guimain.py b/nw/guimain.py index 49d2d2bb..f8e9b9b2 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -282,11 +282,12 @@ class GuiMain(QMainWindow): """Create new project via the new project wizard. """ if self.hasProject: - self.makeAlert( - "Please close the current project before making a new one.", - nwAlert.ERROR - ) - return False + if not self.closeProject(): + self.makeAlert( + "Cannot create new project when another project is open.", + nwAlert.ERROR + ) + return False if projData is None: projData = self.showNewProjectDialog() @@ -313,6 +314,7 @@ class GuiMain(QMainWindow): self.hasProject = True self.statusBar.setRefTime(self.theProject.projOpened) self.rebuildIndex(beQuiet=True) + self._updateWindowTitle(self.theProject.projName) else: self.theProject.clearProject() return False From ecb9e92c48ee775b02bd061b009c166214d68f09 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Fri, 15 Jan 2021 19:27:19 +0100 Subject: [PATCH 4/4] Clear statusbar on new project, and change colors of saved indicators on light desktop --- nw/assets/themes/gui/default_dark/theme.conf | 1 - nw/gui/theme.py | 8 +++----- nw/guimain.py | 7 ++++++- tests/test_gui_theme.py | 1 - 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/nw/assets/themes/gui/default_dark/theme.conf b/nw/assets/themes/gui/default_dark/theme.conf index 9d41dbcf..14d0ad51 100644 --- a/nw/assets/themes/gui/default_dark/theme.conf +++ b/nw/assets/themes/gui/default_dark/theme.conf @@ -23,7 +23,6 @@ link = 44, 152, 247 linkvisited = 44, 152, 247 [GUI] -treewordcount = 197, 200, 198 statusnone = 150, 152, 150 statussaved = 39, 135, 78 statusunsaved = 138, 32, 32 diff --git a/nw/gui/theme.py b/nw/gui/theme.py index 61e2fca7..2b0f4608 100644 --- a/nw/gui/theme.py +++ b/nw/gui/theme.py @@ -76,11 +76,10 @@ class GuiTheme: self.themeLicenseUrl = "" ## GUI - self.treeWCount = [0, 0, 0] self.statNone = [120, 120, 120] - self.statUnsaved = [120, 120, 40] - self.statSaved = [40, 120, 0] - self.helpText = [0, 0, 0] + self.statUnsaved = [200, 15, 39] + self.statSaved = [2, 133, 37] + self.helpText = [0, 0, 0] # Loaded Syntax Settings @@ -309,7 +308,6 @@ class GuiTheme: ## GUI cnfSec = "GUI" if confParser.has_section(cnfSec): - self.treeWCount = self._loadColour(confParser, cnfSec, "treewordcount") self.statNone = self._loadColour(confParser, cnfSec, "statusnone") self.statUnsaved = self._loadColour(confParser, cnfSec, "statusunsaved") self.statSaved = self._loadColour(confParser, cnfSec, "statussaved") diff --git a/nw/guimain.py b/nw/guimain.py index f8e9b9b2..8f209717 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -258,6 +258,7 @@ class GuiMain(QMainWindow): # Work Area self.docEditor.clearEditor() + self.docEditor.setDictionaries() self.closeDocViewer() self.projMeta.clearDetails() @@ -312,8 +313,12 @@ class GuiMain(QMainWindow): self.rebuildTree() self.saveProject() self.hasProject = True - self.statusBar.setRefTime(self.theProject.projOpened) + self.docEditor.setDictionaries() self.rebuildIndex(beQuiet=True) + self.statusBar.setRefTime(self.theProject.projOpened) + self.statusBar.setProjectStatus(True) + self.statusBar.setDocumentStatus(None) + self.statusBar.setStatus("New project created ...") self._updateWindowTitle(self.theProject.projName) else: self.theProject.clearProject() diff --git a/tests/test_gui_theme.py b/tests/test_gui_theme.py index 4214af59..b774f2b9 100644 --- a/tests/test_gui_theme.py +++ b/tests/test_gui_theme.py @@ -73,7 +73,6 @@ def testGuiTheme_Main(qtbot, monkeypatch, nwMinimal, tmpDir): assert thePalette.link().color() == QColor(44, 152, 247) assert thePalette.linkVisited().color() == QColor(44, 152, 247) - assert nwGUI.theTheme.treeWCount == [197, 200, 198] assert nwGUI.theTheme.statNone == [150, 152, 150] assert nwGUI.theTheme.statSaved == [39, 135, 78] assert nwGUI.theTheme.statUnsaved == [138, 32, 32]