Finished all the autoreplace options in the config gui
This commit is contained in:
+36
-60
@@ -14,11 +14,9 @@ import logging
|
|||||||
import configparser
|
import configparser
|
||||||
import nw
|
import nw
|
||||||
|
|
||||||
from os import path, mkdir, getcwd
|
from os import path, mkdir, getcwd
|
||||||
from appdirs import user_config_dir
|
from appdirs import user_config_dir
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from nw.constants import nwQuotes
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -79,13 +77,10 @@ class Config:
|
|||||||
self.doReplaceDQuote = True
|
self.doReplaceDQuote = True
|
||||||
self.doReplaceDash = True
|
self.doReplaceDash = True
|
||||||
self.doReplaceDots = True
|
self.doReplaceDots = True
|
||||||
self.styleSQuote = 1
|
|
||||||
self.styleDQuote = 1
|
|
||||||
self.wordCountTimer = 5.0
|
self.wordCountTimer = 5.0
|
||||||
|
|
||||||
self.fmtDoubleQuotes = ["“","”"]
|
|
||||||
self.fmtSingleQuotes = ["‘","’"]
|
self.fmtSingleQuotes = ["‘","’"]
|
||||||
self.fmtApostrophe = "’"
|
self.fmtDoubleQuotes = ["“","”"]
|
||||||
|
|
||||||
self.spellLanguage = "en_GB"
|
self.spellLanguage = "en_GB"
|
||||||
|
|
||||||
@@ -160,31 +155,28 @@ class Config:
|
|||||||
|
|
||||||
## Editor
|
## Editor
|
||||||
cnfSec = "Editor"
|
cnfSec = "Editor"
|
||||||
self.textFont = self._parseLine(cnfParse, cnfSec, "textfont", self.CNF_STR, self.textFont)
|
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.textSize = self._parseLine(cnfParse, cnfSec, "textsize", self.CNF_INT, self.textSize)
|
||||||
self.textFixedW = self._parseLine(cnfParse, cnfSec, "fixedwidth", self.CNF_BOOL, self.textFixedW)
|
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.textWidth = self._parseLine(cnfParse, cnfSec, "width", self.CNF_INT, self.textWidth)
|
||||||
self.textMargin = self._parseLine(cnfParse, cnfSec, "margins", self.CNF_LIST, self.textMargin)
|
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.tabWidth = self._parseLine(cnfParse, cnfSec, "tabwidth", self.CNF_INT, self.tabWidth)
|
||||||
self.doJustify = self._parseLine(cnfParse, cnfSec, "justify", self.CNF_BOOL, self.doJustify)
|
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.autoSelect = self._parseLine(cnfParse, cnfSec, "autoselect", self.CNF_BOOL, self.autoSelect)
|
||||||
self.doReplace = self._parseLine(cnfParse, cnfSec, "autoreplace", self.CNF_BOOL, self.doReplace)
|
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.doReplaceSQuote = self._parseLine(cnfParse, cnfSec, "repsquotes", self.CNF_BOOL, self.doReplaceSQuote)
|
||||||
self.doReplaceDQuote = self._parseLine(cnfParse, cnfSec, "repdquotes", self.CNF_BOOL, self.doReplaceDQuote)
|
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.doReplaceDash = self._parseLine(cnfParse, cnfSec, "repdash", self.CNF_BOOL, self.doReplaceDash)
|
||||||
self.doReplaceDots = self._parseLine(cnfParse, cnfSec, "repdots", self.CNF_BOOL, self.doReplaceDots)
|
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.fmtSingleQuotes = self._parseLine(cnfParse, cnfSec, "fmtsinglequote", self.CNF_LIST, self.fmtSingleQuotes)
|
||||||
self.styleDQuote = self._parseLine(cnfParse, cnfSec, "styledquote", self.CNF_INT, self.styleDQuote)
|
self.fmtDoubleQuotes = self._parseLine(cnfParse, cnfSec, "fmtdoublequote", self.CNF_LIST, self.fmtDoubleQuotes)
|
||||||
self.spellLanguage = self._parseLine(cnfParse, cnfSec, "spellcheck", self.CNF_STR, self.spellLanguage)
|
self.spellLanguage = self._parseLine(cnfParse, cnfSec, "spellcheck", self.CNF_STR, self.spellLanguage)
|
||||||
|
|
||||||
## Path
|
## Path
|
||||||
cnfSec = "Path"
|
cnfSec = "Path"
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
self.recentList[i] = self._parseLine(cnfParse, cnfSec, "recent%d" % i,self.CNF_STR, self.recentList[i])
|
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
|
return True
|
||||||
|
|
||||||
def saveConfig(self):
|
def saveConfig(self):
|
||||||
@@ -218,22 +210,22 @@ class Config:
|
|||||||
## Editor
|
## Editor
|
||||||
cnfSec = "Editor"
|
cnfSec = "Editor"
|
||||||
cnfParse.add_section(cnfSec)
|
cnfParse.add_section(cnfSec)
|
||||||
cnfParse.set(cnfSec,"textfont", str(self.textFont))
|
cnfParse.set(cnfSec,"textfont", str(self.textFont))
|
||||||
cnfParse.set(cnfSec,"textsize", str(self.textSize))
|
cnfParse.set(cnfSec,"textsize", str(self.textSize))
|
||||||
cnfParse.set(cnfSec,"fixedwidth", str(self.textFixedW))
|
cnfParse.set(cnfSec,"fixedwidth", str(self.textFixedW))
|
||||||
cnfParse.set(cnfSec,"width", str(self.textWidth))
|
cnfParse.set(cnfSec,"width", str(self.textWidth))
|
||||||
cnfParse.set(cnfSec,"margins", self._packList(self.textMargin))
|
cnfParse.set(cnfSec,"margins", self._packList(self.textMargin))
|
||||||
cnfParse.set(cnfSec,"tabwidth", str(self.tabWidth))
|
cnfParse.set(cnfSec,"tabwidth", str(self.tabWidth))
|
||||||
cnfParse.set(cnfSec,"justify", str(self.doJustify))
|
cnfParse.set(cnfSec,"justify", str(self.doJustify))
|
||||||
cnfParse.set(cnfSec,"autoselect", str(self.autoSelect))
|
cnfParse.set(cnfSec,"autoselect", str(self.autoSelect))
|
||||||
cnfParse.set(cnfSec,"autoreplace",str(self.doReplace))
|
cnfParse.set(cnfSec,"autoreplace", str(self.doReplace))
|
||||||
cnfParse.set(cnfSec,"repsquotes", str(self.doReplaceSQuote))
|
cnfParse.set(cnfSec,"repsquotes", str(self.doReplaceSQuote))
|
||||||
cnfParse.set(cnfSec,"repdquotes", str(self.doReplaceDQuote))
|
cnfParse.set(cnfSec,"repdquotes", str(self.doReplaceDQuote))
|
||||||
cnfParse.set(cnfSec,"repdash", str(self.doReplaceDash))
|
cnfParse.set(cnfSec,"repdash", str(self.doReplaceDash))
|
||||||
cnfParse.set(cnfSec,"repdots", str(self.doReplaceDots))
|
cnfParse.set(cnfSec,"repdots", str(self.doReplaceDots))
|
||||||
cnfParse.set(cnfSec,"stylesquote",str(self.styleSQuote))
|
cnfParse.set(cnfSec,"fmtsinglequote",self._packList(self.fmtSingleQuotes))
|
||||||
cnfParse.set(cnfSec,"styledquote",str(self.styleDQuote))
|
cnfParse.set(cnfSec,"fmtdoublequote",self._packList(self.fmtDoubleQuotes))
|
||||||
cnfParse.set(cnfSec,"spellcheck", str(self.spellLanguage))
|
cnfParse.set(cnfSec,"spellcheck", str(self.spellLanguage))
|
||||||
|
|
||||||
## Path
|
## Path
|
||||||
cnfSec = "Path"
|
cnfSec = "Path"
|
||||||
@@ -305,22 +297,6 @@ class Config:
|
|||||||
self.confChanged = True
|
self.confChanged = True
|
||||||
return 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
|
# Internal Functions
|
||||||
##
|
##
|
||||||
|
|||||||
@@ -70,26 +70,3 @@ class nwLabels():
|
|||||||
}
|
}
|
||||||
|
|
||||||
# END 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
|
|
||||||
|
|||||||
+136
-48
@@ -23,8 +23,7 @@ from PyQt5.QtWidgets import (
|
|||||||
QWidget, QTabWidget, QDialogButtonBox, QSpinBox, QGroupBox, QComboBox, QMessageBox,
|
QWidget, QTabWidget, QDialogButtonBox, QSpinBox, QGroupBox, QComboBox, QMessageBox,
|
||||||
QCheckBox, QGridLayout, QFontComboBox
|
QCheckBox, QGridLayout, QFontComboBox
|
||||||
)
|
)
|
||||||
from nw.enum import nwAlert
|
from nw.enum import nwAlert
|
||||||
from nw.constants import nwQuotes
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -76,9 +75,16 @@ class GuiConfigEditor(QDialog):
|
|||||||
|
|
||||||
logger.verbose("ConfigEditor save button clicked")
|
logger.verbose("ConfigEditor save button clicked")
|
||||||
|
|
||||||
|
validEntries = True
|
||||||
needsRestart = False
|
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:
|
if needsRestart:
|
||||||
msgBox = QMessageBox()
|
msgBox = QMessageBox()
|
||||||
@@ -87,7 +93,8 @@ class GuiConfigEditor(QDialog):
|
|||||||
"Some changes will not be applied until<br>%s has been restarted." % nw.__package__
|
"Some changes will not be applied until<br>%s has been restarted." % nw.__package__
|
||||||
)
|
)
|
||||||
|
|
||||||
self.accept()
|
if validEntries:
|
||||||
|
self.accept()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -149,12 +156,14 @@ class GuiConfigEditGeneral(QWidget):
|
|||||||
|
|
||||||
def saveValues(self):
|
def saveValues(self):
|
||||||
|
|
||||||
|
validEntries = True
|
||||||
|
needsRestart = False
|
||||||
|
|
||||||
autoSaveDoc = self.autoSaveDoc.value()
|
autoSaveDoc = self.autoSaveDoc.value()
|
||||||
autoSaveProj = self.autoSaveProj.value()
|
autoSaveProj = self.autoSaveProj.value()
|
||||||
guiTheme = self.guiLookTheme.currentData()
|
guiTheme = self.guiLookTheme.currentData()
|
||||||
|
|
||||||
# Check if restart is needed
|
# Check if restart is needed
|
||||||
needsRestart = False
|
|
||||||
needsRestart |= self.mainConf.guiTheme != guiTheme
|
needsRestart |= self.mainConf.guiTheme != guiTheme
|
||||||
|
|
||||||
self.mainConf.autoSaveDoc = autoSaveDoc
|
self.mainConf.autoSaveDoc = autoSaveDoc
|
||||||
@@ -162,7 +171,7 @@ class GuiConfigEditGeneral(QWidget):
|
|||||||
self.mainConf.guiTheme = guiTheme
|
self.mainConf.guiTheme = guiTheme
|
||||||
self.mainConf.confChanged = True
|
self.mainConf.confChanged = True
|
||||||
|
|
||||||
return needsRestart
|
return validEntries, needsRestart
|
||||||
|
|
||||||
# END Class GuiConfigEditGeneral
|
# END Class GuiConfigEditGeneral
|
||||||
|
|
||||||
@@ -181,7 +190,7 @@ class GuiConfigEditEditor(QWidget):
|
|||||||
self.textStyle.setLayout(self.textStyleForm)
|
self.textStyle.setLayout(self.textStyleForm)
|
||||||
|
|
||||||
self.textStyleFont = QFontComboBox()
|
self.textStyleFont = QFontComboBox()
|
||||||
self.textStyleFont.setMaximumWidth(300)
|
self.textStyleFont.setMaximumWidth(250)
|
||||||
self.textStyleFont.setCurrentFont(QFont(self.mainConf.textFont))
|
self.textStyleFont.setCurrentFont(QFont(self.mainConf.textFont))
|
||||||
|
|
||||||
self.textStyleSize = QSpinBox(self)
|
self.textStyleSize = QSpinBox(self)
|
||||||
@@ -230,7 +239,7 @@ class GuiConfigEditEditor(QWidget):
|
|||||||
self.textFlowForm.addWidget(QLabel("Fixed Width"), 0, 0)
|
self.textFlowForm.addWidget(QLabel("Fixed Width"), 0, 0)
|
||||||
self.textFlowForm.addWidget(self.textFlowFixed, 0, 1)
|
self.textFlowForm.addWidget(self.textFlowFixed, 0, 1)
|
||||||
self.textFlowForm.addWidget(self.textFlowWidth, 0, 2)
|
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(QLabel("Justify Text"), 1, 0)
|
||||||
self.textFlowForm.addWidget(self.textFlowJustify, 1, 1)
|
self.textFlowForm.addWidget(self.textFlowJustify, 1, 1)
|
||||||
self.textFlowForm.addWidget(QLabel("Auto-Select Text"), 2, 0)
|
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(QLabel("Horizontal"), 0, 0)
|
||||||
self.textMarginForm.addWidget(self.textMarginHor, 0, 1)
|
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(QLabel("Vertical"), 1, 0)
|
||||||
self.textMarginForm.addWidget(self.textMarginVer, 1, 1)
|
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(QLabel("Tab Width"), 2, 0)
|
||||||
self.textMarginForm.addWidget(self.textMarginTab, 2, 1)
|
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)
|
self.textMarginForm.setColumnStretch(4, 1)
|
||||||
|
|
||||||
# Auto-Replace
|
# Auto-Replace
|
||||||
@@ -290,13 +299,17 @@ class GuiConfigEditEditor(QWidget):
|
|||||||
else:
|
else:
|
||||||
self.autoReplaceSQ.setCheckState(Qt.Unchecked)
|
self.autoReplaceSQ.setCheckState(Qt.Unchecked)
|
||||||
|
|
||||||
self.autoReplaceSStyle = QComboBox()
|
self.autoReplaceSStyleO = QLineEdit()
|
||||||
for n, qTup in enumerate(nwQuotes.SINGLE):
|
self.autoReplaceSStyleO.setMaxLength(1)
|
||||||
qA, qB, qStr = qTup
|
self.autoReplaceSStyleO.setFixedWidth(30)
|
||||||
self.autoReplaceSStyle.addItem("%s: %stext%s" % (qStr, qA, qB), n)
|
self.autoReplaceSStyleO.setAlignment(Qt.AlignCenter)
|
||||||
singleIdx = self.autoReplaceSStyle.findData(self.mainConf.styleSQuote)
|
self.autoReplaceSStyleO.setText(self.mainConf.fmtSingleQuotes[0])
|
||||||
if singleIdx != -1:
|
|
||||||
self.autoReplaceSStyle.setCurrentIndex(singleIdx)
|
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 = QCheckBox(self)
|
||||||
self.autoReplaceDQ.setToolTip("Auto-replace double quotes.")
|
self.autoReplaceDQ.setToolTip("Auto-replace double quotes.")
|
||||||
@@ -305,25 +318,51 @@ class GuiConfigEditEditor(QWidget):
|
|||||||
else:
|
else:
|
||||||
self.autoReplaceDQ.setCheckState(Qt.Unchecked)
|
self.autoReplaceDQ.setCheckState(Qt.Unchecked)
|
||||||
|
|
||||||
self.autoReplaceDStyle = QComboBox()
|
self.autoReplaceDStyleO = QLineEdit()
|
||||||
for n, qTup in enumerate(nwQuotes.DOUBLE):
|
self.autoReplaceDStyleO.setMaxLength(1)
|
||||||
qA, qB, qStr = qTup
|
self.autoReplaceDStyleO.setFixedWidth(30)
|
||||||
self.autoReplaceDStyle.addItem("%s: %stext%s" % (qStr, qA, qB), n)
|
self.autoReplaceDStyleO.setAlignment(Qt.AlignCenter)
|
||||||
doubleIdx = self.autoReplaceDStyle.findData(self.mainConf.styleSQuote)
|
self.autoReplaceDStyleO.setText(self.mainConf.fmtDoubleQuotes[0])
|
||||||
if doubleIdx != -1:
|
|
||||||
self.autoReplaceDStyle.setCurrentIndex(doubleIdx)
|
|
||||||
|
|
||||||
self.autoReplaceForm.addWidget(QLabel("Enable Feature"), 0, 0)
|
self.autoReplaceDStyleC = QLineEdit()
|
||||||
self.autoReplaceForm.addWidget(self.autoReplaceMain, 0, 1)
|
self.autoReplaceDStyleC.setMaxLength(1)
|
||||||
self.autoReplaceForm.addWidget(QLabel("Single Quotes"), 1, 0)
|
self.autoReplaceDStyleC.setFixedWidth(30)
|
||||||
self.autoReplaceForm.addWidget(self.autoReplaceSQ, 1, 1)
|
self.autoReplaceDStyleC.setAlignment(Qt.AlignCenter)
|
||||||
self.autoReplaceForm.addWidget(QLabel("Style"), 1, 2)
|
self.autoReplaceDStyleC.setText(self.mainConf.fmtDoubleQuotes[1])
|
||||||
self.autoReplaceForm.addWidget(self.autoReplaceSStyle, 1, 3)
|
|
||||||
self.autoReplaceForm.addWidget(QLabel("Double Quotes"), 2, 0)
|
self.autoReplaceDash = QCheckBox(self)
|
||||||
self.autoReplaceForm.addWidget(self.autoReplaceDQ, 2, 1)
|
self.autoReplaceDash.setToolTip("Auto-replace double and triple hyphens with short and long dash.")
|
||||||
self.autoReplaceForm.addWidget(QLabel("Style"), 2, 2)
|
if self.mainConf.doReplaceDash:
|
||||||
self.autoReplaceForm.addWidget(self.autoReplaceDStyle, 2, 3)
|
self.autoReplaceDash.setCheckState(Qt.Checked)
|
||||||
self.autoReplaceForm.setColumnStretch(4, 1)
|
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
|
# Assemble
|
||||||
self.outerBox.addWidget(self.textStyle, 0, 0, 1, 2)
|
self.outerBox.addWidget(self.textStyle, 0, 0, 1, 2)
|
||||||
@@ -337,6 +376,8 @@ class GuiConfigEditEditor(QWidget):
|
|||||||
|
|
||||||
def saveValues(self):
|
def saveValues(self):
|
||||||
|
|
||||||
|
validEntries = True
|
||||||
|
|
||||||
textFont = self.textStyleFont.currentFont().family()
|
textFont = self.textStyleFont.currentFont().family()
|
||||||
textSize = self.textStyleSize.value()
|
textSize = self.textStyleSize.value()
|
||||||
|
|
||||||
@@ -348,10 +389,10 @@ class GuiConfigEditEditor(QWidget):
|
|||||||
doJustify = self.textFlowJustify.isChecked()
|
doJustify = self.textFlowJustify.isChecked()
|
||||||
autoSelect = self.testFlowAutoSelect.isChecked()
|
autoSelect = self.testFlowAutoSelect.isChecked()
|
||||||
|
|
||||||
self.mainConf.textWidth = textWidth
|
self.mainConf.textWidth = textWidth
|
||||||
self.mainConf.textFixedW = textFixedW
|
self.mainConf.textFixedW = textFixedW
|
||||||
self.mainConf.doJustify = doJustify
|
self.mainConf.doJustify = doJustify
|
||||||
self.mainConf.autoSelect = autoSelect
|
self.mainConf.autoSelect = autoSelect
|
||||||
|
|
||||||
textMarginH = self.textMarginHor.value()
|
textMarginH = self.textMarginHor.value()
|
||||||
textMarginV = self.textMarginVer.value()
|
textMarginV = self.textMarginVer.value()
|
||||||
@@ -361,20 +402,67 @@ class GuiConfigEditEditor(QWidget):
|
|||||||
self.mainConf.textMargin[1] = textMarginV
|
self.mainConf.textMargin[1] = textMarginV
|
||||||
self.mainConf.tabWidth = tabWidth
|
self.mainConf.tabWidth = tabWidth
|
||||||
|
|
||||||
doReplace = self.autoReplaceMain.isChecked()
|
doReplace = self.autoReplaceMain.isChecked()
|
||||||
doReplaceSQuote = self.autoReplaceSQ.isChecked()
|
doReplaceSQuote = self.autoReplaceSQ.isChecked()
|
||||||
doReplaceDQuote = self.autoReplaceDQ.isChecked()
|
doReplaceDQuote = self.autoReplaceDQ.isChecked()
|
||||||
styleSQuote = self.autoReplaceSStyle.currentData()
|
doReplaceDash = self.autoReplaceDash.isChecked()
|
||||||
styleDQuote = self.autoReplaceDStyle.currentData()
|
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.doReplace = doReplace
|
||||||
self.mainConf.doReplaceSQuote = doReplaceSQuote
|
self.mainConf.doReplaceSQuote = doReplaceSQuote
|
||||||
self.mainConf.doReplaceDQuote = doReplaceDQuote
|
self.mainConf.doReplaceDQuote = doReplaceDQuote
|
||||||
self.mainConf.setSingleQuotes(styleSQuote)
|
self.mainConf.doReplaceDash = doReplaceDash
|
||||||
self.mainConf.setDoubleQuotes(styleDQuote)
|
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
|
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
|
return False
|
||||||
|
|
||||||
# END Class GuiConfigEditEditor
|
# END Class GuiConfigEditEditor
|
||||||
|
|||||||
+9
-4
@@ -55,7 +55,6 @@ class GuiDocEditor(QTextEdit):
|
|||||||
self.typDQClose = self.mainConf.fmtDoubleQuotes[1]
|
self.typDQClose = self.mainConf.fmtDoubleQuotes[1]
|
||||||
self.typSQOpen = self.mainConf.fmtSingleQuotes[0]
|
self.typSQOpen = self.mainConf.fmtSingleQuotes[0]
|
||||||
self.typSQClose = self.mainConf.fmtSingleQuotes[1]
|
self.typSQClose = self.mainConf.fmtSingleQuotes[1]
|
||||||
self.typApos = self.mainConf.fmtApostrophe
|
|
||||||
|
|
||||||
# Core Elements
|
# Core Elements
|
||||||
self.theQDoc = self.document()
|
self.theQDoc = self.document()
|
||||||
@@ -113,8 +112,10 @@ class GuiDocEditor(QTextEdit):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def initEditor(self):
|
def initEditor(self):
|
||||||
|
"""Initialise or re-initialise the editor with the user's settings.
|
||||||
tHandle = self.theHandle
|
This function is both called when the editor is created, and when the user changes the
|
||||||
|
main editor preferences.
|
||||||
|
"""
|
||||||
|
|
||||||
# Set Font
|
# Set Font
|
||||||
if self.mainConf.textFont is not None:
|
if self.mainConf.textFont is not None:
|
||||||
@@ -125,6 +126,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
self.mainConf.textFont = theFont
|
self.mainConf.textFont = theFont
|
||||||
self.setFontPointSize(self.mainConf.textSize)
|
self.setFontPointSize(self.mainConf.textSize)
|
||||||
|
|
||||||
|
# Set text fixed width, or alternatively, just margins
|
||||||
if self.mainConf.textFixedW:
|
if self.mainConf.textFixedW:
|
||||||
self.setLineWrapMode(QTextEdit.FixedPixelWidth)
|
self.setLineWrapMode(QTextEdit.FixedPixelWidth)
|
||||||
self.setLineWrapColumnOrWidth(self.mainConf.textWidth)
|
self.setLineWrapColumnOrWidth(self.mainConf.textWidth)
|
||||||
@@ -133,6 +135,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
mLR = self.mainConf.textMargin[1]
|
mLR = self.mainConf.textMargin[1]
|
||||||
self.setViewportMargins(mLR,mTB,mLR,mTB)
|
self.setViewportMargins(mLR,mTB,mLR,mTB)
|
||||||
|
|
||||||
|
# Also set the document text options for the document text flow
|
||||||
theOpt = QTextOption()
|
theOpt = QTextOption()
|
||||||
if self.mainConf.tabWidth is not None:
|
if self.mainConf.tabWidth is not None:
|
||||||
theOpt.setTabStopDistance(self.mainConf.tabWidth)
|
theOpt.setTabStopDistance(self.mainConf.tabWidth)
|
||||||
@@ -140,7 +143,9 @@ class GuiDocEditor(QTextEdit):
|
|||||||
theOpt.setAlignment(Qt.AlignJustify)
|
theOpt.setAlignment(Qt.AlignJustify)
|
||||||
self.theQDoc.setDefaultTextOption(theOpt)
|
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.hLight.initHighlighter()
|
||||||
self.clearEditor()
|
self.clearEditor()
|
||||||
self.loadText(tHandle)
|
self.loadText(tHandle)
|
||||||
|
|||||||
Reference in New Issue
Block a user