Replace old option state class with new one everywhere
This commit is contained in:
+64
-65
@@ -24,7 +24,7 @@ from PyQt5.QtWidgets import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from nw.convert import TextFile, HtmlFile, MarkdownFile, LaTeXFile, ConcatFile
|
from nw.convert import TextFile, HtmlFile, MarkdownFile, LaTeXFile, ConcatFile
|
||||||
from nw.tools import OptLastState
|
from nw.tools import OptionState
|
||||||
from nw.common import packageRefURL
|
from nw.common import packageRefURL
|
||||||
from nw.constants import nwFiles, nwItemType, nwAlert
|
from nw.constants import nwFiles, nwItemType, nwAlert
|
||||||
|
|
||||||
@@ -40,8 +40,7 @@ class GuiExport(QDialog):
|
|||||||
self.mainConf = nw.CONFIG
|
self.mainConf = nw.CONFIG
|
||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theProject = theProject
|
self.theProject = theProject
|
||||||
self.optState = ExportLastState(self.theProject,nwFiles.EXPORT_OPT)
|
self.optState = self.theProject.optState
|
||||||
self.optState.loadSettings()
|
|
||||||
|
|
||||||
self.outerBox = QHBoxLayout()
|
self.outerBox = QHBoxLayout()
|
||||||
self.innerBox = QVBoxLayout()
|
self.innerBox = QVBoxLayout()
|
||||||
@@ -50,8 +49,8 @@ class GuiExport(QDialog):
|
|||||||
|
|
||||||
self.guiDeco = self.theParent.theTheme.loadDecoration("export",(64,64))
|
self.guiDeco = self.theParent.theTheme.loadDecoration("export",(64,64))
|
||||||
|
|
||||||
self.tabMain = GuiExportMain(self.theParent, self.theProject, self.optState)
|
self.tabMain = GuiExportMain(self.theParent, self.theProject)
|
||||||
self.tabPandoc = GuiExportPandoc(self.theParent, self.theProject, self.optState)
|
self.tabPandoc = GuiExportPandoc(self.theParent, self.theProject)
|
||||||
|
|
||||||
self.tabWidget = QTabWidget()
|
self.tabWidget = QTabWidget()
|
||||||
self.tabWidget.addTab(self.tabMain, "Settings")
|
self.tabWidget.addTab(self.tabMain, "Settings")
|
||||||
@@ -290,24 +289,24 @@ class GuiExport(QDialog):
|
|||||||
if saveTo.startswith("~"):
|
if saveTo.startswith("~"):
|
||||||
saveTo = path.expanduser(saveTo)
|
saveTo = path.expanduser(saveTo)
|
||||||
|
|
||||||
self.optState.setSetting("wNovel", wNovel)
|
self.optState.setValue("GuiExport", "wNovel", wNovel)
|
||||||
self.optState.setSetting("wNotes", wNotes)
|
self.optState.setValue("GuiExport", "wNotes", wNotes)
|
||||||
self.optState.setSetting("eFormat", eFormat)
|
self.optState.setValue("GuiExport", "eFormat", eFormat)
|
||||||
self.optState.setSetting("fixWidth", fixWidth)
|
self.optState.setValue("GuiExport", "fixWidth", fixWidth)
|
||||||
self.optState.setSetting("wComments",wComments)
|
self.optState.setValue("GuiExport", "wComments", wComments)
|
||||||
self.optState.setSetting("wKeywords",wKeywords)
|
self.optState.setValue("GuiExport", "wKeywords", wKeywords)
|
||||||
self.optState.setSetting("chFormat", chFormat)
|
self.optState.setValue("GuiExport", "chFormat", chFormat)
|
||||||
self.optState.setSetting("unFormat", unFormat)
|
self.optState.setValue("GuiExport", "unFormat", unFormat)
|
||||||
self.optState.setSetting("scFormat", scFormat)
|
self.optState.setValue("GuiExport", "scFormat", scFormat)
|
||||||
self.optState.setSetting("seFormat", seFormat)
|
self.optState.setValue("GuiExport", "seFormat", seFormat)
|
||||||
self.optState.setSetting("saveTo", saveTo)
|
self.optState.setValue("GuiExport", "saveTo", saveTo)
|
||||||
self.optState.setSetting("hScene", hScene)
|
self.optState.setValue("GuiExport", "hScene", hScene)
|
||||||
self.optState.setSetting("hSection", hSection)
|
self.optState.setValue("GuiExport", "hSection", hSection)
|
||||||
|
|
||||||
# Pandoc Settings
|
# Pandoc Settings
|
||||||
pFormat = self.tabPandoc.outputFormat.currentData()
|
pFormat = self.tabPandoc.outputFormat.currentData()
|
||||||
|
|
||||||
self.optState.setSetting("pFormat", pFormat)
|
self.optState.setValue("GuiExport", "pFormat", pFormat)
|
||||||
|
|
||||||
self.optState.saveSettings()
|
self.optState.saveSettings()
|
||||||
self.close()
|
self.close()
|
||||||
@@ -362,14 +361,14 @@ class GuiExportMain(QWidget):
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, theParent, theProject, optState):
|
def __init__(self, theParent, theProject):
|
||||||
QWidget.__init__(self, theParent)
|
QWidget.__init__(self, theParent)
|
||||||
|
|
||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theProject = theProject
|
self.theProject = theProject
|
||||||
self.theTheme = theParent.theTheme
|
self.theTheme = theParent.theTheme
|
||||||
self.outerBox = QGridLayout()
|
self.outerBox = QGridLayout()
|
||||||
self.optState = optState
|
self.optState = self.theProject.optState
|
||||||
self.currFormat = self.FMT_TXT
|
self.currFormat = self.FMT_TXT
|
||||||
|
|
||||||
# Select Files
|
# Select Files
|
||||||
@@ -378,19 +377,27 @@ class GuiExportMain(QWidget):
|
|||||||
self.guiFiles.setLayout(self.guiFilesForm)
|
self.guiFiles.setLayout(self.guiFilesForm)
|
||||||
|
|
||||||
self.expNovel = QCheckBox("Novel files",self)
|
self.expNovel = QCheckBox("Novel files",self)
|
||||||
self.expNovel.setChecked(self.optState.getSetting("wNovel"))
|
self.expNovel.setChecked(
|
||||||
|
self.optState.getBool("GuiExport", "wNovel", True)
|
||||||
|
)
|
||||||
self.expNovel.setToolTip("Include all novel files in the exported document")
|
self.expNovel.setToolTip("Include all novel files in the exported document")
|
||||||
|
|
||||||
self.expNotes = QCheckBox("Note files",self)
|
self.expNotes = QCheckBox("Note files",self)
|
||||||
self.expNotes.setChecked(self.optState.getSetting("wNotes"))
|
self.expNotes.setChecked(
|
||||||
|
self.optState.getBool("GuiExport", "wNotes", False)
|
||||||
|
)
|
||||||
self.expNotes.setToolTip("Include all note files in the exported document")
|
self.expNotes.setToolTip("Include all note files in the exported document")
|
||||||
|
|
||||||
self.expComments = QCheckBox("Comments",self)
|
self.expComments = QCheckBox("Comments",self)
|
||||||
self.expComments.setChecked(self.optState.getSetting("wComments"))
|
self.expComments.setChecked(
|
||||||
|
self.optState.getBool("GuiExport", "wComments", False)
|
||||||
|
)
|
||||||
self.expComments.setToolTip("Export comments from all files")
|
self.expComments.setToolTip("Export comments from all files")
|
||||||
|
|
||||||
self.expKeywords = QCheckBox("Keywords",self)
|
self.expKeywords = QCheckBox("Keywords",self)
|
||||||
self.expKeywords.setChecked(self.optState.getSetting("wKeywords"))
|
self.expKeywords.setChecked(
|
||||||
|
self.optState.getBool("GuiExport", "wKeywords", False)
|
||||||
|
)
|
||||||
self.expKeywords.setToolTip("Export @keywords from all files")
|
self.expKeywords.setToolTip("Export @keywords from all files")
|
||||||
|
|
||||||
self.guiFilesForm.addWidget(self.expNovel, 0, 1)
|
self.guiFilesForm.addWidget(self.expNovel, 0, 1)
|
||||||
@@ -406,13 +413,17 @@ class GuiExportMain(QWidget):
|
|||||||
|
|
||||||
self.chapterFormat = QLineEdit()
|
self.chapterFormat = QLineEdit()
|
||||||
self.chapterFormat.setMaxLength(200)
|
self.chapterFormat.setMaxLength(200)
|
||||||
self.chapterFormat.setText(self.optState.getSetting("chFormat"))
|
self.chapterFormat.setText(
|
||||||
|
self.optState.getString("GuiExport", "chFormat", "Chapter %numword%")
|
||||||
|
)
|
||||||
self.chapterFormat.setToolTip("Available formats: %num%, %numword%, %title%")
|
self.chapterFormat.setToolTip("Available formats: %num%, %numword%, %title%")
|
||||||
self.chapterFormat.setMinimumWidth(250)
|
self.chapterFormat.setMinimumWidth(250)
|
||||||
|
|
||||||
self.unnumFormat = QLineEdit()
|
self.unnumFormat = QLineEdit()
|
||||||
self.unnumFormat.setMaxLength(200)
|
self.unnumFormat.setMaxLength(200)
|
||||||
self.unnumFormat.setText(self.optState.getSetting("unFormat"))
|
self.unnumFormat.setText(
|
||||||
|
self.optState.getString("GuiExport", "unFormat", "%title%")
|
||||||
|
)
|
||||||
self.unnumFormat.setToolTip("Available formats: %title%")
|
self.unnumFormat.setToolTip("Available formats: %title%")
|
||||||
self.unnumFormat.setMinimumWidth(250)
|
self.unnumFormat.setMinimumWidth(250)
|
||||||
|
|
||||||
@@ -428,22 +439,30 @@ class GuiExportMain(QWidget):
|
|||||||
|
|
||||||
self.sceneFormat = QLineEdit()
|
self.sceneFormat = QLineEdit()
|
||||||
self.sceneFormat.setMaxLength(200)
|
self.sceneFormat.setMaxLength(200)
|
||||||
self.sceneFormat.setText(self.optState.getSetting("scFormat"))
|
self.sceneFormat.setText(
|
||||||
|
self.optState.getString("GuiExport", "scFormat", "* * *")
|
||||||
|
)
|
||||||
self.sceneFormat.setToolTip("Available formats: %title%")
|
self.sceneFormat.setToolTip("Available formats: %title%")
|
||||||
self.sceneFormat.setMinimumWidth(100)
|
self.sceneFormat.setMinimumWidth(100)
|
||||||
|
|
||||||
self.sectionFormat = QLineEdit()
|
self.sectionFormat = QLineEdit()
|
||||||
self.sectionFormat.setMaxLength(200)
|
self.sectionFormat.setMaxLength(200)
|
||||||
self.sectionFormat.setText(self.optState.getSetting("seFormat"))
|
self.sectionFormat.setText(
|
||||||
|
self.optState.getString("GuiExport", "seFormat", "")
|
||||||
|
)
|
||||||
self.sectionFormat.setToolTip("Available formats: %title%")
|
self.sectionFormat.setToolTip("Available formats: %title%")
|
||||||
self.sectionFormat.setMinimumWidth(100)
|
self.sectionFormat.setMinimumWidth(100)
|
||||||
|
|
||||||
self.hideScene = QCheckBox("Skip",self)
|
self.hideScene = QCheckBox("Skip",self)
|
||||||
self.hideScene.setChecked(self.optState.getSetting("hScene"))
|
self.hideScene.setChecked(
|
||||||
|
self.optState.getBool("GuiExport", "hScene", False)
|
||||||
|
)
|
||||||
self.hideScene.setToolTip("Skip scene titles in export")
|
self.hideScene.setToolTip("Skip scene titles in export")
|
||||||
|
|
||||||
self.hideSection = QCheckBox("Skip",self)
|
self.hideSection = QCheckBox("Skip",self)
|
||||||
self.hideSection.setChecked(self.optState.getSetting("hSection"))
|
self.hideSection.setChecked(
|
||||||
|
self.optState.getBool("GuiExport", "hSection", False)
|
||||||
|
)
|
||||||
self.hideSection.setToolTip("Skip section titles in export")
|
self.hideSection.setToolTip("Skip section titles in export")
|
||||||
|
|
||||||
self.guiScenesForm.addWidget(QLabel("Scenes"), 0, 0)
|
self.guiScenesForm.addWidget(QLabel("Scenes"), 0, 0)
|
||||||
@@ -458,8 +477,9 @@ class GuiExportMain(QWidget):
|
|||||||
self.exportToForm = QGridLayout(self)
|
self.exportToForm = QGridLayout(self)
|
||||||
self.exportTo.setLayout(self.exportToForm)
|
self.exportTo.setLayout(self.exportToForm)
|
||||||
|
|
||||||
self.exportPath = QLineEdit(self.optState.getSetting("saveTo"))
|
self.exportPath = QLineEdit(
|
||||||
|
self.optState.getString("GuiExport", "saveTo", "")
|
||||||
|
)
|
||||||
self.exportGetPath = QPushButton(self.theTheme.getIcon("folder"),"")
|
self.exportGetPath = QPushButton(self.theTheme.getIcon("folder"),"")
|
||||||
self.exportGetPath.clicked.connect(self._exportFolder)
|
self.exportGetPath.clicked.connect(self._exportFolder)
|
||||||
|
|
||||||
@@ -486,7 +506,9 @@ class GuiExportMain(QWidget):
|
|||||||
self.outputFormat.addItem("Pandoc via Markdown or HTML", self.FMT_PDOC)
|
self.outputFormat.addItem("Pandoc via Markdown or HTML", self.FMT_PDOC)
|
||||||
self.outputFormat.currentIndexChanged.connect(self._updateFormat)
|
self.outputFormat.currentIndexChanged.connect(self._updateFormat)
|
||||||
|
|
||||||
optIdx = self.outputFormat.findData(self.optState.getSetting("eFormat"))
|
optIdx = self.outputFormat.findData(
|
||||||
|
self.optState.getInt("GuiExport", "eFormat", 1)
|
||||||
|
)
|
||||||
if optIdx == -1:
|
if optIdx == -1:
|
||||||
self.outputFormat.setCurrentIndex(1)
|
self.outputFormat.setCurrentIndex(1)
|
||||||
self._updateFormat(1)
|
self._updateFormat(1)
|
||||||
@@ -508,7 +530,9 @@ class GuiExportMain(QWidget):
|
|||||||
self.fixedWidth.setMinimum(0)
|
self.fixedWidth.setMinimum(0)
|
||||||
self.fixedWidth.setMaximum(999)
|
self.fixedWidth.setMaximum(999)
|
||||||
self.fixedWidth.setSingleStep(1)
|
self.fixedWidth.setSingleStep(1)
|
||||||
self.fixedWidth.setValue(self.optState.getSetting("fixWidth"))
|
self.fixedWidth.setValue(
|
||||||
|
self.optState.getInt("GuiExport", "fixWidth", 80)
|
||||||
|
)
|
||||||
self.fixedWidth.setToolTip(
|
self.fixedWidth.setToolTip(
|
||||||
"Applies to .txt and .md files. A value of '0' disables the feature."
|
"Applies to .txt and .md files. A value of '0' disables the feature."
|
||||||
)
|
)
|
||||||
@@ -609,13 +633,13 @@ class GuiExportPandoc(QWidget):
|
|||||||
FMT_ZIM : "markdown",
|
FMT_ZIM : "markdown",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, theParent, theProject, optState):
|
def __init__(self, theParent, theProject):
|
||||||
QWidget.__init__(self, theParent)
|
QWidget.__init__(self, theParent)
|
||||||
|
|
||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theProject = theProject
|
self.theProject = theProject
|
||||||
self.outerBox = QGridLayout()
|
self.outerBox = QGridLayout()
|
||||||
self.optState = optState
|
self.optState = self.theProject.optState
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pypandoc
|
import pypandoc
|
||||||
@@ -659,7 +683,9 @@ class GuiExportPandoc(QWidget):
|
|||||||
self.outputFormat.addItem("ePUB eBook v3 (.epub3)", self.FMT_EPUB3)
|
self.outputFormat.addItem("ePUB eBook v3 (.epub3)", self.FMT_EPUB3)
|
||||||
self.outputFormat.addItem("Zim Wiki (.txt)", self.FMT_ZIM)
|
self.outputFormat.addItem("Zim Wiki (.txt)", self.FMT_ZIM)
|
||||||
|
|
||||||
optIdx = self.outputFormat.findData(self.optState.getSetting("pFormat"))
|
optIdx = self.outputFormat.findData(
|
||||||
|
self.optState.getInt("GuiExport", "pFormat", 1)
|
||||||
|
)
|
||||||
if optIdx == -1:
|
if optIdx == -1:
|
||||||
self.outputFormat.setCurrentIndex(1)
|
self.outputFormat.setCurrentIndex(1)
|
||||||
else:
|
else:
|
||||||
@@ -678,30 +704,3 @@ class GuiExportPandoc(QWidget):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# END Class GuiExportPandoc
|
# END Class GuiExportPandoc
|
||||||
|
|
||||||
class ExportLastState(OptLastState):
|
|
||||||
|
|
||||||
def __init__(self, theProject, theFile):
|
|
||||||
OptLastState.__init__(self, theProject, theFile)
|
|
||||||
self.theState = {
|
|
||||||
"wNovel" : True,
|
|
||||||
"wNotes" : False,
|
|
||||||
"eFormat" : 1,
|
|
||||||
"pFormat" : 1,
|
|
||||||
"fixWidth" : 80,
|
|
||||||
"wComments" : False,
|
|
||||||
"wKeywords" : False,
|
|
||||||
"chFormat" : "Chapter %numword%",
|
|
||||||
"unFormat" : "%title%",
|
|
||||||
"scFormat" : "* * *",
|
|
||||||
"seFormat" : "",
|
|
||||||
"saveTo" : "",
|
|
||||||
"hScene" : False,
|
|
||||||
"hSection" : False,
|
|
||||||
}
|
|
||||||
self.stringOpt = ("chFormat","unFormat","scFormat","seFormat","saveTo")
|
|
||||||
self.boolOpt = ("wNovel","wNotes","wComments","wKeywords","hScene","hSection")
|
|
||||||
self.intOpt = ("eFormat","pFormat","fixWidth")
|
|
||||||
return
|
|
||||||
|
|
||||||
# END Class ExportLastState
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ from PyQt5.QtWidgets import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from nw.constants import nwConst, nwFiles, nwAlert
|
from nw.constants import nwConst, nwFiles, nwAlert
|
||||||
from nw.tools import OptLastState
|
from nw.tools import OptionState
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -38,8 +38,7 @@ class GuiSessionLogView(QDialog):
|
|||||||
self.mainConf = nw.CONFIG
|
self.mainConf = nw.CONFIG
|
||||||
self.theProject = theProject
|
self.theProject = theProject
|
||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.optState = SessionLogLastState(self.theProject,nwFiles.SLOG_OPT)
|
self.optState = self.theProject.optState
|
||||||
self.optState.loadSettings()
|
|
||||||
|
|
||||||
self.timeFilter = 0.0
|
self.timeFilter = 0.0
|
||||||
self.timeTotal = 0.0
|
self.timeTotal = 0.0
|
||||||
@@ -52,13 +51,13 @@ class GuiSessionLogView(QDialog):
|
|||||||
self.setMinimumHeight(400)
|
self.setMinimumHeight(400)
|
||||||
|
|
||||||
widthCol0 = self.optState.validIntRange(
|
widthCol0 = self.optState.validIntRange(
|
||||||
self.optState.getSetting("widthCol0"), 30, 999, 180
|
self.optState.getInt("GuiSession", "widthCol0", 180), 30, 999, 180
|
||||||
)
|
)
|
||||||
widthCol1 = self.optState.validIntRange(
|
widthCol1 = self.optState.validIntRange(
|
||||||
self.optState.getSetting("widthCol1"), 30, 999, 80
|
self.optState.getInt("GuiSession", "widthCol1", 80), 30, 999, 80
|
||||||
)
|
)
|
||||||
widthCol2 = self.optState.validIntRange(
|
widthCol2 = self.optState.validIntRange(
|
||||||
self.optState.getSetting("widthCol2"), 30, 999, 80
|
self.optState.getInt("GuiSession", "widthCol2", 80), 30, 999, 80
|
||||||
)
|
)
|
||||||
|
|
||||||
self.listBox = QTreeWidget()
|
self.listBox = QTreeWidget()
|
||||||
@@ -77,10 +76,11 @@ class GuiSessionLogView(QDialog):
|
|||||||
|
|
||||||
sortValid = (Qt.AscendingOrder, Qt.DescendingOrder)
|
sortValid = (Qt.AscendingOrder, Qt.DescendingOrder)
|
||||||
sortCol = self.optState.validIntRange(
|
sortCol = self.optState.validIntRange(
|
||||||
self.optState.getSetting("sortCol"), 0, 2, 0
|
self.optState.getInt("GuiSession", "sortCol", 0), 0, 2, 0
|
||||||
)
|
)
|
||||||
sortOrder = self.optState.validIntTuple(
|
sortOrder = self.optState.validIntTuple(
|
||||||
self.optState.getSetting("sortOrder"), sortValid, Qt.DescendingOrder
|
self.optState.getInt("GuiSession", "sortOrder", Qt.DescendingOrder),
|
||||||
|
sortValid, Qt.DescendingOrder
|
||||||
)
|
)
|
||||||
|
|
||||||
self.listBox.sortByColumn(sortCol, sortOrder)
|
self.listBox.sortByColumn(sortCol, sortOrder)
|
||||||
@@ -110,11 +110,15 @@ class GuiSessionLogView(QDialog):
|
|||||||
self.filterBox.setLayout(self.filterBoxForm)
|
self.filterBox.setLayout(self.filterBoxForm)
|
||||||
|
|
||||||
self.hideZeros = QCheckBox("Hide zero word count", self)
|
self.hideZeros = QCheckBox("Hide zero word count", self)
|
||||||
self.hideZeros.setChecked(self.optState.getSetting("hideZeros"))
|
self.hideZeros.setChecked(
|
||||||
|
self.optState.getBool("GuiSession", "hideZeros", True)
|
||||||
|
)
|
||||||
self.hideZeros.stateChanged.connect(self._doHideZeros)
|
self.hideZeros.stateChanged.connect(self._doHideZeros)
|
||||||
|
|
||||||
self.hideNegative = QCheckBox("Hide negative word count", self)
|
self.hideNegative = QCheckBox("Hide negative word count", self)
|
||||||
self.hideNegative.setChecked(self.optState.getSetting("hideNegative"))
|
self.hideNegative.setChecked(
|
||||||
|
self.optState.getBool("GuiSession", "hideNegative", False)
|
||||||
|
)
|
||||||
self.hideNegative.stateChanged.connect(self._doHideNegative)
|
self.hideNegative.stateChanged.connect(self._doHideNegative)
|
||||||
|
|
||||||
self.filterBoxForm.addWidget(self.hideZeros, 0, 0)
|
self.filterBoxForm.addWidget(self.hideZeros, 0, 0)
|
||||||
@@ -208,13 +212,13 @@ class GuiSessionLogView(QDialog):
|
|||||||
hideZeros = self.hideZeros.isChecked()
|
hideZeros = self.hideZeros.isChecked()
|
||||||
hideNegative = self.hideNegative.isChecked()
|
hideNegative = self.hideNegative.isChecked()
|
||||||
|
|
||||||
self.optState.setSetting("widthCol0", widthCol0)
|
self.optState.setValue("GuiSession", "widthCol0", widthCol0)
|
||||||
self.optState.setSetting("widthCol1", widthCol1)
|
self.optState.setValue("GuiSession", "widthCol1", widthCol1)
|
||||||
self.optState.setSetting("widthCol2", widthCol2)
|
self.optState.setValue("GuiSession", "widthCol2", widthCol2)
|
||||||
self.optState.setSetting("sortCol", sortCol)
|
self.optState.setValue("GuiSession", "sortCol", sortCol)
|
||||||
self.optState.setSetting("sortOrder", sortOrder)
|
self.optState.setValue("GuiSession", "sortOrder", sortOrder)
|
||||||
self.optState.setSetting("hideZeros", hideZeros)
|
self.optState.setValue("GuiSession", "hideZeros", hideZeros)
|
||||||
self.optState.setSetting("hideNegative",hideNegative)
|
self.optState.setValue("GuiSession", "hideNegative", hideNegative)
|
||||||
|
|
||||||
self.optState.saveSettings()
|
self.optState.saveSettings()
|
||||||
self.close()
|
self.close()
|
||||||
@@ -237,23 +241,3 @@ class GuiSessionLogView(QDialog):
|
|||||||
return "%02d:%02d:%02d" % (tH,tM,tS)
|
return "%02d:%02d:%02d" % (tH,tM,tS)
|
||||||
|
|
||||||
# END Class GuiSessionLogView
|
# END Class GuiSessionLogView
|
||||||
|
|
||||||
class SessionLogLastState(OptLastState):
|
|
||||||
|
|
||||||
def __init__(self, theProject, theFile):
|
|
||||||
OptLastState.__init__(self, theProject, theFile)
|
|
||||||
self.theState = {
|
|
||||||
"widthCol0" : 180,
|
|
||||||
"widthCol1" : 80,
|
|
||||||
"widthCol2" : 80,
|
|
||||||
"sortCol" : 0,
|
|
||||||
"sortOrder" : Qt.DescendingOrder,
|
|
||||||
"hideZeros" : True,
|
|
||||||
"hideNegative" : False,
|
|
||||||
}
|
|
||||||
self.stringOpt = ()
|
|
||||||
self.boolOpt = ("hideZeros","hideNegative")
|
|
||||||
self.intOpt = ("widthCol0","widthCol1","widthCol2","sortCol","sortOrder")
|
|
||||||
return
|
|
||||||
|
|
||||||
# END Class SessionLogLastState
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from PyQt5.QtWidgets import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from nw.constants import nwFiles, nwItemClass
|
from nw.constants import nwFiles, nwItemClass
|
||||||
from nw.tools import OptLastState
|
from nw.tools import OptionState
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -37,8 +37,7 @@ class GuiTimeLineView(QDialog):
|
|||||||
self.theProject = theProject
|
self.theProject = theProject
|
||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theIndex = theIndex
|
self.theIndex = theIndex
|
||||||
self.optState = TimeLineLastState(self.theProject,nwFiles.TLINE_OPT)
|
self.optState = self.theProject.optState
|
||||||
self.optState.loadSettings()
|
|
||||||
|
|
||||||
self.theMatrix = {}
|
self.theMatrix = {}
|
||||||
self.numRows = 0
|
self.numRows = 0
|
||||||
@@ -54,10 +53,10 @@ class GuiTimeLineView(QDialog):
|
|||||||
self.setMinimumHeight(400)
|
self.setMinimumHeight(400)
|
||||||
|
|
||||||
winWidth = self.optState.validIntRange(
|
winWidth = self.optState.validIntRange(
|
||||||
self.optState.getSetting("winWidth"), 700, 10000, 700
|
self.optState.getInt("GuiTimeLine", "winWidth", 700), 700, 10000, 700
|
||||||
)
|
)
|
||||||
winHeight = self.optState.validIntRange(
|
winHeight = self.optState.validIntRange(
|
||||||
self.optState.getSetting("winHeight"), 400, 10000, 400
|
self.optState.getInt("GuiTimeLine", "winHeight", 400), 400, 10000, 400
|
||||||
)
|
)
|
||||||
self.resize(winWidth,winHeight)
|
self.resize(winWidth,winHeight)
|
||||||
|
|
||||||
@@ -79,27 +78,39 @@ class GuiTimeLineView(QDialog):
|
|||||||
self.optFilter.setLayout(self.optFilterGrid)
|
self.optFilter.setLayout(self.optFilterGrid)
|
||||||
|
|
||||||
self.filterPlot = QCheckBox("Plot tags", self)
|
self.filterPlot = QCheckBox("Plot tags", self)
|
||||||
self.filterPlot.setChecked(self.optState.getSetting("fPlot"))
|
self.filterPlot.setChecked(
|
||||||
|
self.optState.getBool("GuiTimeLine", "fPlot", True)
|
||||||
|
)
|
||||||
self.filterPlot.stateChanged.connect(self._filterChange)
|
self.filterPlot.stateChanged.connect(self._filterChange)
|
||||||
|
|
||||||
self.filterChar = QCheckBox("Character tags", self)
|
self.filterChar = QCheckBox("Character tags", self)
|
||||||
self.filterChar.setChecked(self.optState.getSetting("fChar"))
|
self.filterChar.setChecked(
|
||||||
|
self.optState.getBool("GuiTimeLine", "fChar", True)
|
||||||
|
)
|
||||||
self.filterChar.stateChanged.connect(self._filterChange)
|
self.filterChar.stateChanged.connect(self._filterChange)
|
||||||
|
|
||||||
self.filterWorld = QCheckBox("Location tags", self)
|
self.filterWorld = QCheckBox("Location tags", self)
|
||||||
self.filterWorld.setChecked(self.optState.getSetting("fWorld"))
|
self.filterWorld.setChecked(
|
||||||
|
self.optState.getBool("GuiTimeLine", "fWorld", True)
|
||||||
|
)
|
||||||
self.filterWorld.stateChanged.connect(self._filterChange)
|
self.filterWorld.stateChanged.connect(self._filterChange)
|
||||||
|
|
||||||
self.filterTime = QCheckBox("Timeline tags", self)
|
self.filterTime = QCheckBox("Timeline tags", self)
|
||||||
self.filterTime.setChecked(self.optState.getSetting("fTime"))
|
self.filterTime.setChecked(
|
||||||
|
self.optState.getBool("GuiTimeLine", "fTime", True)
|
||||||
|
)
|
||||||
self.filterTime.stateChanged.connect(self._filterChange)
|
self.filterTime.stateChanged.connect(self._filterChange)
|
||||||
|
|
||||||
self.filterObject = QCheckBox("Object tags", self)
|
self.filterObject = QCheckBox("Object tags", self)
|
||||||
self.filterObject.setChecked(self.optState.getSetting("fObject"))
|
self.filterObject.setChecked(
|
||||||
|
self.optState.getBool("GuiTimeLine", "fObject", True)
|
||||||
|
)
|
||||||
self.filterObject.stateChanged.connect(self._filterChange)
|
self.filterObject.stateChanged.connect(self._filterChange)
|
||||||
|
|
||||||
self.filterCustom = QCheckBox("Custom tags", self)
|
self.filterCustom = QCheckBox("Custom tags", self)
|
||||||
self.filterCustom.setChecked(self.optState.getSetting("fCustom"))
|
self.filterCustom.setChecked(
|
||||||
|
self.optState.getBool("GuiTimeLine", "fCustom", True)
|
||||||
|
)
|
||||||
self.filterCustom.stateChanged.connect(self._filterChange)
|
self.filterCustom.stateChanged.connect(self._filterChange)
|
||||||
|
|
||||||
self.optFilterGrid.addWidget(self.filterPlot, 0, 1)
|
self.optFilterGrid.addWidget(self.filterPlot, 0, 1)
|
||||||
@@ -114,7 +125,9 @@ class GuiTimeLineView(QDialog):
|
|||||||
self.optHide.setLayout(self.optHideGrid)
|
self.optHide.setLayout(self.optHideGrid)
|
||||||
|
|
||||||
self.hideUnused = QCheckBox("Hide unused", self)
|
self.hideUnused = QCheckBox("Hide unused", self)
|
||||||
self.hideUnused.setChecked(self.optState.getSetting("hUnused"))
|
self.hideUnused.setChecked(
|
||||||
|
self.optState.getBool("GuiTimeLine", "hUnused", True)
|
||||||
|
)
|
||||||
self.hideUnused.stateChanged.connect(self._filterChange)
|
self.hideUnused.stateChanged.connect(self._filterChange)
|
||||||
|
|
||||||
self.optHideGrid.addWidget(self.hideUnused, 0, 1)
|
self.optHideGrid.addWidget(self.hideUnused, 0, 1)
|
||||||
@@ -227,15 +240,15 @@ class GuiTimeLineView(QDialog):
|
|||||||
fCustom = self.filterCustom.isChecked()
|
fCustom = self.filterCustom.isChecked()
|
||||||
hUnused = self.hideUnused.isChecked()
|
hUnused = self.hideUnused.isChecked()
|
||||||
|
|
||||||
self.optState.setSetting("winWidth", winWidth)
|
self.optState.setValue("GuiTimeLine", "winWidth", winWidth)
|
||||||
self.optState.setSetting("winHeight",winHeight)
|
self.optState.setValue("GuiTimeLine", "winHeight", winHeight)
|
||||||
self.optState.setSetting("fPlot", fPlot)
|
self.optState.setValue("GuiTimeLine", "fPlot", fPlot)
|
||||||
self.optState.setSetting("fChar", fChar)
|
self.optState.setValue("GuiTimeLine", "fChar", fChar)
|
||||||
self.optState.setSetting("fWorld", fWorld)
|
self.optState.setValue("GuiTimeLine", "fWorld", fWorld)
|
||||||
self.optState.setSetting("fTime", fTime)
|
self.optState.setValue("GuiTimeLine", "fTime", fTime)
|
||||||
self.optState.setSetting("fObject", fObject)
|
self.optState.setValue("GuiTimeLine", "fObject", fObject)
|
||||||
self.optState.setSetting("fCustom", fCustom)
|
self.optState.setValue("GuiTimeLine", "fCustom", fCustom)
|
||||||
self.optState.setSetting("hUnused", hUnused)
|
self.optState.setValue("GuiTimeLine", "hUnused", hUnused)
|
||||||
|
|
||||||
self.optState.saveSettings()
|
self.optState.saveSettings()
|
||||||
self.close()
|
self.close()
|
||||||
@@ -247,25 +260,3 @@ class GuiTimeLineView(QDialog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# END Class GuiTimeLineView
|
# END Class GuiTimeLineView
|
||||||
|
|
||||||
class TimeLineLastState(OptLastState):
|
|
||||||
|
|
||||||
def __init__(self, theProject, theFile):
|
|
||||||
OptLastState.__init__(self, theProject, theFile)
|
|
||||||
self.theState = {
|
|
||||||
"winWidth" : 700,
|
|
||||||
"winHeight" : 400,
|
|
||||||
"fPlot" : True,
|
|
||||||
"fChar" : True,
|
|
||||||
"fWorld" : True,
|
|
||||||
"fTime" : True,
|
|
||||||
"fObject" : True,
|
|
||||||
"fCustom" : True,
|
|
||||||
"hUnused" : True,
|
|
||||||
}
|
|
||||||
self.stringOpt = ()
|
|
||||||
self.boolOpt = ("fPlot","fChar","fWorld","fTime","fObject","fCustom","hUnused")
|
|
||||||
self.intOpt = ("winWidth","winHeight")
|
|
||||||
return
|
|
||||||
|
|
||||||
# END Class TimeLineLastState
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ from time import time
|
|||||||
|
|
||||||
from nw.project.status import NWStatus
|
from nw.project.status import NWStatus
|
||||||
from nw.project.item import NWItem
|
from nw.project.item import NWItem
|
||||||
from nw.tools import projectMaintenance
|
from nw.tools import projectMaintenance, OptionState
|
||||||
from nw.common import checkString, checkBool, checkInt
|
from nw.common import checkString, checkBool, checkInt
|
||||||
from nw.constants import (
|
from nw.constants import (
|
||||||
nwFiles, nwConst, nwItemType, nwItemClass, nwItemLayout, nwAlert
|
nwFiles, nwConst, nwItemType, nwItemClass, nwItemLayout, nwAlert
|
||||||
@@ -36,6 +36,7 @@ class NWProject():
|
|||||||
# Internal
|
# Internal
|
||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.mainConf = self.theParent.mainConf
|
self.mainConf = self.theParent.mainConf
|
||||||
|
self.optState = OptionState(self)
|
||||||
self.projOpened = None # The time stamp of when the project file was opened
|
self.projOpened = None # The time stamp of when the project file was opened
|
||||||
self.projChanged = None # The project has unsaved changes
|
self.projChanged = None # The project has unsaved changes
|
||||||
self.projAltered = None # The project has been altered this session
|
self.projAltered = None # The project has been altered this session
|
||||||
@@ -295,6 +296,7 @@ class NWProject():
|
|||||||
nwItem.setFromTag(xValue.tag,xValue.text)
|
nwItem.setFromTag(xValue.tag,xValue.text)
|
||||||
self._appendItem(tHandle,pHandle,nwItem)
|
self._appendItem(tHandle,pHandle,nwItem)
|
||||||
|
|
||||||
|
self.optState.loadSettings()
|
||||||
self.mainConf.setRecent(self.projPath)
|
self.mainConf.setRecent(self.projPath)
|
||||||
self.theParent.setStatus("Opened Project: %s" % self.projName)
|
self.theParent.setStatus("Opened Project: %s" % self.projName)
|
||||||
|
|
||||||
@@ -384,6 +386,7 @@ class NWProject():
|
|||||||
rename(saveFile, backFile)
|
rename(saveFile, backFile)
|
||||||
rename(tempFile, saveFile)
|
rename(tempFile, saveFile)
|
||||||
|
|
||||||
|
self.optState.saveSettings()
|
||||||
self.mainConf.setRecent(self.projPath)
|
self.mainConf.setRecent(self.projPath)
|
||||||
self.theParent.setStatus("Saved Project: %s" % self.projName)
|
self.theParent.setStatus("Saved Project: %s" % self.projName)
|
||||||
self.setProjectChanged(False)
|
self.setProjectChanged(False)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from nw.tools.analyse import TextAnalysis
|
from nw.tools.analyse import TextAnalysis
|
||||||
from nw.tools.legacy import projectMaintenance
|
from nw.tools.legacy import projectMaintenance
|
||||||
from nw.tools.optlaststate import OptLastState
|
from nw.tools.optionstate import OptionState
|
||||||
from nw.tools.spellcheck import NWSpellCheck
|
from nw.tools.spellcheck import NWSpellCheck
|
||||||
from nw.tools.spellenchant import NWSpellEnchant
|
from nw.tools.spellenchant import NWSpellEnchant
|
||||||
from nw.tools.spellsimple import NWSpellSimple
|
from nw.tools.spellsimple import NWSpellSimple
|
||||||
@@ -12,7 +12,7 @@ from nw.tools.wordcount import countWords
|
|||||||
__all__ = [
|
__all__ = [
|
||||||
"TextAnalysis",
|
"TextAnalysis",
|
||||||
"projectMaintenance",
|
"projectMaintenance",
|
||||||
"OptLastState",
|
"OptionState",
|
||||||
"NWSpellCheck",
|
"NWSpellCheck",
|
||||||
"NWSpellEnchant",
|
"NWSpellEnchant",
|
||||||
"NWSpellSimple",
|
"NWSpellSimple",
|
||||||
|
|||||||
@@ -129,74 +129,22 @@ class OptionState():
|
|||||||
return defaultValue
|
return defaultValue
|
||||||
return defaultValue
|
return defaultValue
|
||||||
|
|
||||||
# END Class OptionState
|
|
||||||
|
|
||||||
class OptLastState():
|
|
||||||
|
|
||||||
def __init__(self, theProject, theFile):
|
|
||||||
self.theProject = theProject
|
|
||||||
self.theFile = theFile
|
|
||||||
self.theState = {}
|
|
||||||
self.stringOpt = ()
|
|
||||||
self.boolOpt = ()
|
|
||||||
self.intOpt = ()
|
|
||||||
return
|
|
||||||
|
|
||||||
def loadSettings(self):
|
|
||||||
stateFile = path.join(self.theProject.projMeta,self.theFile)
|
|
||||||
theState = {}
|
|
||||||
if path.isfile(stateFile):
|
|
||||||
logger.debug("Loading options file")
|
|
||||||
try:
|
|
||||||
with open(stateFile,mode="r",encoding="utf8") as inFile:
|
|
||||||
theJson = inFile.read()
|
|
||||||
theState = json.loads(theJson)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error("Failed to load options file")
|
|
||||||
logger.error(str(e))
|
|
||||||
return False
|
|
||||||
for anOpt in theState:
|
|
||||||
self.theState[anOpt] = theState[anOpt]
|
|
||||||
return True
|
|
||||||
|
|
||||||
def saveSettings(self):
|
|
||||||
stateFile = path.join(self.theProject.projMeta,self.theFile)
|
|
||||||
logger.debug("Saving options file")
|
|
||||||
try:
|
|
||||||
with open(stateFile,mode="w+",encoding="utf8") as outFile:
|
|
||||||
outFile.write(json.dumps(self.theState, indent=2))
|
|
||||||
except Exception as e:
|
|
||||||
logger.error("Failed to save options file")
|
|
||||||
logger.error(str(e))
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def setSetting(self, setName, setValue):
|
|
||||||
if setName in self.theState:
|
|
||||||
self.theState[setName] = setValue
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def getSetting(self, setName):
|
|
||||||
if setName in self.stringOpt:
|
|
||||||
return checkString(self.theState[setName],self.theState[setName],False)
|
|
||||||
elif setName in self.boolOpt:
|
|
||||||
return checkBool(self.theState[setName],self.theState[setName],False)
|
|
||||||
elif setName in self.intOpt:
|
|
||||||
return checkInt(self.theState[setName],self.theState[setName],False)
|
|
||||||
return None
|
|
||||||
|
|
||||||
def validIntRange(self, theValue, intA, intB, intDefault):
|
def validIntRange(self, theValue, intA, intB, intDefault):
|
||||||
|
"""Check that an int is in a given range. If it isn't, return
|
||||||
|
the default value.
|
||||||
|
"""
|
||||||
if isinstance(theValue, int):
|
if isinstance(theValue, int):
|
||||||
if theValue >= intA and theValue <= intB:
|
if theValue >= intA and theValue <= intB:
|
||||||
return theValue
|
return theValue
|
||||||
return intDefault
|
return intDefault
|
||||||
|
|
||||||
def validIntTuple(self, theValue, theTuple, intDefault):
|
def validIntTuple(self, theValue, theTuple, intDefault):
|
||||||
|
"""Check that an int is an element of a tuple. If it isn't,
|
||||||
|
return the default value.
|
||||||
|
"""
|
||||||
if isinstance(theValue, int):
|
if isinstance(theValue, int):
|
||||||
if theValue in theTuple:
|
if theValue in theTuple:
|
||||||
return theValue
|
return theValue
|
||||||
return intDefault
|
return intDefault
|
||||||
|
|
||||||
# END Class OptLastState
|
# END Class OptionState
|
||||||
Reference in New Issue
Block a user