diff --git a/nw/core/project.py b/nw/core/project.py index 36589f3c..3943f50c 100644 --- a/nw/core/project.py +++ b/nw/core/project.py @@ -255,6 +255,8 @@ class NWProject(): self.setBookTitle(projTitle) self.setBookAuthors(projAuthors) + aDoc = NWDoc(self, self.theParent) + if popMinimal: # Creating a minimal project with a few root folders and a # single chapter folder with a single file. @@ -263,11 +265,24 @@ class NWProject(): xHandle = self.newRoot("Characters", nwItemClass.CHARACTER) xHandle = self.newRoot("World", nwItemClass.WORLD) tHandle = self.newFile("Title Page", nwItemClass.NOVEL, nHandle) - cHandle = self.newFolder("New Chapter", nwItemClass.NOVEL, nHandle) - fHandle = self.newFile("New Chapter", nwItemClass.NOVEL, cHandle) - XHandle = self.newFile("New Scene", nwItemClass.NOVEL, cHandle) + dHandle = self.newFolder("New Chapter", nwItemClass.NOVEL, nHandle) + cHandle = self.newFile("New Chapter", nwItemClass.NOVEL, dHandle) + sHandle = self.newFile("New Scene", nwItemClass.NOVEL, dHandle) + self.projTree.setFileItemLayout(tHandle, nwItemLayout.TITLE) - self.projTree.setFileItemLayout(fHandle, nwItemLayout.CHAPTER) + self.projTree.setFileItemLayout(cHandle, nwItemLayout.CHAPTER) + + aDoc.openDocument(tHandle, showStatus=False) + aDoc.saveDocument("# %s\n\n" % projName) + aDoc.clearDocument() + + aDoc.openDocument(cHandle, showStatus=False) + aDoc.saveDocument("## New Chapter\n\n") + aDoc.clearDocument() + + aDoc.openDocument(sHandle, showStatus=False) + aDoc.saveDocument("### New Scene\n\n") + aDoc.clearDocument() elif popCustom: # Create a project structure based on selected root folders @@ -284,6 +299,10 @@ class NWProject(): tHandle = self.newFile("Title Page", nwItemClass.NOVEL, nHandle) self.projTree.setFileItemLayout(tHandle, nwItemLayout.TITLE) + aDoc.openDocument(tHandle, showStatus=False) + aDoc.saveDocument("# %s\n\n" % projName) + aDoc.clearDocument() + # Create chapters and scenes numChapters = projData.get("numChapters", 0) numScenes = projData.get("numScenes", 0) @@ -296,21 +315,34 @@ class NWProject(): pHandle = nHandle if chFolders: pHandle = self.newFolder(chTitle, nwItemClass.NOVEL, nHandle) + cHandle = self.newFile(chTitle, nwItemClass.NOVEL, pHandle) self.projTree.setFileItemLayout(cHandle, nwItemLayout.CHAPTER) + aDoc.openDocument(cHandle, showStatus=False) + aDoc.saveDocument("## %s\n\n" % chTitle) + aDoc.clearDocument() + # Create chapter scenes if numScenes > 0: for sc in range(numScenes): scTitle = "Scene %d.%d" % (ch+1, sc+1) sHandle = self.newFile(scTitle, nwItemClass.NOVEL, pHandle) + aDoc.openDocument(sHandle, showStatus=False) + aDoc.saveDocument("### %s\n\n" % scTitle) + aDoc.clearDocument() + # Create scenes (no chapters) elif numScenes > 0: for sc in range(numScenes): scTitle = "Scene %d" % (sc+1) sHandle = self.newFile(scTitle, nwItemClass.NOVEL, nHandle) + aDoc.openDocument(sHandle, showStatus=False) + aDoc.saveDocument("### %s\n\n" % scTitle) + aDoc.clearDocument() + else: # Fallback just in case. We shouldn't reach here. self.newRoot("Novel", nwItemClass.NOVEL) diff --git a/nw/guimain.py b/nw/guimain.py index 12a17c30..175b29c1 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -300,6 +300,7 @@ class GuiMain(QMainWindow): self.saveProject() self.hasProject = True self.statusBar.setRefTime(self.theProject.projOpened) + self.rebuildIndex(beQuiet=True) else: self.theProject.clearProject() return False @@ -700,7 +701,7 @@ class GuiMain(QMainWindow): self.treeView.buildTree() return - def rebuildIndex(self): + def rebuildIndex(self, beQuiet=False): """Rebuild the entire index. """ if not self.hasProject: @@ -743,7 +744,7 @@ class GuiMain(QMainWindow): qApp.restoreOverrideCursor() - if self.mainConf.showGUI: + if self.mainConf.showGUI and not beQuiet: self.makeAlert("The project index has been successfully rebuilt.", nwAlert.INFO) return True diff --git a/tests/nwdummy.py b/tests/nwdummy.py index 2c54a92a..880a54eb 100644 --- a/tests/nwdummy.py +++ b/tests/nwdummy.py @@ -8,6 +8,7 @@ class DummyMain(): def __init__(self): self.mainConf = None + self.statusBar = StatusBar() return def makeAlert(self, theMessage, theLevel): @@ -33,3 +34,13 @@ class DummyMain(): return # END Class GuiMain + +class StatusBar(): + + def __init__(self): + return + + def setStatus(self, theText): + return + +# END Class StatusBar diff --git a/tests/reference/gui/0_nwProject.nwx b/tests/reference/gui/0_nwProject.nwx index 9ed7722a..4bd15d6f 100644 --- a/tests/reference/gui/0_nwProject.nwx +++ b/tests/reference/gui/0_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -13,8 +13,8 @@ True None None - 0 - 0 + 6 + 6 0 @@ -52,8 +52,8 @@ New True TITLE - 0 - 0 + 11 + 2 0 0 @@ -71,8 +71,8 @@ New True CHAPTER - 0 - 0 + 11 + 2 0 0 @@ -83,8 +83,8 @@ New True SCENE - 0 - 0 + 9 + 2 0 0 diff --git a/tests/reference/gui/1_nwProject.nwx b/tests/reference/gui/1_nwProject.nwx index 3dad289d..43dcf523 100644 --- a/tests/reference/gui/1_nwProject.nwx +++ b/tests/reference/gui/1_nwProject.nwx @@ -1,11 +1,11 @@ - + New Project - 4 + 5 1 - 13 + 14 True @@ -13,8 +13,8 @@ True 0e17daca5f3e1 None - 86 - 59 + 90 + 63 27 @@ -52,8 +52,8 @@ New True TITLE - 0 - 0 + 11 + 2 0 0 @@ -71,8 +71,8 @@ New True CHAPTER - 0 - 0 + 11 + 2 0 0 diff --git a/tests/reference/gui/2_nwProject.nwx b/tests/reference/gui/2_nwProject.nwx index dbeecf74..1e3a2ca3 100644 --- a/tests/reference/gui/2_nwProject.nwx +++ b/tests/reference/gui/2_nwProject.nwx @@ -1,13 +1,13 @@ - + Project Name Project Title Jane Doe John Doh - 1 + 2 1 - 1 + 0 True @@ -15,8 +15,8 @@ True None None - 0 - 0 + 6 + 6 0 With This Stuff @@ -56,8 +56,8 @@ New True TITLE - 0 - 0 + 11 + 2 0 0 @@ -75,8 +75,8 @@ New True CHAPTER - 0 - 0 + 11 + 2 0 0 @@ -87,8 +87,8 @@ New True SCENE - 0 - 0 + 9 + 2 0 0 diff --git a/tests/reference/gui/3_nwProject.nwx b/tests/reference/gui/3_nwProject.nwx index 92369f44..11be0c01 100644 --- a/tests/reference/gui/3_nwProject.nwx +++ b/tests/reference/gui/3_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -13,8 +13,8 @@ True 0e17daca5f3e1 None - 59 - 59 + 6 + 6 0 @@ -52,8 +52,8 @@ New True TITLE - 0 - 0 + 11 + 2 0 0 @@ -71,8 +71,8 @@ New True CHAPTER - 0 - 0 + 11 + 2 0 0 @@ -83,9 +83,9 @@ Note False PAGE - 331 - 59 - 2 + 9 + 2 + 0 0 diff --git a/tests/test_gui.py b/tests/test_gui.py index e282504a..821d96c1 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -14,8 +14,8 @@ from nw.gui import ( ) from nw.constants import * -keyDelay = 5 -stepDelay = 50 +keyDelay = 2 +stepDelay = 20 @pytest.mark.gui def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp): @@ -89,6 +89,7 @@ def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp): # Type something into the document nwGUI.setFocus(2) + qtbot.keyClick(nwGUI.docEditor, "a", modifier=Qt.ControlModifier, delay=keyDelay) for c in "# Jane Doe": qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay) qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) @@ -110,6 +111,7 @@ def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp): # Type something into the document nwGUI.setFocus(2) + qtbot.keyClick(nwGUI.docEditor, "a", modifier=Qt.ControlModifier, delay=keyDelay) for c in "# Main Plot": qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay) qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) @@ -136,6 +138,7 @@ def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp): # Type something into the document nwGUI.setFocus(2) + qtbot.keyClick(nwGUI.docEditor, "a", modifier=Qt.ControlModifier, delay=keyDelay) for c in "# Main Location": qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay) qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) @@ -158,6 +161,7 @@ def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp): # Type something into the document nwGUI.setFocus(2) + qtbot.keyClick(nwGUI.docEditor, "a", modifier=Qt.ControlModifier, delay=keyDelay) for c in "# Novel": qtbot.keyClick(nwGUI.docEditor, c, delay=keyDelay) qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) @@ -399,7 +403,7 @@ def testItemEditor(qtbot, nwTempGUI, nwRef, nwTemp): assert not nwGUI.docEditor.setCursorLine("where?") assert nwGUI.docEditor.setCursorLine(2) qtbot.wait(stepDelay) - assert nwGUI.docEditor.getCursorPosition() == 9 + assert nwGUI.docEditor.getCursorPosition() == 15 qtbot.wait(stepDelay) assert nwGUI.saveProject() @@ -438,10 +442,10 @@ def testWritingStatsExport(qtbot, nwTempGUI, nwRef, nwTemp): jsonData = json.loads(inFile.read()) assert len(jsonData) == 3 - assert jsonData[0]["length"] > 0 - assert jsonData[0]["newWords"] == 86 - assert jsonData[0]["novelWords"] == 59 - assert jsonData[0]["noteWords"] == 27 + assert jsonData[1]["length"] > 0 + assert jsonData[1]["newWords"] == 84 + assert jsonData[1]["novelWords"] == 63 + assert jsonData[1]["noteWords"] == 27 # No Novel Files qtbot.mouseClick(sessLog.incNovel, Qt.LeftButton) @@ -456,7 +460,7 @@ def testWritingStatsExport(qtbot, nwTempGUI, nwRef, nwTemp): assert len(jsonData) == 2 assert jsonData[0]["length"] > 0 assert jsonData[0]["newWords"] == 27 - assert jsonData[0]["novelWords"] == 59 + assert jsonData[0]["novelWords"] == 63 assert jsonData[0]["noteWords"] == 27 # No Note Files @@ -471,10 +475,10 @@ def testWritingStatsExport(qtbot, nwTempGUI, nwRef, nwTemp): jsonData = json.loads(inFile.read()) assert len(jsonData) == 3 - assert jsonData[0]["length"] > 0 - assert jsonData[0]["newWords"] == 59 - assert jsonData[0]["novelWords"] == 59 - assert jsonData[0]["noteWords"] == 27 + assert jsonData[1]["length"] > 0 + assert jsonData[1]["newWords"] == 57 + assert jsonData[1]["novelWords"] == 63 + assert jsonData[1]["noteWords"] == 27 # No Negative Entries qtbot.mouseClick(sessLog.incNotes, Qt.LeftButton) @@ -487,7 +491,7 @@ def testWritingStatsExport(qtbot, nwTempGUI, nwRef, nwTemp): with open(jsonStats, mode="r", encoding="utf-8") as inFile: jsonData = json.loads(inFile.read()) - assert len(jsonData) == 1 + assert len(jsonData) == 2 # Un-hide Zero Entries qtbot.mouseClick(sessLog.hideNegative, Qt.LeftButton)