Auto-replace values now loaded and saved.

This commit is contained in:
Veronica K. B. Olsen
2019-06-08 20:02:09 +02:00
parent f219d1f8bb
commit 2d55ec06cc
4 changed files with 80 additions and 39 deletions
+19 -8
View File
@@ -50,7 +50,7 @@ class GuiProjectEditor(QDialog):
self.tabMain = GuiProjectEditMain(self.theParent, self.theProject)
self.tabStatus = GuiProjectEditStatus(self.theParent, self.theProject.statusItems)
self.tabImport = GuiProjectEditStatus(self.theParent, self.theProject.importItems)
self.tabReplace = GuiProjectEditReplace(self.theParent, self.theProject.importItems)
self.tabReplace = GuiProjectEditReplace(self.theParent, self.theProject)
self.tabWidget = QTabWidget()
self.tabWidget.addTab(self.tabMain, "Settings")
@@ -75,12 +75,6 @@ class GuiProjectEditor(QDialog):
return
# def keyPressEvent(self, theEvent):
# if theEvent.key() == Qt.Key_Enter or theEvent.key() == Qt.Key_Return:
# return
# QDialog.keyPressEvent(self, theEvent)
# return
def _doSave(self):
logger.verbose("ProjectEditor save button clicked")
@@ -99,6 +93,9 @@ class GuiProjectEditor(QDialog):
self.theProject.setImportColours(importCol)
if self.tabStatus.colChanged or self.tabImport.colChanged:
self.theParent.rebuildTree()
if self.tabReplace.arChanged:
newList = self.tabReplace.getNewList()
self.theProject.setAutoReplace(newList)
self.close()
@@ -313,9 +310,13 @@ class GuiProjectEditReplace(QWidget):
self.outerBox = QVBoxLayout()
self.bottomBox = QHBoxLayout()
self.listBox = QTreeWidget()
self.listBox.setHeaderLabels(["Keyword","Value"])
self.listBox.setHeaderLabels(["Keyword","Replace With"])
self.listBox.setIndentation(0)
for aKey, aVal in self.theProject.autoReplace.items():
newItem = QTreeWidgetItem(["<%s>" % aKey, aVal])
self.listBox.addTopLevelItem(newItem)
self.editKey = QLineEdit()
self.editValue = QLineEdit()
self.addButton = QPushButton(QIcon.fromTheme("list-add"),"")
@@ -362,4 +363,14 @@ class GuiProjectEditReplace(QWidget):
self.arChanged = True
return True
def getNewList(self):
newList = {}
for n in range(self.listBox.topLevelItemCount()):
tItem = self.listBox.topLevelItem(n)
aKey = tItem.text(0)
aVal = tItem.text(1)
if len(aKey) > 2:
newList[aKey[1:-1]] = aVal
return newList
# END Class GuiProjectEditReplace
+44 -29
View File
@@ -32,37 +32,40 @@ class NWProject():
def __init__(self, theParent):
# Internal
self.theParent = theParent
self.mainConf = self.theParent.mainConf
self.projChanged = None
self.projOpened = None
self.theParent = theParent
self.mainConf = self.theParent.mainConf
self.projChanged = None
self.projOpened = None
# Debug
self.handleSeed = None
self.handleSeed = None
# Class Settings
self.projTree = None
self.treeOrder = None
self.treeRoots = None
self.trashRoot = None
self.projPath = None
self.projMeta = None
self.projCache = None
self.projFile = None
self.projTree = None
self.treeOrder = None
self.treeRoots = None
self.trashRoot = None
self.projPath = None
self.projMeta = None
self.projCache = None
self.projFile = None
# Project Meta
self.projName = None
self.bookTitle = None
self.bookAuthors = None
self.projName = None
self.bookTitle = None
self.bookAuthors = None
# Various
self.autoReplace = None
# Project Settings
self.spellCheck = False
self.statusItems = None
self.importItems = None
self.lastEdited = None
self.lastViewed = None
self.lastWCount = 0
self.currWCount = 0
self.spellCheck = False
self.statusItems = None
self.importItems = None
self.lastEdited = None
self.lastViewed = None
self.lastWCount = 0
self.currWCount = 0
# Set Defaults
self.clearProject()
@@ -150,6 +153,7 @@ class NWProject():
self.projName = ""
self.bookTitle = ""
self.bookAuthors = []
self.autoReplace = {}
self.spellCheck = False
self.statusItems = NWStatus()
self.statusItems.addEntry("New", (100,100,100))
@@ -220,16 +224,19 @@ class NWProject():
if xItem.text is None: continue
if xItem.tag == "spellCheck":
self.spellCheck = checkBool(xItem.text,False)
if xItem.tag == "lastEdited":
elif xItem.tag == "lastEdited":
self.lastEdited = checkString(xItem.text,None,True)
if xItem.tag == "lastViewed":
elif xItem.tag == "lastViewed":
self.lastViewed = checkString(xItem.text,None,True)
if xItem.tag == "lastWordCount":
elif xItem.tag == "lastWordCount":
self.lastWCount = checkInt(xItem.text,0,False)
if xItem.tag == "status":
elif xItem.tag == "status":
self.statusItems.unpackEntries(xItem)
if xItem.tag == "importance":
elif xItem.tag == "importance":
self.importItems.unpackEntries(xItem)
elif xItem.tag == "autoReplace":
for xEntry in xItem:
self.autoReplace[xEntry.tag] = checkString(xEntry.text,None,False)
elif xChild.tag == "content":
logger.debug("Found project content")
for xItem in xChild:
@@ -292,6 +299,10 @@ class NWProject():
self._saveProjectValue(xSettings,"lastEdited", self.lastEdited)
self._saveProjectValue(xSettings,"lastViewed", self.lastViewed)
self._saveProjectValue(xSettings,"lastWordCount",self.currWCount)
xAutoRep = etree.SubElement(xSettings,"autoReplace")
for aKey, aValue in self.autoReplace.items():
if len(aKey) > 0:
self._saveProjectValue(xAutoRep,aKey,aValue)
xStatus = etree.SubElement(xSettings,"status")
self.statusItems.packEntries(xStatus)
@@ -401,7 +412,7 @@ class NWProject():
self.setProjectChanged(True)
return
def setImportColours(self, newCols,):
def setImportColours(self, newCols):
replaceMap = self.importItems.setNewEntries(newCols)
if self.projTree is not None:
for nwItem in self.projTree.values():
@@ -411,6 +422,10 @@ class NWProject():
self.setProjectChanged(True)
return
def setAutoReplace(self, autoReplace):
self.autoReplace = autoReplace
return
def setProjectChanged(self, bValue):
self.projChanged = bValue
self.theParent.setProjectStatus(self.projChanged)