Added a number of options to the config gui

This commit is contained in:
Veronica K. B. Olsen
2019-06-10 21:55:17 +02:00
parent ca0a756fe5
commit 30f25fcb2b
5 changed files with 147 additions and 12 deletions
+6 -3
View File
@@ -64,10 +64,11 @@ class Config:
self.autoSaveDoc = 30 self.autoSaveDoc = 30
## Text Editor ## Text Editor
self.textFont = None
self.textSize = 12
self.textFixedW = True self.textFixedW = True
self.textWidth = 600 self.textWidth = 600
self.textMargin = [40, 40] self.textMargin = [40, 40]
self.textSize = 13
self.tabWidth = 40 self.tabWidth = 40
self.doJustify = True self.doJustify = True
self.autoSelect = True self.autoSelect = True
@@ -155,10 +156,11 @@ class Config:
## Editor ## Editor
cnfSec = "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.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.textSize = self._parseLine(cnfParse, cnfSec, "textsize", self.CNF_INT, self.textSize)
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)
@@ -207,10 +209,11 @@ 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,"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,"textsize", str(self.textSize))
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))
+110 -5
View File
@@ -16,11 +16,12 @@ import nw
from os import path from os import path
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon, QPixmap, QColor, QBrush, QStandardItemModel from PyQt5.QtGui import QIcon, QPixmap, QColor, QBrush, QStandardItemModel, QFont
from PyQt5.QtSvg import QSvgWidget from PyQt5.QtSvg import QSvgWidget
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QDialog, QHBoxLayout, QVBoxLayout, QFormLayout, QLineEdit, QPlainTextEdit, QLabel, QDialog, QHBoxLayout, QVBoxLayout, QFormLayout, QLineEdit, QPlainTextEdit, QLabel,
QWidget, QTabWidget, QDialogButtonBox, QSpinBox, QGroupBox, QComboBox, QMessageBox QWidget, QTabWidget, QDialogButtonBox, QSpinBox, QGroupBox, QComboBox, QMessageBox,
QCheckBox, QGridLayout, QFontComboBox
) )
from nw.enum import nwAlert from nw.enum import nwAlert
@@ -46,10 +47,12 @@ class GuiConfigEditor(QDialog):
self.svgGradient.setFixedWidth(80) self.svgGradient.setFixedWidth(80)
self.theProject.countStatus() self.theProject.countStatus()
self.tabMain = GuiConfigEditGeneral(self.theParent, self.theProject) self.tabMain = GuiConfigEditGeneral(self.theParent)
self.tabEditor = GuiConfigEditEditor(self.theParent)
self.tabWidget = QTabWidget() self.tabWidget = QTabWidget()
self.tabWidget.addTab(self.tabMain, "General") self.tabWidget.addTab(self.tabMain, "General")
self.tabWidget.addTab(self.tabEditor, "Editor")
self.setLayout(self.outerBox) self.setLayout(self.outerBox)
self.outerBox.addWidget(self.svgGradient) self.outerBox.addWidget(self.svgGradient)
@@ -74,6 +77,7 @@ class GuiConfigEditor(QDialog):
needsRestart = False needsRestart = False
needsRestart |= self.tabMain.saveValues() needsRestart |= self.tabMain.saveValues()
needsRestart |= self.tabEditor.saveValues()
if needsRestart: if needsRestart:
msgBox = QMessageBox() msgBox = QMessageBox()
@@ -95,12 +99,11 @@ class GuiConfigEditor(QDialog):
class GuiConfigEditGeneral(QWidget): class GuiConfigEditGeneral(QWidget):
def __init__(self, theParent, theProject): def __init__(self, theParent):
QWidget.__init__(self, theParent) QWidget.__init__(self, theParent)
self.mainConf = nw.CONFIG self.mainConf = nw.CONFIG
self.theParent = theParent self.theParent = theParent
self.theProject = theProject
self.outerBox = QVBoxLayout() self.outerBox = QVBoxLayout()
# User Interface # User Interface
@@ -160,3 +163,105 @@ class GuiConfigEditGeneral(QWidget):
return needsRestart return needsRestart
# END Class GuiConfigEditGeneral # END Class GuiConfigEditGeneral
class GuiConfigEditEditor(QWidget):
def __init__(self, theParent):
QWidget.__init__(self, theParent)
self.mainConf = nw.CONFIG
self.theParent = theParent
self.outerBox = QVBoxLayout()
# Text Style
self.textStyle = QGroupBox("Text Style", self)
self.textStyleForm = QGridLayout(self)
self.textStyle.setLayout(self.textStyleForm)
self.textStyleFont = QFontComboBox()
self.textStyleFont.setMaximumWidth(250)
self.textStyleFont.setCurrentFont(QFont(self.mainConf.textFont))
self.textStyleSize = QSpinBox(self)
self.textStyleSize.setMinimum(5)
self.textStyleSize.setMaximum(120)
self.textStyleSize.setSingleStep(1)
self.textStyleSize.setValue(self.mainConf.textSize)
self.textStyleForm.addWidget(QLabel("Font"), 0, 0)
self.textStyleForm.addWidget(self.textStyleFont, 0, 1, 1, 2)
self.textStyleForm.addWidget(QLabel("Font Size"), 1, 0)
self.textStyleForm.addWidget(self.textStyleSize, 1, 1)
self.textStyleForm.setColumnStretch(3, 1)
# Text Flow
self.textFlow = QGroupBox("Text Flow", self)
self.textFlowForm = QGridLayout(self)
self.textFlow.setLayout(self.textFlowForm)
self.textFlowFixed = QCheckBox(self)
self.textFlowFixed.setToolTip("Make text in editor fixed width and scale margins instead.")
if self.mainConf.textFixedW:
self.textFlowFixed.setCheckState(Qt.Checked)
else:
self.textFlowFixed.setCheckState(Qt.Unchecked)
self.textFlowWidth = QSpinBox(self)
self.textFlowWidth.setMinimum(300)
self.textFlowWidth.setMaximum(10000)
self.textFlowWidth.setSingleStep(10)
self.textFlowWidth.setValue(self.mainConf.textWidth)
self.textFlowJustify = QCheckBox(self)
self.textFlowJustify.setToolTip("Justify text in main document editor.")
if self.mainConf.doJustify:
self.textFlowJustify.setCheckState(Qt.Checked)
else:
self.textFlowJustify.setCheckState(Qt.Unchecked)
self.testFlowAutoSelect = QCheckBox(self)
self.testFlowAutoSelect.setToolTip("Auto-select word under cursor when applying formatting.")
if self.mainConf.autoSelect:
self.testFlowAutoSelect.setCheckState(Qt.Checked)
else:
self.testFlowAutoSelect.setCheckState(Qt.Unchecked)
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("Justify Text"), 1, 0)
self.textFlowForm.addWidget(self.textFlowJustify, 1, 1)
self.textFlowForm.addWidget(QLabel("Auto-Select Text"), 2, 0)
self.textFlowForm.addWidget(self.testFlowAutoSelect, 2, 1)
self.textFlowForm.setColumnStretch(4, 1)
# Assemble
self.outerBox.addWidget(self.textStyle)
self.outerBox.addWidget(self.textFlow)
self.outerBox.addStretch(0)
self.setLayout(self.outerBox)
return
def saveValues(self):
textFont = self.textStyleFont.currentFont().family()
textSize = self.textStyleSize.value()
self.mainConf.textFont = textFont
self.mainConf.textSize = textSize
textWidth = self.textFlowWidth.value()
textFixedW = self.textFlowFixed.isChecked()
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.confChanged = True
return False
# END Class GuiConfigEditEditor
+19 -1
View File
@@ -18,7 +18,7 @@ from time import time
from PyQt5.QtCore import Qt, QTimer from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import QTextEdit, QAction, QMenu, QShortcut from PyQt5.QtWidgets import QTextEdit, QAction, QMenu, QShortcut
from PyQt5.QtGui import QTextCursor, QTextOption, QIcon, QKeySequence from PyQt5.QtGui import QTextCursor, QTextOption, QIcon, QKeySequence, QFont
from nw.project.document import NWDoc from nw.project.document import NWDoc
from nw.gui.dochighlight import GuiDocHighlighter from nw.gui.dochighlight import GuiDocHighlighter
@@ -113,7 +113,18 @@ class GuiDocEditor(QTextEdit):
return True return True
def initEditor(self): def initEditor(self):
tHandle = self.theHandle
# Set Font
if self.mainConf.textFont is not None:
self.setFontFamily(self.mainConf.textFont)
else:
# If none is defined, set the default back to config
theFont = self.theQDoc.defaultFont().family()
self.mainConf.textFont = theFont
self.setFontPointSize(self.mainConf.textSize) self.setFontPointSize(self.mainConf.textSize)
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)
@@ -121,12 +132,19 @@ class GuiDocEditor(QTextEdit):
mTB = self.mainConf.textMargin[0] mTB = self.mainConf.textMargin[0]
mLR = self.mainConf.textMargin[1] mLR = self.mainConf.textMargin[1]
self.setViewportMargins(mLR,mTB,mLR,mTB) self.setViewportMargins(mLR,mTB,mLR,mTB)
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)
if self.mainConf.doJustify: if self.mainConf.doJustify:
theOpt.setAlignment(Qt.AlignJustify) theOpt.setAlignment(Qt.AlignJustify)
self.theQDoc.setDefaultTextOption(theOpt) self.theQDoc.setDefaultTextOption(theOpt)
if tHandle is not None:
self.hLight.initHighlighter()
self.clearEditor()
self.loadText(tHandle)
return True return True
def loadText(self, tHandle): def loadText(self, tHandle):
+11 -3
View File
@@ -32,7 +32,9 @@ class GuiDocHighlighter(QSyntaxHighlighter):
self.theDict = None self.theDict = None
self.theHandle = None self.theHandle = None
self.spellCheck = False self.spellCheck = False
self.spellRx = None
self.hRules = [] self.hRules = []
self.hStyles = {}
self.colHead = QColor(*self.theTheme.colHead) self.colHead = QColor(*self.theTheme.colHead)
self.colHeadH = QColor(*self.theTheme.colHeadH) self.colHeadH = QColor(*self.theTheme.colHeadH)
@@ -47,6 +49,14 @@ class GuiDocHighlighter(QSyntaxHighlighter):
self.colTagErr = QColor(*self.theTheme.colTagErr) self.colTagErr = QColor(*self.theTheme.colTagErr)
self.colRepTag = QColor(*self.theTheme.colRepTag) self.colRepTag = QColor(*self.theTheme.colRepTag)
self.initHighlighter()
logger.debug("DocHighlighter initialisation complete")
return
def initHighlighter(self):
self.hStyles = { self.hStyles = {
"header1" : self._makeFormat(self.colHead, "bold",1.8), "header1" : self._makeFormat(self.colHead, "bold",1.8),
"header2" : self._makeFormat(self.colHead, "bold",1.6), "header2" : self._makeFormat(self.colHead, "bold",1.6),
@@ -160,9 +170,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
self.rules = [(QRegularExpression(a),b) for (a,b) in self.hRules] self.rules = [(QRegularExpression(a),b) for (a,b) in self.hRules]
self.spellRx = QRegularExpression(r"\b[^\s]+\b") self.spellRx = QRegularExpression(r"\b[^\s]+\b")
logger.debug("DocHighlighter initialisation complete") return True
return
## ##
# Setters # Setters
+1
View File
@@ -465,6 +465,7 @@ class GuiMain(QMainWindow):
if dlgConf.exec_() == QDialog.Accepted: if dlgConf.exec_() == QDialog.Accepted:
logger.debug("Applying new preferences") logger.debug("Applying new preferences")
self.initMain() self.initMain()
self.docEditor.initEditor()
return True return True
def editProjectDialog(self): def editProjectDialog(self):