Finished all the autoreplace options in the config gui

This commit is contained in:
Veronica K. B. Olsen
2019-06-11 15:43:04 +02:00
parent 4aa6e25acd
commit f9f8d292d1
4 changed files with 181 additions and 135 deletions
+5 -29
View File
@@ -18,8 +18,6 @@ from os import path, mkdir, getcwd
from appdirs import user_config_dir
from datetime import datetime
from nw.constants import nwQuotes
logger = logging.getLogger(__name__)
class Config:
@@ -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"
@@ -173,8 +168,8 @@ class Config:
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.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
@@ -182,9 +177,6 @@ class Config:
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):
@@ -231,8 +223,8 @@ class Config:
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,"fmtsinglequote",self._packList(self.fmtSingleQuotes))
cnfParse.set(cnfSec,"fmtdoublequote",self._packList(self.fmtDoubleQuotes))
cnfParse.set(cnfSec,"spellcheck", str(self.spellLanguage))
## 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
##
-23
View File
@@ -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
+121 -33
View File
@@ -24,7 +24,6 @@ from PyQt5.QtWidgets import (
QCheckBox, QGridLayout, QFontComboBox
)
from nw.enum import nwAlert
from nw.constants import nwQuotes
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,6 +93,7 @@ class GuiConfigEditor(QDialog):
"Some changes will not be applied until<br>%s has been restarted." % nw.__package__
)
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.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("Style"), 1, 2)
self.autoReplaceForm.addWidget(self.autoReplaceSStyle, 1, 3)
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("Style"), 2, 2)
self.autoReplaceForm.addWidget(self.autoReplaceDStyle, 2, 3)
self.autoReplaceForm.setColumnStretch(4, 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()
@@ -364,17 +405,64 @@ class GuiConfigEditEditor(QWidget):
doReplace = self.autoReplaceMain.isChecked()
doReplaceSQuote = self.autoReplaceSQ.isChecked()
doReplaceDQuote = self.autoReplaceDQ.isChecked()
styleSQuote = self.autoReplaceSStyle.currentData()
styleDQuote = self.autoReplaceDStyle.currentData()
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
+9 -4
View File
@@ -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)