From f9f8d292d1ff580950fcb72804d1174c455f5a6c Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Tue, 11 Jun 2019 15:43:04 +0200 Subject: [PATCH] Finished all the autoreplace options in the config gui --- nw/config.py | 96 ++++++++------------- nw/constants.py | 23 ------ nw/gui/configeditor.py | 184 ++++++++++++++++++++++++++++++----------- nw/gui/doceditor.py | 13 ++- 4 files changed, 181 insertions(+), 135 deletions(-) diff --git a/nw/config.py b/nw/config.py index 8cb91674..e7da0533 100644 --- a/nw/config.py +++ b/nw/config.py @@ -14,11 +14,9 @@ import logging import configparser import nw -from os import path, mkdir, getcwd -from appdirs import user_config_dir -from datetime import datetime - -from nw.constants import nwQuotes +from os import path, mkdir, getcwd +from appdirs import user_config_dir +from datetime import datetime logger = logging.getLogger(__name__) @@ -79,13 +77,10 @@ class Config: self.doReplaceDQuote = True self.doReplaceDash = True self.doReplaceDots = True - self.styleSQuote = 1 - self.styleDQuote = 1 self.wordCountTimer = 5.0 - self.fmtDoubleQuotes = ["“","”"] self.fmtSingleQuotes = ["‘","’"] - self.fmtApostrophe = "’" + self.fmtDoubleQuotes = ["“","”"] self.spellLanguage = "en_GB" @@ -160,31 +155,28 @@ class Config: ## Editor cnfSec = "Editor" - self.textFont = self._parseLine(cnfParse, cnfSec, "textfont", self.CNF_STR, self.textFont) - self.textSize = self._parseLine(cnfParse, cnfSec, "textsize", self.CNF_INT, self.textSize) - self.textFixedW = self._parseLine(cnfParse, cnfSec, "fixedwidth", self.CNF_BOOL, self.textFixedW) - self.textWidth = self._parseLine(cnfParse, cnfSec, "width", self.CNF_INT, self.textWidth) - self.textMargin = self._parseLine(cnfParse, cnfSec, "margins", self.CNF_LIST, self.textMargin) - self.tabWidth = self._parseLine(cnfParse, cnfSec, "tabwidth", self.CNF_INT, self.tabWidth) - self.doJustify = self._parseLine(cnfParse, cnfSec, "justify", self.CNF_BOOL, self.doJustify) - self.autoSelect = self._parseLine(cnfParse, cnfSec, "autoselect", self.CNF_BOOL, self.autoSelect) - self.doReplace = self._parseLine(cnfParse, cnfSec, "autoreplace", self.CNF_BOOL, self.doReplace) - self.doReplaceSQuote = self._parseLine(cnfParse, cnfSec, "repsquotes", self.CNF_BOOL, self.doReplaceSQuote) - self.doReplaceDQuote = self._parseLine(cnfParse, cnfSec, "repdquotes", self.CNF_BOOL, self.doReplaceDQuote) - self.doReplaceDash = self._parseLine(cnfParse, cnfSec, "repdash", self.CNF_BOOL, self.doReplaceDash) - self.doReplaceDots = self._parseLine(cnfParse, cnfSec, "repdots", self.CNF_BOOL, self.doReplaceDots) - self.styleSQuote = self._parseLine(cnfParse, cnfSec, "stylesquote", self.CNF_INT, self.styleSQuote) - self.styleDQuote = self._parseLine(cnfParse, cnfSec, "styledquote", self.CNF_INT, self.styleDQuote) - self.spellLanguage = self._parseLine(cnfParse, cnfSec, "spellcheck", self.CNF_STR, self.spellLanguage) + self.textFont = self._parseLine(cnfParse, cnfSec, "textfont", self.CNF_STR, self.textFont) + self.textSize = self._parseLine(cnfParse, cnfSec, "textsize", self.CNF_INT, self.textSize) + self.textFixedW = self._parseLine(cnfParse, cnfSec, "fixedwidth", self.CNF_BOOL, self.textFixedW) + self.textWidth = self._parseLine(cnfParse, cnfSec, "width", self.CNF_INT, self.textWidth) + self.textMargin = self._parseLine(cnfParse, cnfSec, "margins", self.CNF_LIST, self.textMargin) + self.tabWidth = self._parseLine(cnfParse, cnfSec, "tabwidth", self.CNF_INT, self.tabWidth) + self.doJustify = self._parseLine(cnfParse, cnfSec, "justify", self.CNF_BOOL, self.doJustify) + self.autoSelect = self._parseLine(cnfParse, cnfSec, "autoselect", self.CNF_BOOL, self.autoSelect) + self.doReplace = self._parseLine(cnfParse, cnfSec, "autoreplace", self.CNF_BOOL, self.doReplace) + self.doReplaceSQuote = self._parseLine(cnfParse, cnfSec, "repsquotes", self.CNF_BOOL, self.doReplaceSQuote) + self.doReplaceDQuote = self._parseLine(cnfParse, cnfSec, "repdquotes", self.CNF_BOOL, self.doReplaceDQuote) + self.doReplaceDash = self._parseLine(cnfParse, cnfSec, "repdash", self.CNF_BOOL, self.doReplaceDash) + self.doReplaceDots = self._parseLine(cnfParse, cnfSec, "repdots", self.CNF_BOOL, self.doReplaceDots) + self.fmtSingleQuotes = self._parseLine(cnfParse, cnfSec, "fmtsinglequote", self.CNF_LIST, self.fmtSingleQuotes) + self.fmtDoubleQuotes = self._parseLine(cnfParse, cnfSec, "fmtdoublequote", self.CNF_LIST, self.fmtDoubleQuotes) + self.spellLanguage = self._parseLine(cnfParse, cnfSec, "spellcheck", self.CNF_STR, self.spellLanguage) ## Path cnfSec = "Path" for i in range(10): self.recentList[i] = self._parseLine(cnfParse, cnfSec, "recent%d" % i,self.CNF_STR, self.recentList[i]) - self.setSingleQuotes(self.styleSQuote) - self.setDoubleQuotes(self.styleDQuote) - return True def saveConfig(self): @@ -218,22 +210,22 @@ class Config: ## Editor cnfSec = "Editor" cnfParse.add_section(cnfSec) - cnfParse.set(cnfSec,"textfont", str(self.textFont)) - cnfParse.set(cnfSec,"textsize", str(self.textSize)) - cnfParse.set(cnfSec,"fixedwidth", str(self.textFixedW)) - cnfParse.set(cnfSec,"width", str(self.textWidth)) - cnfParse.set(cnfSec,"margins", self._packList(self.textMargin)) - cnfParse.set(cnfSec,"tabwidth", str(self.tabWidth)) - cnfParse.set(cnfSec,"justify", str(self.doJustify)) - cnfParse.set(cnfSec,"autoselect", str(self.autoSelect)) - cnfParse.set(cnfSec,"autoreplace",str(self.doReplace)) - cnfParse.set(cnfSec,"repsquotes", str(self.doReplaceSQuote)) - cnfParse.set(cnfSec,"repdquotes", str(self.doReplaceDQuote)) - cnfParse.set(cnfSec,"repdash", str(self.doReplaceDash)) - cnfParse.set(cnfSec,"repdots", str(self.doReplaceDots)) - cnfParse.set(cnfSec,"stylesquote",str(self.styleSQuote)) - cnfParse.set(cnfSec,"styledquote",str(self.styleDQuote)) - cnfParse.set(cnfSec,"spellcheck", str(self.spellLanguage)) + cnfParse.set(cnfSec,"textfont", str(self.textFont)) + cnfParse.set(cnfSec,"textsize", str(self.textSize)) + cnfParse.set(cnfSec,"fixedwidth", str(self.textFixedW)) + cnfParse.set(cnfSec,"width", str(self.textWidth)) + cnfParse.set(cnfSec,"margins", self._packList(self.textMargin)) + cnfParse.set(cnfSec,"tabwidth", str(self.tabWidth)) + cnfParse.set(cnfSec,"justify", str(self.doJustify)) + cnfParse.set(cnfSec,"autoselect", str(self.autoSelect)) + cnfParse.set(cnfSec,"autoreplace", str(self.doReplace)) + cnfParse.set(cnfSec,"repsquotes", str(self.doReplaceSQuote)) + cnfParse.set(cnfSec,"repdquotes", str(self.doReplaceDQuote)) + cnfParse.set(cnfSec,"repdash", str(self.doReplaceDash)) + cnfParse.set(cnfSec,"repdots", str(self.doReplaceDots)) + cnfParse.set(cnfSec,"fmtsinglequote",self._packList(self.fmtSingleQuotes)) + cnfParse.set(cnfSec,"fmtdoublequote",self._packList(self.fmtDoubleQuotes)) + cnfParse.set(cnfSec,"spellcheck", str(self.spellLanguage)) ## Path cnfSec = "Path" @@ -305,22 +297,6 @@ class Config: self.confChanged = True return True - def setSingleQuotes(self, quoteStyle): - if quoteStyle >= 0 and quoteStyle < len(nwQuotes.SINGLE): - self.fmtSingleQuotes[0] = nwQuotes.SINGLE[quoteStyle][0] - self.fmtSingleQuotes[1] = nwQuotes.SINGLE[quoteStyle][1] - self.styleSQuote = quoteStyle - return True - return False - - def setDoubleQuotes(self, quoteStyle): - if quoteStyle >= 0 and quoteStyle < len(nwQuotes.DOUBLE): - self.fmtDoubleQuotes[0] = nwQuotes.DOUBLE[quoteStyle][0] - self.fmtDoubleQuotes[1] = nwQuotes.DOUBLE[quoteStyle][1] - self.styleDQuote = quoteStyle - return True - return False - ## # Internal Functions ## diff --git a/nw/constants.py b/nw/constants.py index 9c93901c..8a545d0c 100644 --- a/nw/constants.py +++ b/nw/constants.py @@ -70,26 +70,3 @@ class nwLabels(): } # END Class nwLabels - -class nwQuotes(): - - SINGLE = [ - ("'", "'", "Straight"), - ("‘", "’", "English"), - ("‹", "›", "French"), - ("›", "‹", "Danish"), - ("’", "’", "Swedish"), - ("‚", "‘", "German"), - ("’", "‚", "Dutch"), - ] - DOUBLE = [ - ("\"", "\"", "Straight"), - ("“", "”", "English"), - ("«", "»", "French"), - ("»", "«", "Danish"), - ("”", "”", "Swedish"), - ("„", "“", "German"), - ("„", "”", "Dutch"), - ] - -# END Class nwQuotes diff --git a/nw/gui/configeditor.py b/nw/gui/configeditor.py index 9ba93299..f08a5385 100644 --- a/nw/gui/configeditor.py +++ b/nw/gui/configeditor.py @@ -23,8 +23,7 @@ from PyQt5.QtWidgets import ( QWidget, QTabWidget, QDialogButtonBox, QSpinBox, QGroupBox, QComboBox, QMessageBox, QCheckBox, QGridLayout, QFontComboBox ) -from nw.enum import nwAlert -from nw.constants import nwQuotes +from nw.enum import nwAlert logger = logging.getLogger(__name__) @@ -76,9 +75,16 @@ class GuiConfigEditor(QDialog): logger.verbose("ConfigEditor save button clicked") + validEntries = True needsRestart = False - needsRestart |= self.tabMain.saveValues() - needsRestart |= self.tabEditor.saveValues() + + retA, retB = self.tabMain.saveValues() + validEntries &= retA + needsRestart |= retB + + retA, retB = self.tabEditor.saveValues() + validEntries &= retA + needsRestart |= retB if needsRestart: msgBox = QMessageBox() @@ -87,7 +93,8 @@ class GuiConfigEditor(QDialog): "Some changes will not be applied until
%s has been restarted." % nw.__package__ ) - self.accept() + if validEntries: + self.accept() return @@ -149,12 +156,14 @@ class GuiConfigEditGeneral(QWidget): def saveValues(self): + validEntries = True + needsRestart = False + autoSaveDoc = self.autoSaveDoc.value() autoSaveProj = self.autoSaveProj.value() guiTheme = self.guiLookTheme.currentData() # Check if restart is needed - needsRestart = False needsRestart |= self.mainConf.guiTheme != guiTheme self.mainConf.autoSaveDoc = autoSaveDoc @@ -162,7 +171,7 @@ class GuiConfigEditGeneral(QWidget): self.mainConf.guiTheme = guiTheme self.mainConf.confChanged = True - return needsRestart + return validEntries, needsRestart # END Class GuiConfigEditGeneral @@ -181,7 +190,7 @@ class GuiConfigEditEditor(QWidget): self.textStyle.setLayout(self.textStyleForm) self.textStyleFont = QFontComboBox() - self.textStyleFont.setMaximumWidth(300) + self.textStyleFont.setMaximumWidth(250) self.textStyleFont.setCurrentFont(QFont(self.mainConf.textFont)) self.textStyleSize = QSpinBox(self) @@ -230,7 +239,7 @@ class GuiConfigEditEditor(QWidget): self.textFlowForm.addWidget(QLabel("Fixed Width"), 0, 0) self.textFlowForm.addWidget(self.textFlowFixed, 0, 1) self.textFlowForm.addWidget(self.textFlowWidth, 0, 2) - self.textFlowForm.addWidget(QLabel("pixles"), 0, 3) + self.textFlowForm.addWidget(QLabel("px"), 0, 3) self.textFlowForm.addWidget(QLabel("Justify Text"), 1, 0) self.textFlowForm.addWidget(self.textFlowJustify, 1, 1) self.textFlowForm.addWidget(QLabel("Auto-Select Text"), 2, 0) @@ -262,13 +271,13 @@ class GuiConfigEditEditor(QWidget): self.textMarginForm.addWidget(QLabel("Horizontal"), 0, 0) self.textMarginForm.addWidget(self.textMarginHor, 0, 1) - self.textMarginForm.addWidget(QLabel("pixles"), 0, 2) + self.textMarginForm.addWidget(QLabel("px"), 0, 2) self.textMarginForm.addWidget(QLabel("Vertical"), 1, 0) self.textMarginForm.addWidget(self.textMarginVer, 1, 1) - self.textMarginForm.addWidget(QLabel("pixles"), 1, 2) + self.textMarginForm.addWidget(QLabel("px"), 1, 2) self.textMarginForm.addWidget(QLabel("Tab Width"), 2, 0) self.textMarginForm.addWidget(self.textMarginTab, 2, 1) - self.textMarginForm.addWidget(QLabel("pixles"), 2, 2) + self.textMarginForm.addWidget(QLabel("px"), 2, 2) self.textMarginForm.setColumnStretch(4, 1) # Auto-Replace @@ -290,13 +299,17 @@ class GuiConfigEditEditor(QWidget): else: self.autoReplaceSQ.setCheckState(Qt.Unchecked) - self.autoReplaceSStyle = QComboBox() - for n, qTup in enumerate(nwQuotes.SINGLE): - qA, qB, qStr = qTup - self.autoReplaceSStyle.addItem("%s: %stext%s" % (qStr, qA, qB), n) - singleIdx = self.autoReplaceSStyle.findData(self.mainConf.styleSQuote) - if singleIdx != -1: - self.autoReplaceSStyle.setCurrentIndex(singleIdx) + self.autoReplaceSStyleO = QLineEdit() + self.autoReplaceSStyleO.setMaxLength(1) + self.autoReplaceSStyleO.setFixedWidth(30) + self.autoReplaceSStyleO.setAlignment(Qt.AlignCenter) + self.autoReplaceSStyleO.setText(self.mainConf.fmtSingleQuotes[0]) + + self.autoReplaceSStyleC = QLineEdit() + self.autoReplaceSStyleC.setMaxLength(1) + self.autoReplaceSStyleC.setFixedWidth(30) + self.autoReplaceSStyleC.setAlignment(Qt.AlignCenter) + self.autoReplaceSStyleC.setText(self.mainConf.fmtSingleQuotes[1]) self.autoReplaceDQ = QCheckBox(self) self.autoReplaceDQ.setToolTip("Auto-replace double quotes.") @@ -305,25 +318,51 @@ class GuiConfigEditEditor(QWidget): else: self.autoReplaceDQ.setCheckState(Qt.Unchecked) - self.autoReplaceDStyle = QComboBox() - for n, qTup in enumerate(nwQuotes.DOUBLE): - qA, qB, qStr = qTup - self.autoReplaceDStyle.addItem("%s: %stext%s" % (qStr, qA, qB), n) - doubleIdx = self.autoReplaceDStyle.findData(self.mainConf.styleSQuote) - if doubleIdx != -1: - self.autoReplaceDStyle.setCurrentIndex(doubleIdx) + self.autoReplaceDStyleO = QLineEdit() + self.autoReplaceDStyleO.setMaxLength(1) + self.autoReplaceDStyleO.setFixedWidth(30) + self.autoReplaceDStyleO.setAlignment(Qt.AlignCenter) + self.autoReplaceDStyleO.setText(self.mainConf.fmtDoubleQuotes[0]) - self.autoReplaceForm.addWidget(QLabel("Enable Feature"), 0, 0) - self.autoReplaceForm.addWidget(self.autoReplaceMain, 0, 1) - self.autoReplaceForm.addWidget(QLabel("Single Quotes"), 1, 0) - self.autoReplaceForm.addWidget(self.autoReplaceSQ, 1, 1) - self.autoReplaceForm.addWidget(QLabel("Style"), 1, 2) - self.autoReplaceForm.addWidget(self.autoReplaceSStyle, 1, 3) - self.autoReplaceForm.addWidget(QLabel("Double Quotes"), 2, 0) - self.autoReplaceForm.addWidget(self.autoReplaceDQ, 2, 1) - self.autoReplaceForm.addWidget(QLabel("Style"), 2, 2) - self.autoReplaceForm.addWidget(self.autoReplaceDStyle, 2, 3) - self.autoReplaceForm.setColumnStretch(4, 1) + self.autoReplaceDStyleC = QLineEdit() + self.autoReplaceDStyleC.setMaxLength(1) + self.autoReplaceDStyleC.setFixedWidth(30) + self.autoReplaceDStyleC.setAlignment(Qt.AlignCenter) + self.autoReplaceDStyleC.setText(self.mainConf.fmtDoubleQuotes[1]) + + self.autoReplaceDash = QCheckBox(self) + self.autoReplaceDash.setToolTip("Auto-replace double and triple hyphens with short and long dash.") + if self.mainConf.doReplaceDash: + self.autoReplaceDash.setCheckState(Qt.Checked) + else: + self.autoReplaceDash.setCheckState(Qt.Unchecked) + + self.autoReplaceDots = QCheckBox(self) + self.autoReplaceDots.setToolTip("Auto-replace three dots with ellipsis.") + if self.mainConf.doReplaceDots: + self.autoReplaceDots.setCheckState(Qt.Checked) + else: + self.autoReplaceDots.setCheckState(Qt.Unchecked) + + self.autoReplaceForm.addWidget(QLabel("Enable Feature"), 0, 0) + self.autoReplaceForm.addWidget(self.autoReplaceMain, 0, 1) + self.autoReplaceForm.addWidget(QLabel("Single Quotes"), 1, 0) + self.autoReplaceForm.addWidget(self.autoReplaceSQ, 1, 1) + self.autoReplaceForm.addWidget(QLabel("Open"), 1, 2) + self.autoReplaceForm.addWidget(self.autoReplaceSStyleO, 1, 3) + self.autoReplaceForm.addWidget(QLabel("Close"), 1, 4) + self.autoReplaceForm.addWidget(self.autoReplaceSStyleC, 1, 5) + self.autoReplaceForm.addWidget(QLabel("Double Quotes"), 2, 0) + self.autoReplaceForm.addWidget(self.autoReplaceDQ, 2, 1) + self.autoReplaceForm.addWidget(QLabel("Open"), 2, 2) + self.autoReplaceForm.addWidget(self.autoReplaceDStyleO, 2, 3) + self.autoReplaceForm.addWidget(QLabel("Close"), 2, 4) + self.autoReplaceForm.addWidget(self.autoReplaceDStyleC, 2, 5) + self.autoReplaceForm.addWidget(QLabel("Hyphens with Dash"), 3, 0) + self.autoReplaceForm.addWidget(self.autoReplaceDash, 3, 1) + self.autoReplaceForm.addWidget(QLabel("Dots with Ellipsis"), 4, 0) + self.autoReplaceForm.addWidget(self.autoReplaceDots, 4, 1) + self.autoReplaceForm.setColumnStretch(6, 1) # Assemble self.outerBox.addWidget(self.textStyle, 0, 0, 1, 2) @@ -337,6 +376,8 @@ class GuiConfigEditEditor(QWidget): def saveValues(self): + validEntries = True + textFont = self.textStyleFont.currentFont().family() textSize = self.textStyleSize.value() @@ -348,10 +389,10 @@ class GuiConfigEditEditor(QWidget): doJustify = self.textFlowJustify.isChecked() autoSelect = self.testFlowAutoSelect.isChecked() - self.mainConf.textWidth = textWidth - self.mainConf.textFixedW = textFixedW - self.mainConf.doJustify = doJustify - self.mainConf.autoSelect = autoSelect + self.mainConf.textWidth = textWidth + self.mainConf.textFixedW = textFixedW + self.mainConf.doJustify = doJustify + self.mainConf.autoSelect = autoSelect textMarginH = self.textMarginHor.value() textMarginV = self.textMarginVer.value() @@ -361,20 +402,67 @@ class GuiConfigEditEditor(QWidget): self.mainConf.textMargin[1] = textMarginV self.mainConf.tabWidth = tabWidth - doReplace = self.autoReplaceMain.isChecked() - doReplaceSQuote = self.autoReplaceSQ.isChecked() - doReplaceDQuote = self.autoReplaceDQ.isChecked() - styleSQuote = self.autoReplaceSStyle.currentData() - styleDQuote = self.autoReplaceDStyle.currentData() + doReplace = self.autoReplaceMain.isChecked() + doReplaceSQuote = self.autoReplaceSQ.isChecked() + doReplaceDQuote = self.autoReplaceDQ.isChecked() + doReplaceDash = self.autoReplaceDash.isChecked() + doReplaceDots = self.autoReplaceDash.isChecked() + fmtSingleQuotesO = self.autoReplaceSStyleO.text() + fmtSingleQuotesC = self.autoReplaceSStyleC.text() + fmtDoubleQuotesO = self.autoReplaceDStyleO.text() + fmtDoubleQuotesC = self.autoReplaceDStyleC.text() self.mainConf.doReplace = doReplace self.mainConf.doReplaceSQuote = doReplaceSQuote self.mainConf.doReplaceDQuote = doReplaceDQuote - self.mainConf.setSingleQuotes(styleSQuote) - self.mainConf.setDoubleQuotes(styleDQuote) + self.mainConf.doReplaceDash = doReplaceDash + self.mainConf.doReplaceDots = doReplaceDots + + if self._checkQuoteSymbol(fmtSingleQuotesO): + self.mainConf.fmtSingleQuotes[0] = fmtSingleQuotesO + else: + self.theParent.makeAlert("Invalid quote symbol: %s" % fmtSingleQuotesO, nwAlert.ERROR) + validEntries = False + + if self._checkQuoteSymbol(fmtSingleQuotesC): + self.mainConf.fmtSingleQuotes[1] = fmtSingleQuotesC + else: + self.theParent.makeAlert("Invalid quote symbol: %s" % fmtSingleQuotesC, nwAlert.ERROR) + validEntries = False + + if self._checkQuoteSymbol(fmtDoubleQuotesO): + self.mainConf.fmtDoubleQuotes[0] = fmtDoubleQuotesO + else: + self.theParent.makeAlert("Invalid quote symbol: %s" % fmtDoubleQuotesO, nwAlert.ERROR) + validEntries = False + + if self._checkQuoteSymbol(fmtDoubleQuotesC): + self.mainConf.fmtDoubleQuotes[1] = fmtDoubleQuotesC + else: + self.theParent.makeAlert("Invalid quote symbol: %s" % fmtDoubleQuotesC, nwAlert.ERROR) + validEntries = False self.mainConf.confChanged = True + return validEntries, False + + ## + # Internal Functions + ## + + def _checkQuoteSymbol(self, toCheck): + validOnes = [ + "\"","'", + "“","”","„", + "‘","’","‚", + "«","»","‹","›", + "『","』","「","」", + "《","》","〈","〉" + ] + if len(toCheck) != 1: + return False + if toCheck in validOnes: + return True return False # END Class GuiConfigEditEditor diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 307cafce..9b36790a 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -55,7 +55,6 @@ class GuiDocEditor(QTextEdit): self.typDQClose = self.mainConf.fmtDoubleQuotes[1] self.typSQOpen = self.mainConf.fmtSingleQuotes[0] self.typSQClose = self.mainConf.fmtSingleQuotes[1] - self.typApos = self.mainConf.fmtApostrophe # Core Elements self.theQDoc = self.document() @@ -113,8 +112,10 @@ class GuiDocEditor(QTextEdit): return True def initEditor(self): - - tHandle = self.theHandle + """Initialise or re-initialise the editor with the user's settings. + This function is both called when the editor is created, and when the user changes the + main editor preferences. + """ # Set Font if self.mainConf.textFont is not None: @@ -125,6 +126,7 @@ class GuiDocEditor(QTextEdit): self.mainConf.textFont = theFont self.setFontPointSize(self.mainConf.textSize) + # Set text fixed width, or alternatively, just margins if self.mainConf.textFixedW: self.setLineWrapMode(QTextEdit.FixedPixelWidth) self.setLineWrapColumnOrWidth(self.mainConf.textWidth) @@ -133,6 +135,7 @@ class GuiDocEditor(QTextEdit): mLR = self.mainConf.textMargin[1] self.setViewportMargins(mLR,mTB,mLR,mTB) + # Also set the document text options for the document text flow theOpt = QTextOption() if self.mainConf.tabWidth is not None: theOpt.setTabStopDistance(self.mainConf.tabWidth) @@ -140,7 +143,9 @@ class GuiDocEditor(QTextEdit): theOpt.setAlignment(Qt.AlignJustify) self.theQDoc.setDefaultTextOption(theOpt) - if tHandle is not None: + # If we have a document open, we should reload it in case the font changed + if self.theHandle is not None: + tHandle = self.theHandle self.hLight.initHighlighter() self.clearEditor() self.loadText(tHandle)