+247
-203
File diff suppressed because it is too large
Load Diff
+254
-210
File diff suppressed because it is too large
Load Diff
+254
-210
File diff suppressed because it is too large
Load Diff
+254
-210
File diff suppressed because it is too large
Load Diff
@@ -164,6 +164,9 @@ class Config:
|
||||
self.fmtApostrophe = nwUnicode.U_RSQUO
|
||||
self.fmtSingleQuotes = [nwUnicode.U_LSQUO, nwUnicode.U_RSQUO]
|
||||
self.fmtDoubleQuotes = [nwUnicode.U_LDQUO, nwUnicode.U_RDQUO]
|
||||
self.fmtPadBefore = ""
|
||||
self.fmtPadAfter = ""
|
||||
self.fmtPadThin = False
|
||||
|
||||
## Spell Checking
|
||||
self.spellTool = None
|
||||
@@ -578,6 +581,15 @@ class Config:
|
||||
self.fmtDoubleQuotes = self._parseLine(
|
||||
cnfParse, cnfSec, "fmtdoublequote", self.CNF_S_LST, self.fmtDoubleQuotes
|
||||
)
|
||||
self.fmtPadBefore = self._parseLine(
|
||||
cnfParse, cnfSec, "fmtpadbefore", self.CNF_STR, self.fmtPadBefore
|
||||
)
|
||||
self.fmtPadAfter = self._parseLine(
|
||||
cnfParse, cnfSec, "fmtpadafter", self.CNF_STR, self.fmtPadAfter
|
||||
)
|
||||
self.fmtPadThin = self._parseLine(
|
||||
cnfParse, cnfSec, "fmtpadthin", self.CNF_BOOL, self.fmtPadThin
|
||||
)
|
||||
self.spellTool = self._parseLine(
|
||||
cnfParse, cnfSec, "spelltool", self.CNF_STR, self.spellTool
|
||||
)
|
||||
@@ -746,6 +758,9 @@ class Config:
|
||||
cnfParse.set(cnfSec, "autoscrollpos", str(self.autoScrollPos))
|
||||
cnfParse.set(cnfSec, "fmtsinglequote", self._packList(self.fmtSingleQuotes))
|
||||
cnfParse.set(cnfSec, "fmtdoublequote", self._packList(self.fmtDoubleQuotes))
|
||||
cnfParse.set(cnfSec, "fmtpadbefore", str(self.fmtPadBefore))
|
||||
cnfParse.set(cnfSec, "fmtpadafter", str(self.fmtPadAfter))
|
||||
cnfParse.set(cnfSec, "fmtpadthin", str(self.fmtPadThin))
|
||||
cnfParse.set(cnfSec, "spelltool", str(self.spellTool))
|
||||
cnfParse.set(cnfSec, "spellcheck", str(self.spellLanguage))
|
||||
cnfParse.set(cnfSec, "showtabsnspaces", str(self.showTabsNSpaces))
|
||||
|
||||
+59
-26
@@ -98,10 +98,12 @@ class GuiDocEditor(QTextEdit):
|
||||
self.queuePos = None # Used for delayed change of cursor position
|
||||
|
||||
# Typography
|
||||
self.typDQOpen = self.mainConf.fmtDoubleQuotes[0]
|
||||
self.typDQClose = self.mainConf.fmtDoubleQuotes[1]
|
||||
self.typSQOpen = self.mainConf.fmtSingleQuotes[0]
|
||||
self.typSQClose = self.mainConf.fmtSingleQuotes[1]
|
||||
self.typDQOpen = '"'
|
||||
self.typDQClose = '"'
|
||||
self.typSQOpen = "'"
|
||||
self.typSQClose = "'"
|
||||
self.typPadChar = " "
|
||||
self.addPadding = False
|
||||
|
||||
# Core Elements and Signals
|
||||
self.qDocument = self.document()
|
||||
@@ -197,6 +199,17 @@ class GuiDocEditor(QTextEdit):
|
||||
self.nonWord += "".join(self.mainConf.fmtDoubleQuotes)
|
||||
self.nonWord += "".join(self.mainConf.fmtSingleQuotes)
|
||||
|
||||
# Typography
|
||||
if self.mainConf.fmtPadThin:
|
||||
self.typPadChar = nwUnicode.U_THNBSP
|
||||
else:
|
||||
self.typPadChar = nwUnicode.U_NBSP
|
||||
|
||||
self.typSQOpen = self.mainConf.fmtSingleQuotes[0]
|
||||
self.typSQClose = self.mainConf.fmtSingleQuotes[1]
|
||||
self.typDQOpen = self.mainConf.fmtDoubleQuotes[0]
|
||||
self.typDQClose = self.mainConf.fmtDoubleQuotes[1]
|
||||
|
||||
# Reload spell check and dictionaries
|
||||
self._setupSpellChecking()
|
||||
self.setDictionaries()
|
||||
@@ -206,6 +219,7 @@ class GuiDocEditor(QTextEdit):
|
||||
if self.mainConf.textFont is None:
|
||||
# If none is defined, set the default back to config
|
||||
self.mainConf.textFont = self.qDocument.defaultFont().family()
|
||||
|
||||
theFont.setFamily(self.mainConf.textFont)
|
||||
theFont.setPointSize(self.mainConf.textSize)
|
||||
self.setFont(theFont)
|
||||
@@ -1202,7 +1216,7 @@ class GuiDocEditor(QTextEdit):
|
||||
return
|
||||
|
||||
def _docAutoReplace(self, theBlock):
|
||||
"""Autoreplace text elements based on main configuration.
|
||||
"""Auto-replace text elements based on main configuration.
|
||||
"""
|
||||
if not theBlock.isValid():
|
||||
return
|
||||
@@ -1219,43 +1233,62 @@ class GuiDocEditor(QTextEdit):
|
||||
theTwo = theText[thePos-2:thePos]
|
||||
theThree = theText[thePos-3:thePos]
|
||||
|
||||
if self.mainConf.doReplaceDQuote and theTwo == " \"":
|
||||
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
|
||||
theCursor.insertText(self.typDQOpen)
|
||||
if not theOne: # Makes Neo sad
|
||||
return
|
||||
|
||||
elif self.mainConf.doReplaceDQuote and theOne == "\"":
|
||||
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
|
||||
nDelete = 0
|
||||
tInsert = theOne
|
||||
|
||||
if self.mainConf.doReplaceDQuote and theTwo == ' "':
|
||||
nDelete = 1
|
||||
tInsert = self.typDQOpen
|
||||
|
||||
elif self.mainConf.doReplaceDQuote and theOne == '"':
|
||||
nDelete = 1
|
||||
if thePos == 1:
|
||||
theCursor.insertText(self.typDQOpen)
|
||||
tInsert = self.typDQOpen
|
||||
else:
|
||||
theCursor.insertText(self.typDQClose)
|
||||
tInsert = self.typDQClose
|
||||
|
||||
elif self.mainConf.doReplaceSQuote and theTwo == " '":
|
||||
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
|
||||
theCursor.insertText(self.typSQOpen)
|
||||
nDelete = 1
|
||||
tInsert = self.typSQOpen
|
||||
|
||||
elif self.mainConf.doReplaceSQuote and theOne == "'":
|
||||
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 1)
|
||||
nDelete = 1
|
||||
if thePos == 1:
|
||||
theCursor.insertText(self.typSQOpen)
|
||||
tInsert = self.typSQOpen
|
||||
else:
|
||||
theCursor.insertText(self.typSQClose)
|
||||
tInsert = self.typSQClose
|
||||
|
||||
elif self.mainConf.doReplaceDash and theThree == "---":
|
||||
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 3)
|
||||
theCursor.insertText(nwUnicode.U_EMDASH)
|
||||
nDelete = 3
|
||||
tInsert = nwUnicode.U_EMDASH
|
||||
|
||||
elif self.mainConf.doReplaceDash and theTwo == "--":
|
||||
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 2)
|
||||
theCursor.insertText(nwUnicode.U_ENDASH)
|
||||
nDelete = 2
|
||||
tInsert = nwUnicode.U_ENDASH
|
||||
|
||||
elif self.mainConf.doReplaceDash and theTwo == nwUnicode.U_ENDASH+"-":
|
||||
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 2)
|
||||
theCursor.insertText(nwUnicode.U_EMDASH)
|
||||
elif self.mainConf.doReplaceDash and theTwo == nwUnicode.U_ENDASH + "-":
|
||||
nDelete = 2
|
||||
tInsert = nwUnicode.U_EMDASH
|
||||
|
||||
elif self.mainConf.doReplaceDots and theThree == "...":
|
||||
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 3)
|
||||
theCursor.insertText(nwUnicode.U_HELLIP)
|
||||
nDelete = 3
|
||||
tInsert = nwUnicode.U_HELLIP
|
||||
|
||||
tCheck = tInsert
|
||||
if tCheck in self.mainConf.fmtPadBefore:
|
||||
nDelete = max(nDelete, 1)
|
||||
tInsert = self.typPadChar + tInsert
|
||||
|
||||
if tCheck in self.mainConf.fmtPadAfter:
|
||||
nDelete = max(nDelete, 1)
|
||||
tInsert = tInsert + self.typPadChar
|
||||
|
||||
if nDelete > 0:
|
||||
theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, nDelete)
|
||||
theCursor.insertText(tInsert)
|
||||
|
||||
return
|
||||
|
||||
|
||||
+92
-21
@@ -61,6 +61,7 @@ class GuiPreferences(PagedDialog):
|
||||
self.tabEditor = GuiPreferencesEditor(self.theParent)
|
||||
self.tabSyntax = GuiPreferencesSyntax(self.theParent)
|
||||
self.tabAuto = GuiPreferencesAutomation(self.theParent)
|
||||
self.tabQuote = GuiPreferencesQuotes(self.theParent)
|
||||
|
||||
self.addTab(self.tabGeneral, self.tr("General"))
|
||||
self.addTab(self.tabProjects, self.tr("Projects"))
|
||||
@@ -68,6 +69,7 @@ class GuiPreferences(PagedDialog):
|
||||
self.addTab(self.tabEditor, self.tr("Editor"))
|
||||
self.addTab(self.tabSyntax, self.tr("Highlighting"))
|
||||
self.addTab(self.tabAuto, self.tr("Automation"))
|
||||
self.addTab(self.tabQuote, self.tr("Quotes"))
|
||||
|
||||
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
||||
self.buttonBox.accepted.connect(self._doSave)
|
||||
@@ -1034,6 +1036,95 @@ class GuiPreferencesAutomation(QWidget):
|
||||
self.tr("Three consecutive dots become ellipsis.")
|
||||
)
|
||||
|
||||
# Automatic Padding
|
||||
# =================
|
||||
self.mainForm.addGroupLabel(self.tr("Automatic Padding"))
|
||||
|
||||
## Pad Before
|
||||
self.fmtPadBefore = QLineEdit()
|
||||
self.fmtPadBefore.setMaxLength(32)
|
||||
self.fmtPadBefore.setText(self.mainConf.fmtPadBefore)
|
||||
self.mainForm.addRow(
|
||||
self.tr("Insert non-breaking space before"),
|
||||
self.fmtPadBefore,
|
||||
self.tr("Automatically add space before any of the symbols."),
|
||||
)
|
||||
|
||||
## Pad After
|
||||
self.fmtPadAfter = QLineEdit()
|
||||
self.fmtPadAfter.setMaxLength(32)
|
||||
self.fmtPadAfter.setText(self.mainConf.fmtPadAfter)
|
||||
self.mainForm.addRow(
|
||||
self.tr("Insert non-breaking space after"),
|
||||
self.fmtPadAfter,
|
||||
self.tr("Automatically add space after any of the symbols."),
|
||||
)
|
||||
|
||||
## Use Thin Space
|
||||
self.fmtPadThin = QSwitch()
|
||||
self.fmtPadThin.setChecked(self.mainConf.fmtPadThin)
|
||||
self.fmtPadThin.setEnabled(self.mainConf.doReplace)
|
||||
self.mainForm.addRow(
|
||||
self.tr("Use thin space instead"),
|
||||
self.fmtPadThin,
|
||||
self.tr("Inserts a thinner space instead of regular space.")
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
def saveValues(self):
|
||||
"""Save the values set for this tab.
|
||||
"""
|
||||
# Automatic Features
|
||||
self.mainConf.autoSelect = self.autoSelect.isChecked()
|
||||
self.mainConf.doReplace = self.doReplace.isChecked()
|
||||
|
||||
# Replace as You Type
|
||||
self.mainConf.doReplaceSQuote = self.doReplaceSQuote.isChecked()
|
||||
self.mainConf.doReplaceDQuote = self.doReplaceDQuote.isChecked()
|
||||
self.mainConf.doReplaceDash = self.doReplaceDash.isChecked()
|
||||
self.mainConf.doReplaceDots = self.doReplaceDots.isChecked()
|
||||
|
||||
# Automatic Padding
|
||||
self.mainConf.fmtPadBefore = self.fmtPadBefore.text().strip()
|
||||
self.mainConf.fmtPadAfter = self.fmtPadAfter.text().strip()
|
||||
self.mainConf.fmtPadThin = self.fmtPadThin.isChecked()
|
||||
|
||||
self.mainConf.confChanged = True
|
||||
|
||||
return
|
||||
|
||||
##
|
||||
# Slots
|
||||
##
|
||||
|
||||
def _toggleAutoReplaceMain(self, theState):
|
||||
"""Enables or disables switches controlled by the main auto
|
||||
replace switch.
|
||||
"""
|
||||
self.doReplaceSQuote.setEnabled(theState)
|
||||
self.doReplaceDQuote.setEnabled(theState)
|
||||
self.doReplaceDash.setEnabled(theState)
|
||||
self.doReplaceDots.setEnabled(theState)
|
||||
self.fmtPadThin.setEnabled(theState)
|
||||
return
|
||||
|
||||
# END Class GuiPreferencesAutomation
|
||||
|
||||
class GuiPreferencesQuotes(QWidget):
|
||||
|
||||
def __init__(self, theParent):
|
||||
QWidget.__init__(self, theParent)
|
||||
|
||||
self.mainConf = nw.CONFIG
|
||||
self.theParent = theParent
|
||||
self.theTheme = theParent.theTheme
|
||||
|
||||
# The Form
|
||||
self.mainForm = QConfigLayout()
|
||||
self.mainForm.setHelpTextStyle(self.theTheme.helpText)
|
||||
self.setLayout(self.mainForm)
|
||||
|
||||
# Quotation Style
|
||||
# ===============
|
||||
self.mainForm.addGroupLabel(self.tr("Quotation Style"))
|
||||
@@ -1113,16 +1204,6 @@ class GuiPreferencesAutomation(QWidget):
|
||||
def saveValues(self):
|
||||
"""Save the values set for this tab.
|
||||
"""
|
||||
# Automatic Features
|
||||
self.mainConf.autoSelect = self.autoSelect.isChecked()
|
||||
self.mainConf.doReplace = self.doReplace.isChecked()
|
||||
|
||||
# Replace as You Type
|
||||
self.mainConf.doReplaceSQuote = self.doReplaceSQuote.isChecked()
|
||||
self.mainConf.doReplaceDQuote = self.doReplaceDQuote.isChecked()
|
||||
self.mainConf.doReplaceDash = self.doReplaceDash.isChecked()
|
||||
self.mainConf.doReplaceDots = self.doReplaceDots.isChecked()
|
||||
|
||||
# Quotation Style
|
||||
self.mainConf.fmtSingleQuotes[0] = self.quoteSym["SO"].text()
|
||||
self.mainConf.fmtSingleQuotes[1] = self.quoteSym["SC"].text()
|
||||
@@ -1137,16 +1218,6 @@ class GuiPreferencesAutomation(QWidget):
|
||||
# Slots
|
||||
##
|
||||
|
||||
def _toggleAutoReplaceMain(self, theState):
|
||||
"""Enables or disables switches controlled by the main auto
|
||||
replace switch.
|
||||
"""
|
||||
self.doReplaceSQuote.setEnabled(theState)
|
||||
self.doReplaceDQuote.setEnabled(theState)
|
||||
self.doReplaceDash.setEnabled(theState)
|
||||
self.doReplaceDots.setEnabled(theState)
|
||||
return
|
||||
|
||||
def _getQuote(self, qType):
|
||||
"""Dialog for single quote open.
|
||||
"""
|
||||
@@ -1156,4 +1227,4 @@ class GuiPreferencesAutomation(QWidget):
|
||||
|
||||
return
|
||||
|
||||
# END Class GuiPreferencesAutomation
|
||||
# END Class GuiPreferencesQuotes
|
||||
|
||||
@@ -48,6 +48,9 @@ autoscroll = False
|
||||
autoscrollpos = 30
|
||||
fmtsinglequote = ‘, ’
|
||||
fmtdoublequote = “, ”
|
||||
fmtpadbefore =
|
||||
fmtpadafter =
|
||||
fmtpadthin = False
|
||||
spelltool = internal
|
||||
spellcheck = en
|
||||
showtabsnspaces = False
|
||||
|
||||
@@ -48,6 +48,9 @@ autoscroll = True
|
||||
autoscrollpos = 30
|
||||
fmtsinglequote = ‘, ’
|
||||
fmtdoublequote = “, ”
|
||||
fmtpadbefore =
|
||||
fmtpadafter =
|
||||
fmtpadthin = False
|
||||
spelltool = internal
|
||||
spellcheck = en
|
||||
showtabsnspaces = True
|
||||
|
||||
@@ -229,9 +229,14 @@ def testGuiPreferences_Main(qtbot, monkeypatch, fncDir, outDir, refDir):
|
||||
assert not tabAuto.doReplaceDash.isEnabled()
|
||||
assert not tabAuto.doReplaceDots.isEnabled()
|
||||
|
||||
# Quotation Style
|
||||
qtbot.wait(keyDelay)
|
||||
tabQuote = nwPrefs.tabQuote
|
||||
nwPrefs._tabBox.setCurrentWidget(tabQuote)
|
||||
|
||||
monkeypatch.setattr(QuotesDialog, "selectedQuote", "'")
|
||||
monkeypatch.setattr(QuotesDialog, "exec_", lambda *args: QDialog.Accepted)
|
||||
qtbot.mouseClick(tabAuto.btnDoubleStyleC, Qt.LeftButton)
|
||||
qtbot.mouseClick(tabQuote.btnDoubleStyleC, Qt.LeftButton)
|
||||
|
||||
# Save and Check Config
|
||||
qtbot.mouseClick(nwPrefs.buttonBox.button(QDialogButtonBox.Ok), Qt.LeftButton)
|
||||
|
||||
Reference in New Issue
Block a user