From db67816276ed25a1462c30e15e178b0785e564ff Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Tue, 23 Apr 2019 17:45:38 +0200 Subject: [PATCH] Added text size and justify as editor options. --- nw/config.py | 8 ++++++++ nw/gui/doceditor.py | 9 ++++++--- nw/gui/dochighlight.py | 12 ++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/nw/config.py b/nw/config.py index f34c870d..f5ae78d2 100644 --- a/nw/config.py +++ b/nw/config.py @@ -61,6 +61,8 @@ class Config: self.textFixedW = True self.textWidth = 600 self.textMargin = [40, 40] + self.textSize = 13 + self.doJustify = True self.autoSelect = True self.doReplace = True self.doReplaceSQuote = True @@ -122,6 +124,10 @@ class Config: self.textMargin = self.unpackList( confParser.get(cnfSec,"margins"), 2, self.textMargin ) + if confParser.has_option(cnfSec,"textsize"): + self.textSize = confParser.getint(cnfSec,"textsize") + if confParser.has_option(cnfSec,"justify"): + self.doJustify = confParser.getboolean(cnfSec,"justify") if confParser.has_option(cnfSec,"autoselect"): self.autoSelect = confParser.getboolean(cnfSec,"autoselect") if confParser.has_option(cnfSec,"autoreplace"): @@ -169,6 +175,8 @@ class Config: confParser.set(cnfSec,"fixedwidth", str(self.textFixedW)) confParser.set(cnfSec,"width", str(self.textWidth)) confParser.set(cnfSec,"margins", self.packList(self.textMargin)) + confParser.set(cnfSec,"textsize", str(self.textSize)) + confParser.set(cnfSec,"justify", str(self.doJustify)) confParser.set(cnfSec,"autoselect", str(self.autoSelect)) confParser.set(cnfSec,"autoreplace",str(self.doReplace)) confParser.set(cnfSec,"repsquotes", str(self.doReplaceSQuote)) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index a0b516d1..6e9e6625 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -16,8 +16,8 @@ import nw from time import time from PyQt5.QtWidgets import QTextEdit -from PyQt5.QtCore import QTimer -from PyQt5.QtGui import QTextCursor +from PyQt5.QtCore import Qt, QTimer +from PyQt5.QtGui import QTextCursor, QTextOption from nw.gui.dochighlight import GuiDocHighlighter from nw.gui.wordcounter import WordCounter @@ -61,12 +61,15 @@ class GuiDocEditor(QTextEdit): self.setViewportMargins(mLR,mTB,mLR,mTB) self.theDoc = self.document() + self.hLight = GuiDocHighlighter(self.theDoc) self.theDoc.setDocumentMargin(0) self.theDoc.contentsChange.connect(self._docChange) - self.hLight = GuiDocHighlighter(self.theDoc) + if self.mainConf.doJustify: + self.theDoc.setDefaultTextOption(QTextOption(Qt.AlignJustify)) self.setMinimumWidth(400) self.setAcceptRichText(False) + self.setFontPointSize(self.mainConf.textSize) # Set Up Word Count Thread and Timer self.wcInterval = self.mainConf.wordCountTimer diff --git a/nw/gui/dochighlight.py b/nw/gui/dochighlight.py index 7f11e96d..2287e535 100644 --- a/nw/gui/dochighlight.py +++ b/nw/gui/dochighlight.py @@ -37,10 +37,10 @@ class GuiDocHighlighter(QSyntaxHighlighter): self.colVal = (184,200, 0,255) self.hStyles = { - "header1" : self._makeFormat(self.colHead,"bold",20), - "header2" : self._makeFormat(self.colHead,"bold",18), - "header3" : self._makeFormat(self.colHead,"bold",16), - "header4" : self._makeFormat(self.colHead,"bold",14), + "header1" : self._makeFormat(self.colHead,"bold",1.8), + "header2" : self._makeFormat(self.colHead,"bold",1.6), + "header3" : self._makeFormat(self.colHead,"bold",1.4), + "header4" : self._makeFormat(self.colHead,"bold",1.2), "bold" : self._makeFormat(self.colEmph,"bold"), "italic" : self._makeFormat(self.colEmph,"italic"), "strike" : self._makeFormat(self.colEmph,"strike"), @@ -103,8 +103,8 @@ class GuiDocHighlighter(QSyntaxHighlighter): if "underline" in fmtStyle: theFormat.setFontUnderline(True) - if isinstance(fmtSize,int): - theFormat.setFontPointSize(fmtSize) + if fmtSize is not None: + theFormat.setFontPointSize(round(fmtSize*self.mainConf.textSize)) return theFormat