Merge pull request #12 from vkbo/save_cursor

Save Cursor Position
This commit is contained in:
Veronica K. Berglyd Olsen
2019-05-18 15:13:40 +02:00
committed by GitHub
16 changed files with 160 additions and 89 deletions
+26 -8
View File
@@ -100,7 +100,7 @@ class GuiDocEditor(QTextEdit):
return return
## ##
# Class Methods # Setters and Getters
## ##
def setDocumentChanged(self, bValue): def setDocumentChanged(self, bValue):
@@ -116,6 +116,24 @@ class GuiDocEditor(QTextEdit):
self.setDocumentChanged(False) self.setDocumentChanged(False)
return True return True
def getText(self):
theText = self.toPlainText()
return theText
def setCursorPosition(self, thePosition):
theCursor = self.textCursor()
theCursor.setPosition(thePosition)
self.setTextCursor(theCursor)
return True
def getCursorPosition(self):
theCursor = self.textCursor()
return theCursor.position()
##
# Spell Checking
##
def setPwl(self, pwlFile): def setPwl(self, pwlFile):
if pwlFile is not None: if pwlFile is not None:
self.pwlFile = pwlFile self.pwlFile = pwlFile
@@ -134,9 +152,13 @@ class GuiDocEditor(QTextEdit):
self.rehighlightDocument() self.rehighlightDocument()
return True return True
def getText(self): def rehighlightDocument(self):
theText = self.toPlainText() self.hLight.rehighlight()
return theText return
##
# General Class Methods
##
def changeWidth(self): def changeWidth(self):
"""Automatically adjust the margins so the text is centred, but only if Config.textFixedW is """Automatically adjust the margins so the text is centred, but only if Config.textFixedW is
@@ -169,10 +191,6 @@ class GuiDocEditor(QTextEdit):
return False return False
return True return True
def rehighlightDocument(self):
self.hLight.rehighlight()
return
## ##
# Document Events and Maintenance # Document Events and Maintenance
## ##
+4
View File
@@ -206,15 +206,19 @@ class GuiMain(QMainWindow):
self.saveDocument() self.saveDocument()
self.stackPane.setCurrentIndex(self.stackDoc) self.stackPane.setCurrentIndex(self.stackDoc)
self.docEditor.setText(self.theDocument.openDocument(tHandle)) self.docEditor.setText(self.theDocument.openDocument(tHandle))
self.docEditor.setCursorPosition(self.theDocument.theItem.cursorPos)
self.docEditor.changeWidth() self.docEditor.changeWidth()
self.docEditor.setFocus()
return True return True
def saveDocument(self): def saveDocument(self):
if self.theDocument.theItem is not None: if self.theDocument.theItem is not None:
docHtml = self.docEditor.getText() docHtml = self.docEditor.getText()
cursPos = self.docEditor.getCursorPosition()
self.theDocument.theItem.setCharCount(self.docEditor.charCount) self.theDocument.theItem.setCharCount(self.docEditor.charCount)
self.theDocument.theItem.setWordCount(self.docEditor.wordCount) self.theDocument.theItem.setWordCount(self.docEditor.wordCount)
self.theDocument.theItem.setParaCount(self.docEditor.paraCount) self.theDocument.theItem.setParaCount(self.docEditor.paraCount)
self.theDocument.theItem.setCursorPos(cursPos)
self.theDocument.saveDocument(docHtml) self.theDocument.saveDocument(docHtml)
self.docEditor.setDocumentChanged(False) self.docEditor.setDocumentChanged(False)
return True return True
+10 -1
View File
@@ -38,9 +38,11 @@ class NWItem():
self.itemStatus = 0 self.itemStatus = 0
self.isExpanded = False self.isExpanded = False
# Document Meta Data
self.charCount = 0 self.charCount = 0
self.wordCount = 0 self.wordCount = 0
self.paraCount = 0 self.paraCount = 0
self.cursorPos = 0
return return
@@ -64,6 +66,7 @@ class NWItem():
xSub = self._subPack(xPack,"charCount", text=str(self.charCount), none=False) xSub = self._subPack(xPack,"charCount", text=str(self.charCount), none=False)
xSub = self._subPack(xPack,"wordCount", text=str(self.wordCount), none=False) xSub = self._subPack(xPack,"wordCount", text=str(self.wordCount), none=False)
xSub = self._subPack(xPack,"paraCount", text=str(self.paraCount), none=False) xSub = self._subPack(xPack,"paraCount", text=str(self.paraCount), none=False)
xSub = self._subPack(xPack,"cursorPos", text=str(self.cursorPos), none=False)
return xPack return xPack
def _subPack(self, xParent, name, attrib=None, text=None, none=True): def _subPack(self, xParent, name, attrib=None, text=None, none=True):
@@ -90,6 +93,7 @@ class NWItem():
elif tagName == "charCount": self.setCharCount(tagValue) elif tagName == "charCount": self.setCharCount(tagValue)
elif tagName == "wordCount": self.setWordCount(tagValue) elif tagName == "wordCount": self.setWordCount(tagValue)
elif tagName == "paraCount": self.setParaCount(tagValue) elif tagName == "paraCount": self.setParaCount(tagValue)
elif tagName == "cursorPos": self.setCursorPos(tagValue)
else: else:
logger.error("Unknown tag '%s'" % tagName) logger.error("Unknown tag '%s'" % tagName)
return return
@@ -166,7 +170,7 @@ class NWItem():
return return
## ##
# Set Stats # Set Document Meta Data
## ##
def setCharCount(self, theCount): def setCharCount(self, theCount):
@@ -184,4 +188,9 @@ class NWItem():
self.paraCount = theCount self.paraCount = theCount
return return
def setCursorPos(self, thePosition):
thePosition = checkInt(thePosition,0)
self.cursorPos = thePosition
return
# END Class NWItem # END Class NWItem
+11 -2
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.1.0" fileVersion="1.0" timeStamp="2019-05-12 16:22:26"> <novelWriterXML appVersion="0.1.2" fileVersion="1.0" timeStamp="2019-05-18 13:47:34">
<project> <project>
<name>Sample Project</name> <name>Sample Project</name>
<title>Sample Project</title> <title>Sample Project</title>
@@ -27,6 +27,7 @@
<charCount>23</charCount> <charCount>23</charCount>
<wordCount>5</wordCount> <wordCount>5</wordCount>
<paraCount>1</paraCount> <paraCount>1</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="e7ded148d6e4a" order="1" parent="7031beac91f75"> <item handle="e7ded148d6e4a" order="1" parent="7031beac91f75">
<name>Some Chapter</name> <name>Some Chapter</name>
@@ -45,6 +46,7 @@
<charCount>2571</charCount> <charCount>2571</charCount>
<wordCount>377</wordCount> <wordCount>377</wordCount>
<paraCount>5</paraCount> <paraCount>5</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="636b6aa9b697b" order="1" parent="e7ded148d6e4a"> <item handle="636b6aa9b697b" order="1" parent="e7ded148d6e4a">
<name>File With Stuff</name> <name>File With Stuff</name>
@@ -53,9 +55,10 @@
<status>1</status> <status>1</status>
<expanded>False</expanded> <expanded>False</expanded>
<layout>SCENE</layout> <layout>SCENE</layout>
<charCount>417</charCount> <charCount>405</charCount>
<wordCount>71</wordCount> <wordCount>71</wordCount>
<paraCount>5</paraCount> <paraCount>5</paraCount>
<cursorPos>421</cursorPos>
</item> </item>
<item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a"> <item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a">
<name>New File</name> <name>New File</name>
@@ -67,6 +70,7 @@
<charCount>69</charCount> <charCount>69</charCount>
<wordCount>17</wordCount> <wordCount>17</wordCount>
<paraCount>1</paraCount> <paraCount>1</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="f6622b4617424" order="1" parent="None"> <item handle="f6622b4617424" order="1" parent="None">
<name>Characters</name> <name>Characters</name>
@@ -92,6 +96,7 @@
<charCount>42</charCount> <charCount>42</charCount>
<wordCount>8</wordCount> <wordCount>8</wordCount>
<paraCount>1</paraCount> <paraCount>1</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="bb2c23b3c42cc" order="1" parent="f7e2d9f330615"> <item handle="bb2c23b3c42cc" order="1" parent="f7e2d9f330615">
<name>Jane Smith</name> <name>Jane Smith</name>
@@ -103,6 +108,7 @@
<charCount>51</charCount> <charCount>51</charCount>
<wordCount>9</wordCount> <wordCount>9</wordCount>
<paraCount>1</paraCount> <paraCount>1</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="73eee34351f85" order="2" parent="None"> <item handle="73eee34351f85" order="2" parent="None">
<name>Locations</name> <name>Locations</name>
@@ -121,6 +127,7 @@
<charCount>66</charCount> <charCount>66</charCount>
<wordCount>13</wordCount> <wordCount>13</wordCount>
<paraCount>1</paraCount> <paraCount>1</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="f75dac270c2a7" order="3" parent="None"> <item handle="f75dac270c2a7" order="3" parent="None">
<name>Trash</name> <name>Trash</name>
@@ -139,6 +146,7 @@
<charCount>0</charCount> <charCount>0</charCount>
<wordCount>0</wordCount> <wordCount>0</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="879437bde105e" order="1" parent="f75dac270c2a7"> <item handle="879437bde105e" order="1" parent="f75dac270c2a7">
<name>New File</name> <name>New File</name>
@@ -150,6 +158,7 @@
<charCount>0</charCount> <charCount>0</charCount>
<wordCount>0</wordCount> <wordCount>0</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
</content> </content>
</novelWriterXML> </novelWriterXML>
+36
View File
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
"""novelWriter Test Config
"""
import pytest, shutil
from os import path, mkdir
@pytest.fixture(scope="session")
def nwTemp():
testDir = path.dirname(__file__)
tempDir = path.join(testDir,"temp")
if path.isdir(tempDir):
shutil.rmtree(tempDir)
if not path.isdir(tempDir):
mkdir(tempDir)
return tempDir
@pytest.fixture(scope="session")
def nwTempProj(nwTemp):
projDir = path.join(nwTemp,"proj")
if not path.isdir(projDir):
mkdir(projDir)
return projDir
@pytest.fixture(scope="session")
def nwTempGUI(nwTemp):
guiDir = path.join(nwTemp,"gui")
if not path.isdir(guiDir):
mkdir(guiDir)
return guiDir
@pytest.fixture(scope="session")
def nwRef():
testDir = path.dirname(__file__)
refDir = path.join(testDir,"reference")
return refDir
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.1.2" fileVersion="1.0" timeStamp="2019-05-16 22:37:13"> <novelWriterXML appVersion="0.1.2" fileVersion="1.0" timeStamp="2019-05-18 14:55:20">
<project> <project>
<name></name> <name></name>
<title></title> <title></title>
@@ -32,6 +32,7 @@
<charCount>0</charCount> <charCount>0</charCount>
<wordCount>0</wordCount> <wordCount>0</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="44cb730c42048" order="1" parent="None"> <item handle="44cb730c42048" order="1" parent="None">
<name>Characters</name> <name>Characters</name>
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.1.2" fileVersion="1.0" timeStamp="2019-05-17 20:43:19"> <novelWriterXML appVersion="0.1.2" fileVersion="1.0" timeStamp="2019-05-18 14:58:58">
<project> <project>
<name>Project Name</name> <name>Project Name</name>
<title>Project Title</title> <title>Project Title</title>
@@ -34,6 +34,7 @@
<charCount>0</charCount> <charCount>0</charCount>
<wordCount>0</wordCount> <wordCount>0</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="44cb730c42048" order="1" parent="None"> <item handle="44cb730c42048" order="1" parent="None">
<name>Characters</name> <name>Characters</name>
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.1.2" fileVersion="1.0" timeStamp="2019-05-17 21:06:41"> <novelWriterXML appVersion="0.1.2" fileVersion="1.0" timeStamp="2019-05-18 15:00:34">
<project> <project>
<name></name> <name></name>
<title></title> <title></title>
@@ -32,6 +32,7 @@
<charCount>0</charCount> <charCount>0</charCount>
<wordCount>0</wordCount> <wordCount>0</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="44cb730c42048" order="1" parent="None"> <item handle="44cb730c42048" order="1" parent="None">
<name>Characters</name> <name>Characters</name>
+1 -1
View File
@@ -1,5 +1,5 @@
[Main] [Main]
timestamp = 2019-05-12 12:04:16 timestamp = 2019-05-18 15:06:44
[Sizes] [Sizes]
geometry = 1100, 650 geometry = 1100, 650
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.1.0" fileVersion="1.0" timeStamp="2019-05-12 14:21:08"> <novelWriterXML appVersion="0.1.2" fileVersion="1.0" timeStamp="2019-05-18 14:46:29">
<project> <project>
<name></name> <name></name>
<title></title> <title></title>
@@ -53,6 +53,7 @@
<charCount>0</charCount> <charCount>0</charCount>
<wordCount>0</wordCount> <wordCount>0</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
</content> </content>
</novelWriterXML> </novelWriterXML>
@@ -53,6 +53,7 @@
<charCount>0</charCount> <charCount>0</charCount>
<wordCount>0</wordCount> <wordCount>0</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="39fa9ec190eee" order="None" parent="None"> <item handle="39fa9ec190eee" order="None" parent="None">
<name>Timeline</name> <name>Timeline</name>
+22 -22
View File
@@ -4,40 +4,34 @@
import nw, pytest import nw, pytest
from nwtools import * from nwtools import *
from os import path, unlink from os import path
from nw.config import Config from nw.config import Config
theConf = Config() theConf = Config()
testDir = path.dirname(__file__)
testTemp = path.join(testDir,"temp")
testRef = path.join(testDir,"reference")
tmpConf = path.join(testTemp,"novelwriter.conf")
refConf = path.join(testRef, "novelwriter.conf")
ensureDir(testTemp)
# Clean out old stuff
if path.isfile(tmpConf):
unlink(tmpConf)
@pytest.mark.core @pytest.mark.core
def testConfigInit(): def testConfigInit(nwTemp,nwRef):
assert theConf.initConfig(testTemp) tmpConf = path.join(nwTemp,"novelwriter.conf")
refConf = path.join(nwRef, "novelwriter.conf")
assert theConf.initConfig(nwTemp)
assert cmpFiles(tmpConf, refConf, [2]) assert cmpFiles(tmpConf, refConf, [2])
assert not theConf.confChanged assert not theConf.confChanged
@pytest.mark.core @pytest.mark.core
def testConfigSave(): def testConfigSave(nwTemp,nwRef):
tmpConf = path.join(nwTemp,"novelwriter.conf")
refConf = path.join(nwRef, "novelwriter.conf")
assert theConf.confPath == nwTemp
assert theConf.saveConfig() assert theConf.saveConfig()
assert cmpFiles(tmpConf, refConf, [2]) assert cmpFiles(tmpConf, refConf, [2])
assert not theConf.confChanged assert not theConf.confChanged
@pytest.mark.core @pytest.mark.core
def testConfigSetConfPath(): def testConfigSetConfPath(nwTemp):
assert theConf.setConfPath(None) assert theConf.setConfPath(None)
assert not theConf.setConfPath(path.join("somewhere","over","the","rainbow")) assert not theConf.setConfPath(path.join("somewhere","over","the","rainbow"))
assert theConf.setConfPath(path.join(testTemp,"novelwriter.conf")) assert theConf.setConfPath(path.join(nwTemp,"novelwriter.conf"))
assert theConf.confPath == testTemp assert theConf.confPath == nwTemp
assert theConf.confFile == "novelwriter.conf" assert theConf.confFile == "novelwriter.conf"
assert not theConf.confChanged assert not theConf.confChanged
@@ -47,7 +41,9 @@ def testConfigLoad():
assert not theConf.confChanged assert not theConf.confChanged
@pytest.mark.core @pytest.mark.core
def testConfigSetWinSize(): def testConfigSetWinSize(nwTemp,nwRef):
tmpConf = path.join(nwTemp,"novelwriter.conf")
refConf = path.join(nwRef, "novelwriter.conf")
assert theConf.setWinSize(1105, 655) assert theConf.setWinSize(1105, 655)
assert not theConf.confChanged assert not theConf.confChanged
assert theConf.setWinSize(70,70) assert theConf.setWinSize(70,70)
@@ -58,7 +54,9 @@ def testConfigSetWinSize():
assert not theConf.confChanged assert not theConf.confChanged
@pytest.mark.core @pytest.mark.core
def testConfigSetTreeColWidths(): def testConfigSetTreeColWidths(nwTemp,nwRef):
tmpConf = path.join(nwTemp,"novelwriter.conf")
refConf = path.join(nwRef, "novelwriter.conf")
assert theConf.setTreeColWidths([0, 0, 0]) assert theConf.setTreeColWidths([0, 0, 0])
assert theConf.confChanged assert theConf.confChanged
assert theConf.setTreeColWidths([120, 30, 50]) assert theConf.setTreeColWidths([120, 30, 50])
@@ -67,7 +65,9 @@ def testConfigSetTreeColWidths():
assert not theConf.confChanged assert not theConf.confChanged
@pytest.mark.core @pytest.mark.core
def testConfigSetMainPanePos(): def testConfigSetMainPanePos(nwTemp,nwRef):
tmpConf = path.join(nwTemp,"novelwriter.conf")
refConf = path.join(nwRef, "novelwriter.conf")
assert theConf.setMainPanePos([0, 0]) assert theConf.setMainPanePos([0, 0])
assert theConf.confChanged assert theConf.confChanged
assert theConf.setMainPanePos([300, 800]) assert theConf.setMainPanePos([300, 800])
+21 -29
View File
@@ -14,14 +14,10 @@ from nw.enum import *
keyDelay = 10 keyDelay = 10
stepDelay = 50 stepDelay = 50
testDir = path.dirname(__file__)
testRef = path.join(testDir,"reference")
@pytest.mark.gui @pytest.mark.gui
def testMainWindows(qtbot, tmpdir): def testMainWindows(qtbot, nwTempGUI, nwRef):
confDir = str(tmpdir.mkdir("conf")) nwGUI = nw.main(["--testmode","--config=%s" % nwTempGUI])
projDir = str(tmpdir.mkdir("project"))
nwGUI = nw.main(["--testmode","--config=%s" % confDir])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
qtbot.waitForWindowShown(nwGUI) qtbot.waitForWindowShown(nwGUI)
@@ -29,12 +25,12 @@ def testMainWindows(qtbot, tmpdir):
# Create new, save, open project # Create new, save, open project
nwGUI.theProject.handleSeed = 42 nwGUI.theProject.handleSeed = 42
assert nwGUI.theProject.setProjectPath(projDir) assert nwGUI.theProject.setProjectPath(nwTempGUI)
assert nwGUI.newProject() assert nwGUI.newProject()
assert nwGUI.theProject.setProjectPath(projDir) assert nwGUI.theProject.setProjectPath(nwTempGUI)
assert nwGUI.saveProject() assert nwGUI.saveProject()
qtbot.wait(stepDelay) qtbot.wait(stepDelay)
assert nwGUI.openProject(projDir) assert nwGUI.openProject(nwTempGUI)
qtbot.wait(stepDelay) qtbot.wait(stepDelay)
# Check that tree items have been created # Check that tree items have been created
@@ -108,18 +104,16 @@ def testMainWindows(qtbot, tmpdir):
qtbot.wait(stepDelay) qtbot.wait(stepDelay)
# Check the files # Check the files
projFile = path.join(projDir,"nwProject.nwx") projFile = path.join(nwTempGUI,"nwProject.nwx")
assert cmpFiles(projFile, path.join(testRef,"gui_nwProject.nwx"), [2]) assert cmpFiles(projFile, path.join(nwRef,"gui","1_nwProject.nwx"), [2])
sceneFile = path.join(projDir,"data_3","1489056e0916_main.nwd") sceneFile = path.join(nwTempGUI,"data_3","1489056e0916_main.nwd")
assert cmpFiles(sceneFile, path.join(testRef,"gui_1489056e0916_main.nwd")) assert cmpFiles(sceneFile, path.join(nwRef,"gui","1_1489056e0916_main.nwd"))
# qtbot.stopForInteraction() # qtbot.stopForInteraction()
@pytest.mark.gui @pytest.mark.gui
def testProjectEditor(qtbot, tmpdir): def testProjectEditor(qtbot, nwTempGUI, nwRef):
confDir = str(tmpdir.mkdir("conf")) nwGUI = nw.main(["--testmode","--config=%s" % nwTempGUI])
projDir = str(tmpdir.mkdir("project"))
nwGUI = nw.main(["--testmode","--config=%s" % confDir])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
qtbot.waitForWindowShown(nwGUI) qtbot.waitForWindowShown(nwGUI)
@@ -127,9 +121,9 @@ def testProjectEditor(qtbot, tmpdir):
# Create new, save, open project # Create new, save, open project
nwGUI.theProject.handleSeed = 42 nwGUI.theProject.handleSeed = 42
assert nwGUI.theProject.setProjectPath(projDir) assert nwGUI.theProject.setProjectPath(nwTempGUI)
assert nwGUI.newProject() assert nwGUI.newProject()
assert nwGUI.theProject.setProjectPath(projDir) assert nwGUI.theProject.setProjectPath(nwTempGUI)
projEdit = GuiProjectEditor(nwGUI, nwGUI.theProject) projEdit = GuiProjectEditor(nwGUI, nwGUI.theProject)
qtbot.addWidget(projEdit) qtbot.addWidget(projEdit)
@@ -162,16 +156,14 @@ def testProjectEditor(qtbot, tmpdir):
qtbot.wait(stepDelay) qtbot.wait(stepDelay)
# Check the files # Check the files
projFile = path.join(projDir,"nwProject.nwx") projFile = path.join(nwTempGUI,"nwProject.nwx")
assert cmpFiles(projFile, path.join(testRef,"projedit_nwProject.nwx"), [2]) assert cmpFiles(projFile, path.join(nwRef,"gui","2_nwProject.nwx"), [2])
# qtbot.stopForInteraction() # qtbot.stopForInteraction()
@pytest.mark.gui @pytest.mark.gui
def testItemEditor(qtbot, tmpdir): def testItemEditor(qtbot, nwTempGUI, nwRef):
confDir = str(tmpdir.mkdir("conf")) nwGUI = nw.main(["--testmode","--config=%s" % nwTempGUI])
projDir = str(tmpdir.mkdir("project"))
nwGUI = nw.main(["--testmode","--config=%s" % confDir])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
nwGUI.show() nwGUI.show()
qtbot.waitForWindowShown(nwGUI) qtbot.waitForWindowShown(nwGUI)
@@ -179,9 +171,9 @@ def testItemEditor(qtbot, tmpdir):
# Create new, save, open project # Create new, save, open project
nwGUI.theProject.handleSeed = 42 nwGUI.theProject.handleSeed = 42
assert nwGUI.theProject.setProjectPath(projDir) assert nwGUI.theProject.setProjectPath(nwTempGUI)
assert nwGUI.newProject() assert nwGUI.newProject()
assert nwGUI.theProject.setProjectPath(projDir) assert nwGUI.theProject.setProjectPath(nwTempGUI)
itemEdit = GuiItemEditor(nwGUI, nwGUI.theProject, "31489056e0916") itemEdit = GuiItemEditor(nwGUI, nwGUI.theProject, "31489056e0916")
qtbot.addWidget(itemEdit) qtbot.addWidget(itemEdit)
@@ -211,7 +203,7 @@ def testItemEditor(qtbot, tmpdir):
qtbot.wait(stepDelay) qtbot.wait(stepDelay)
# Check the files # Check the files
projFile = path.join(projDir,"nwProject.nwx") projFile = path.join(nwTempGUI,"nwProject.nwx")
assert cmpFiles(projFile, path.join(testRef,"itemedit_nwProject.nwx"), [2]) assert cmpFiles(projFile, path.join(nwRef,"gui","3_nwProject.nwx"), [2])
# qtbot.stopForInteraction() # qtbot.stopForInteraction()
+19 -21
View File
@@ -3,7 +3,7 @@
""" """
import nw, pytest, types import nw, pytest, types
from os import path, unlink from os import path
from nwtools import * from nwtools import *
from nwdummy import DummyMain from nwdummy import DummyMain
@@ -13,42 +13,40 @@ from nw.project.project import NWProject
from nw.project.item import NWItem from nw.project.item import NWItem
from nw.enum import nwItemClass from nw.enum import nwItemClass
theConf = Config() theConf = Config()
theMain = DummyMain() theMain = DummyMain()
theMain.mainConf = theConf theMain.mainConf = theConf
testDir = path.dirname(__file__)
testTemp = path.join(testDir,"temp")
testRef = path.join(testDir,"reference")
testProj = path.join(testTemp,"proj")
ensureDir(testTemp)
ensureDir(testProj)
theConf.initConfig(testRef)
theProject = NWProject(theMain) theProject = NWProject(theMain)
theProject.handleSeed = 42 theProject.handleSeed = 42
projFile = path.join(testProj,"nwProject.nwx")
@pytest.mark.project @pytest.mark.project
def testProjectNew(): def testProjectNew(nwTempProj,nwRef):
projFile = path.join(nwTempProj,"nwProject.nwx")
refFile = path.join(nwRef,"proj","1_nwProject.nwx")
assert theConf.initConfig(nwRef)
assert theProject.newProject() assert theProject.newProject()
assert theProject.setProjectPath(testProj) assert theProject.setProjectPath(nwTempProj)
assert theProject.saveProject() assert theProject.saveProject()
assert cmpFiles(projFile, path.join(testRef,"new_nwProject.nwx"), [2]) assert cmpFiles(projFile, refFile, [2])
@pytest.mark.project @pytest.mark.project
def testProjectOpen(): def testProjectOpen(nwTempProj):
projFile = path.join(nwTempProj,"nwProject.nwx")
assert theProject.openProject(projFile) assert theProject.openProject(projFile)
@pytest.mark.project @pytest.mark.project
def testProjectSave(): def testProjectSave(nwTempProj,nwRef):
projFile = path.join(nwTempProj,"nwProject.nwx")
refFile = path.join(nwRef,"proj","1_nwProject.nwx")
assert theProject.saveProject() assert theProject.saveProject()
assert cmpFiles(projFile, path.join(testRef,"new_nwProject.nwx"), [2]) assert cmpFiles(projFile, refFile, [2])
assert not theProject.projChanged assert not theProject.projChanged
@pytest.mark.project @pytest.mark.project
def testProjectNewRoot(): def testProjectNewRoot(nwTempProj,nwRef):
projFile = path.join(nwTempProj,"nwProject.nwx")
refFile = path.join(nwRef,"proj","2_nwProject.nwx")
assert theProject.openProject(projFile) assert theProject.openProject(projFile)
assert isinstance(theProject.newRoot("Novel", nwItemClass.NOVEL), type(None)) assert isinstance(theProject.newRoot("Novel", nwItemClass.NOVEL), type(None))
assert isinstance(theProject.newRoot("Plot", nwItemClass.PLOT), type(None)) assert isinstance(theProject.newRoot("Plot", nwItemClass.PLOT), type(None))
@@ -60,5 +58,5 @@ def testProjectNewRoot():
assert isinstance(theProject.newRoot("Custom2", nwItemClass.CUSTOM), str) assert isinstance(theProject.newRoot("Custom2", nwItemClass.CUSTOM), str)
assert theProject.projChanged assert theProject.projChanged
assert theProject.saveProject() assert theProject.saveProject()
assert cmpFiles(projFile, path.join(testRef,"roots_nwProject.nwx"), [2]) assert cmpFiles(projFile, refFile, [2])
assert not theProject.projChanged assert not theProject.projChanged