Added some more options to the export GUI and the ability to skip scene and section titles
This commit is contained in:
@@ -37,6 +37,7 @@ class LaTeXFile(TextFile):
|
||||
self.outFile = open(filePath,mode="wt+",encoding="utf8")
|
||||
self.outFile.write("\\documentclass[12pt]{report}\n")
|
||||
self.outFile.write("\\usepackage[utf8]{inputenc}\n")
|
||||
self.outFile.write("\\usepackage[T1]{fontenc}\n")
|
||||
self.outFile.write("\n")
|
||||
self.outFile.write("\\begin{document}\n")
|
||||
except Exception as e:
|
||||
|
||||
@@ -39,7 +39,7 @@ class TextFile():
|
||||
self.makeAlert = self.theParent.makeAlert
|
||||
|
||||
self.setComments(False)
|
||||
self.setMeta(False)
|
||||
self.setKeywords(False)
|
||||
self.setWordWrap(80)
|
||||
|
||||
return
|
||||
@@ -60,8 +60,8 @@ class TextFile():
|
||||
self.theConv.setComments(doComments)
|
||||
return
|
||||
|
||||
def setMeta(self, doMeta):
|
||||
self.theConv.setCommands(doMeta)
|
||||
def setKeywords(self, doKeywords):
|
||||
self.theConv.setKeywords(doKeywords)
|
||||
return
|
||||
|
||||
def setWordWrap(self, wordWrap):
|
||||
@@ -83,12 +83,12 @@ class TextFile():
|
||||
self.theConv.setUnNumberedFormat(fmtUnNum)
|
||||
return
|
||||
|
||||
def setSceneFormat(self, fmtScene):
|
||||
self.theConv.setSceneFormat(fmtScene)
|
||||
def setSceneFormat(self, fmtScene, hideScene):
|
||||
self.theConv.setSceneFormat(fmtScene, hideScene)
|
||||
return
|
||||
|
||||
def setSectionFormat(self, fmtSection):
|
||||
self.theConv.setSectionFormat(fmtSection)
|
||||
def setSectionFormat(self, fmtSection, hideSection):
|
||||
self.theConv.setSectionFormat(fmtSection, hideSection)
|
||||
return
|
||||
|
||||
##
|
||||
|
||||
@@ -83,7 +83,10 @@ class ToHtml(Tokenizer):
|
||||
self.theResult += "<h4%s>%s</h4>\n" % (hStyle,tText)
|
||||
|
||||
elif tType == self.T_SEP:
|
||||
self.theResult += "<div%s>%s</div>\n" % (hStyle,tText)
|
||||
self.theResult += "<p%s>%s</p>\n" % (hStyle,tText)
|
||||
|
||||
elif tType == self.T_SKIP:
|
||||
self.theResult += "<p> </p>\n"
|
||||
|
||||
elif tType == self.T_TEXT:
|
||||
tTemp = tText
|
||||
@@ -94,8 +97,8 @@ class ToHtml(Tokenizer):
|
||||
elif tType == self.T_COMMENT and self.doComments:
|
||||
self.theResult += "<div class='comment'>%s</div>\n" % tText
|
||||
|
||||
elif tType == self.T_COMMAND and self.doCommands:
|
||||
self.theResult += "<pre>%s</pre>\n" % tText
|
||||
elif tType == self.T_KEYWORD and self.doKeywords:
|
||||
self.theResult += "<pre>@%s</pre>\n" % tText
|
||||
|
||||
# print(self.theResult)
|
||||
|
||||
|
||||
@@ -90,6 +90,10 @@ class ToLaTeX(Tokenizer):
|
||||
self.theResult += "%s\n" % self._escapeUnicode(tText)
|
||||
self.theResult += endText
|
||||
|
||||
elif tType == self.T_SKIP:
|
||||
self.theResult += "\\bigskip\n"
|
||||
self.theResult += "\\bigskip\n\n"
|
||||
|
||||
elif tType == self.T_TEXT:
|
||||
thisPar.append(self._escapeUnicode(tText))
|
||||
|
||||
@@ -99,7 +103,7 @@ class ToLaTeX(Tokenizer):
|
||||
elif tType == self.T_COMMENT and self.doComments:
|
||||
self.theResult += "%s\n\n" % tText
|
||||
|
||||
elif tType == self.T_COMMAND and self.doCommands:
|
||||
elif tType == self.T_KEYWORD and self.doKeywords:
|
||||
self.theResult += "%% @%s\n\n" % tText
|
||||
|
||||
return
|
||||
|
||||
@@ -98,13 +98,16 @@ class ToMarkdown(Tokenizer):
|
||||
elif tType == self.T_SEP:
|
||||
self.theResult += "%s\n\n" % tText
|
||||
|
||||
elif tType == self.T_SKIP:
|
||||
self.theResult += "\n\n\n\n"
|
||||
|
||||
elif tType == self.T_TEXT:
|
||||
thisPar.append(tText)
|
||||
|
||||
elif tType == self.T_COMMENT and self.doComments:
|
||||
self.theResult += "%s\n\n" % tText
|
||||
|
||||
elif tType == self.T_COMMAND and self.doCommands:
|
||||
elif tType == self.T_KEYWORD and self.doKeywords:
|
||||
self.theResult += "%s\n\n" % tText
|
||||
|
||||
return
|
||||
|
||||
@@ -105,13 +105,16 @@ class ToText(Tokenizer):
|
||||
tText = self._centreText(tText,self.wordWrap)
|
||||
self.theResult += "%s\n\n" % tText
|
||||
|
||||
elif tType == self.T_SEP:
|
||||
self.theResult += "\n\n\n\n"
|
||||
|
||||
elif tType == self.T_TEXT:
|
||||
thisPar.append(tText)
|
||||
|
||||
elif tType == self.T_COMMENT and self.doComments:
|
||||
self.theResult += "%s\n\n" % tText
|
||||
|
||||
elif tType == self.T_COMMAND and self.doCommands:
|
||||
elif tType == self.T_KEYWORD and self.doKeywords:
|
||||
self.theResult += "%s\n\n" % tText
|
||||
|
||||
return
|
||||
|
||||
+41
-30
@@ -35,14 +35,15 @@ class Tokenizer():
|
||||
|
||||
T_EMPTY = 1 # Empty line (new paragraph)
|
||||
T_COMMENT = 2 # Comment line
|
||||
T_COMMAND = 3 # Command line
|
||||
T_KEYWORD = 3 # Command line
|
||||
T_HEAD1 = 4 # Header 1 (title)
|
||||
T_HEAD2 = 5 # Header 2 (chapter)
|
||||
T_HEAD3 = 6 # Header 3 (scene)
|
||||
T_HEAD4 = 7 # Header 4
|
||||
T_TEXT = 8 # Text line
|
||||
T_SEP = 9 # Scene separator
|
||||
T_PBREAK = 10 # Page break
|
||||
T_SKIP = 10 # Scene separator
|
||||
T_PBREAK = 11 # Page break
|
||||
|
||||
A_LEFT = 1 # Left aligned
|
||||
A_RIGHT = 2 # Right aligned
|
||||
@@ -51,30 +52,31 @@ class Tokenizer():
|
||||
|
||||
def __init__(self, theProject, theParent):
|
||||
|
||||
self.mainConf = nw.CONFIG
|
||||
self.theProject = theProject
|
||||
self.theParent = theParent
|
||||
self.mainConf = nw.CONFIG
|
||||
self.theProject = theProject
|
||||
self.theParent = theParent
|
||||
|
||||
self.theText = None
|
||||
self.theHandle = None
|
||||
self.theItem = None
|
||||
self.theTokens = None
|
||||
self.theResult = None
|
||||
self.theText = None
|
||||
self.theHandle = None
|
||||
self.theItem = None
|
||||
self.theTokens = None
|
||||
self.theResult = None
|
||||
|
||||
self.wordWrap = 80
|
||||
self.doComments = False
|
||||
self.doCommands = False
|
||||
self.wordWrap = 80
|
||||
self.doComments = False
|
||||
self.doKeywords = False
|
||||
|
||||
self.fmtTitle = "%title%"
|
||||
self.fmtChapter = "Chapter %numword%: %title%"
|
||||
self.fmtUnNum = "%title%"
|
||||
self.fmtScene = "* * *"
|
||||
self.fmtSection = "%title%"
|
||||
self.fmtTitle = "%title%"
|
||||
self.fmtChapter = "Chapter %numword%: %title%"
|
||||
self.fmtUnNum = "%title%"
|
||||
self.fmtScene = "* * *"
|
||||
self.fmtSection = "%title%"
|
||||
|
||||
self.noSection = True
|
||||
self.hideScene = False
|
||||
self.hideSection = False
|
||||
|
||||
self.numChapter = 0
|
||||
self.firstScene = False
|
||||
self.numChapter = 0
|
||||
self.firstScene = False
|
||||
|
||||
return
|
||||
|
||||
@@ -86,8 +88,8 @@ class Tokenizer():
|
||||
self.doComments = doComments
|
||||
return
|
||||
|
||||
def setCommands(self, doCommands):
|
||||
self.doCommands = doCommands
|
||||
def setKeywords(self, doKeywords):
|
||||
self.doKeywords = doKeywords
|
||||
return
|
||||
|
||||
def setWordWrap(self, wordWrap):
|
||||
@@ -109,12 +111,14 @@ class Tokenizer():
|
||||
self.fmtUnNum = fmtUnNum
|
||||
return
|
||||
|
||||
def setSceneFormat(self, fmtScene):
|
||||
self.fmtScene = fmtScene
|
||||
def setSceneFormat(self, fmtScene, hideScene):
|
||||
self.fmtScene = fmtScene
|
||||
self.hideScene = hideScene
|
||||
return
|
||||
|
||||
def setSectionFormat(self, fmtSection):
|
||||
self.fmtSection = fmtSection
|
||||
def setSectionFormat(self, fmtSection, hideSection):
|
||||
self.fmtSection = fmtSection
|
||||
self.hideSection = hideSection
|
||||
return
|
||||
|
||||
##
|
||||
@@ -175,7 +179,7 @@ class Tokenizer():
|
||||
elif aLine[0] == "%":
|
||||
self.theTokens.append((self.T_COMMENT,aLine[1:].strip(),None,self.A_LEFT))
|
||||
elif aLine[0] == "@":
|
||||
self.theTokens.append((self.T_COMMAND,aLine[1:].strip(),None,self.A_LEFT))
|
||||
self.theTokens.append((self.T_KEYWORD,aLine[1:].strip(),None,self.A_LEFT))
|
||||
elif aLine[:2] == "# ":
|
||||
self.theTokens.append((self.T_HEAD1,aLine[2:].strip(),None,self.A_LEFT))
|
||||
elif aLine[:3] == "## ":
|
||||
@@ -242,8 +246,13 @@ class Tokenizer():
|
||||
|
||||
elif tType == self.T_HEAD3:
|
||||
tTemp = self._doFormatScene(tText)
|
||||
if tTemp == "":
|
||||
if tTemp == "" and self.hideScene:
|
||||
self.theTokens[n] = (self.T_EMPTY,"",None,self.A_LEFT)
|
||||
elif tTemp == "" and not self.hideScene:
|
||||
if self.firstScene:
|
||||
self.theTokens[n] = (self.T_EMPTY,"",None,self.A_LEFT)
|
||||
else:
|
||||
self.theTokens[n] = (self.T_SKIP,"",None,self.A_LEFT)
|
||||
elif tTemp == self.fmtScene:
|
||||
if self.firstScene:
|
||||
self.theTokens[n] = (self.T_EMPTY,"",None,self.A_LEFT)
|
||||
@@ -255,8 +264,10 @@ class Tokenizer():
|
||||
|
||||
elif tType == self.T_HEAD4:
|
||||
tTemp = self._doFormatSection(tText)
|
||||
if tTemp == "":
|
||||
if tTemp == "" and self.hideSection:
|
||||
self.theTokens[n] = (self.T_EMPTY,"",None,self.A_LEFT)
|
||||
elif tTemp == "" and not self.hideSection:
|
||||
self.theTokens[n] = (self.T_SKIP,"",None,self.A_LEFT)
|
||||
elif tTemp == self.fmtSection:
|
||||
self.theTokens[n] = (self.T_SEP,tTemp,None,self.A_CENTRE)
|
||||
else:
|
||||
|
||||
+38
-12
@@ -109,11 +109,14 @@ class GuiExport(QDialog):
|
||||
eFormat = self.tabMain.outputFormat.currentData()
|
||||
fixWidth = self.tabMain.fixedWidth.value()
|
||||
wComments = self.tabMain.expComments.isChecked()
|
||||
wKeywords = self.tabMain.expKeywords.isChecked()
|
||||
chFormat = self.tabMain.chapterFormat.text()
|
||||
unFormat = self.tabMain.unnumFormat.text()
|
||||
scFormat = self.tabMain.sceneFormat.text()
|
||||
seFormat = self.tabMain.sectionFormat.text()
|
||||
saveTo = self.tabMain.exportPath.text()
|
||||
hScene = self.tabMain.hideScene.isChecked()
|
||||
hSection = self.tabMain.hideSection.isChecked()
|
||||
|
||||
pFormat = self.tabPandoc.outputFormat.currentData()
|
||||
tFormat = GuiExportPandoc.FMT_VIA[pFormat]
|
||||
@@ -151,13 +154,14 @@ class GuiExport(QDialog):
|
||||
|
||||
if outFile.openFile(saveTo):
|
||||
outFile.setComments(wComments)
|
||||
outFile.setKeywords(wKeywords)
|
||||
outFile.setExportNovel(wNovel)
|
||||
outFile.setExportNotes(wNotes)
|
||||
outFile.setWordWrap(fixWidth)
|
||||
outFile.setChapterFormat(chFormat)
|
||||
outFile.setUnNumberedFormat(unFormat)
|
||||
outFile.setSceneFormat(scFormat)
|
||||
outFile.setSectionFormat(seFormat)
|
||||
outFile.setSceneFormat(scFormat, hScene)
|
||||
outFile.setSectionFormat(seFormat, hSection)
|
||||
else:
|
||||
self.exportStatus.setText("Failed to open file for writing ...")
|
||||
return False
|
||||
@@ -270,22 +274,28 @@ class GuiExport(QDialog):
|
||||
eFormat = self.tabMain.outputFormat.currentData()
|
||||
fixWidth = self.tabMain.fixedWidth.value()
|
||||
wComments = self.tabMain.expComments.isChecked()
|
||||
wKeywords = self.tabMain.expKeywords.isChecked()
|
||||
chFormat = self.tabMain.chapterFormat.text()
|
||||
unFormat = self.tabMain.unnumFormat.text()
|
||||
scFormat = self.tabMain.sceneFormat.text()
|
||||
seFormat = self.tabMain.sectionFormat.text()
|
||||
saveTo = self.tabMain.exportPath.text()
|
||||
hScene = self.tabMain.hideScene.isChecked()
|
||||
hSection = self.tabMain.hideSection.isChecked()
|
||||
|
||||
self.optState.setSetting("wNovel", wNovel)
|
||||
self.optState.setSetting("wNotes", wNotes)
|
||||
self.optState.setSetting("eFormat", eFormat)
|
||||
self.optState.setSetting("fixWidth", fixWidth)
|
||||
self.optState.setSetting("wComments",wComments)
|
||||
self.optState.setSetting("wKeywords",wKeywords)
|
||||
self.optState.setSetting("chFormat", chFormat)
|
||||
self.optState.setSetting("unFormat", unFormat)
|
||||
self.optState.setSetting("scFormat", scFormat)
|
||||
self.optState.setSetting("seFormat", seFormat)
|
||||
self.optState.setSetting("saveTo", saveTo)
|
||||
self.optState.setSetting("hScene", hScene)
|
||||
self.optState.setSetting("hSection", hSection)
|
||||
|
||||
# Pandoc Settings
|
||||
pFormat = self.tabPandoc.outputFormat.currentData()
|
||||
@@ -356,24 +366,27 @@ class GuiExportMain(QWidget):
|
||||
self.guiFilesForm = QGridLayout(self)
|
||||
self.guiFiles.setLayout(self.guiFilesForm)
|
||||
|
||||
self.expNovel = QCheckBox(self)
|
||||
self.expNovel = QCheckBox("Novel files",self)
|
||||
self.expNovel.setChecked(self.optState.getSetting("wNovel"))
|
||||
self.expNovel.setToolTip("Include all novel files in the exported document")
|
||||
|
||||
self.expNotes = QCheckBox(self)
|
||||
self.expNotes = QCheckBox("Note files",self)
|
||||
self.expNotes.setChecked(self.optState.getSetting("wNotes"))
|
||||
self.expNotes.setToolTip("Include all note files in the exported document")
|
||||
|
||||
self.expComments = QCheckBox(self)
|
||||
self.expComments = QCheckBox("Comments",self)
|
||||
self.expComments.setChecked(self.optState.getSetting("wComments"))
|
||||
self.expComments.setToolTip("Export comments from all files")
|
||||
|
||||
self.guiFilesForm.addWidget(QLabel("Novel files"), 0, 0)
|
||||
self.guiFilesForm.addWidget(self.expNovel, 0, 1)
|
||||
self.guiFilesForm.addWidget(QLabel("Note files"), 1, 0)
|
||||
self.guiFilesForm.addWidget(self.expNotes, 1, 1)
|
||||
self.guiFilesForm.addWidget(QLabel("Comments"), 2, 0)
|
||||
self.guiFilesForm.addWidget(self.expComments, 2, 1)
|
||||
self.expKeywords = QCheckBox("Keywords",self)
|
||||
self.expKeywords.setChecked(self.optState.getSetting("wKeywords"))
|
||||
self.expKeywords.setToolTip("Export @keywords from all files")
|
||||
|
||||
self.guiFilesForm.addWidget(self.expNovel, 0, 1)
|
||||
self.guiFilesForm.addWidget(self.expComments, 0, 2)
|
||||
self.guiFilesForm.addWidget(self.expNotes, 1, 1)
|
||||
self.guiFilesForm.addWidget(self.expKeywords, 1, 2)
|
||||
self.guiFilesForm.setRowStretch(2, 1)
|
||||
|
||||
# Chapter Settings
|
||||
self.guiChapters = QGroupBox("Chapter Headings", self)
|
||||
@@ -410,10 +423,20 @@ class GuiExportMain(QWidget):
|
||||
self.sectionFormat.setToolTip("Available formats: %title%")
|
||||
self.sectionFormat.setMinimumWidth(100)
|
||||
|
||||
self.hideScene = QCheckBox("Skip",self)
|
||||
self.hideScene.setChecked(self.optState.getSetting("hScene"))
|
||||
self.hideScene.setToolTip("Skip scene titles in export")
|
||||
|
||||
self.hideSection = QCheckBox("Skip",self)
|
||||
self.hideSection.setChecked(self.optState.getSetting("hSection"))
|
||||
self.hideSection.setToolTip("Skip section titles in export")
|
||||
|
||||
self.guiScenesForm.addWidget(QLabel("Scenes"), 0, 0)
|
||||
self.guiScenesForm.addWidget(self.sceneFormat, 0, 1)
|
||||
self.guiScenesForm.addWidget(self.hideScene, 0, 2)
|
||||
self.guiScenesForm.addWidget(QLabel("Sections"), 1, 0)
|
||||
self.guiScenesForm.addWidget(self.sectionFormat, 1, 1)
|
||||
self.guiScenesForm.addWidget(self.hideSection, 1, 2)
|
||||
|
||||
# Output Path
|
||||
self.exportTo = QGroupBox("Export Folder", self)
|
||||
@@ -650,14 +673,17 @@ class ExportLastState(OptLastState):
|
||||
"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")
|
||||
self.boolOpt = ("wNovel","wNotes","wComments","wKeywords","hScene","hSection")
|
||||
self.intOpt = ("eFormat","pFormat","fixWidth")
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user