Major reorganisation of themes, and added a few more syntax themes

This commit is contained in:
Veronica K. B. Olsen
2019-06-15 20:07:35 +02:00
parent 583e10adec
commit b934d0439a
17 changed files with 347 additions and 159 deletions
+13 -7
View File
@@ -17,7 +17,7 @@ from time import time
from PyQt5.QtCore import Qt, QTimer, QSizeF
from PyQt5.QtWidgets import QTextEdit, QAction, QMenu, QShortcut
from PyQt5.QtGui import QTextCursor, QTextOption, QIcon, QKeySequence, QFont
from PyQt5.QtGui import QTextCursor, QTextOption, QIcon, QKeySequence, QFont, QColor, QPalette
from nw.project.document import NWDoc
from nw.gui.dochighlight import GuiDocHighlighter
@@ -37,8 +37,9 @@ class GuiDocEditor(QTextEdit):
# Class Variables
self.mainConf = nw.CONFIG
self.theParent = theParent
self.theProject = theProject
self.theParent = theParent
self.theTheme = theParent.theTheme
self.docChanged = False
self.spellCheck = False
self.nwDocument = NWDoc(self.theProject, self.theParent)
@@ -132,6 +133,11 @@ class GuiDocEditor(QTextEdit):
theFont.setPointSize(self.mainConf.textSize)
self.setFont(theFont)
docPalette = self.palette()
docPalette.setColor(QPalette.Base, QColor(*self.theTheme.colBack))
docPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText))
self.setPalette(docPalette)
# Set text fixed width, or alternatively, just margins
self.qDocument.setDocumentMargin(self.mainConf.textMargin)
@@ -249,11 +255,11 @@ class GuiDocEditor(QTextEdit):
tM = int((wW - sW - tW)/2)
if tM < 0:
tM = 0
# print(wW, tW, dW, sW, tM)
self.setViewportMargins(tM,0,tM,0)
self.qDocument.setTextWidth(tW)
else:
self.setViewportMargins(0,0,0,0)
docFormat = self.qDocument.rootFrame().frameFormat()
docFormat.setLeftMargin(tM)
docFormat.setRightMargin(tM)
self.qDocument.rootFrame().setFrameFormat(docFormat)
return
def docAction(self, theAction):
+1 -1
View File
@@ -360,7 +360,7 @@ class GuiDocTree(QTreeWidget):
newItem.setText(self.C_FLAGS, "")
newItem.setText(self.C_HANDLE, tHandle)
newItem.setForeground(self.C_COUNT,QColor(*self.theParent.theTheme.treeWCount))
# newItem.setForeground(self.C_COUNT,QColor(*self.theParent.theTheme.treeWCount))
newItem.setTextAlignment(self.C_COUNT,Qt.AlignRight)
newItem.setFont(self.C_FLAGS,self.fontFlags)
+65 -49
View File
@@ -15,7 +15,7 @@ import nw
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtWidgets import QTextBrowser
from PyQt5.QtGui import QTextOption, QFont
from PyQt5.QtGui import QTextOption, QFont, QPalette, QColor
from nw.convert.tokenizer import Tokenizer
from nw.convert.tohtml import ToHtml
@@ -37,57 +37,14 @@ class GuiDocViewer(QTextBrowser):
self.theTheme = theParent.theTheme
self.theHandle = None
self.theQDoc = self.document()
self.theQDoc.setDefaultStyleSheet((
"body {{"
" font-size: {textSize}pt;"
" color: rgb({tColR},{tColG},{tColB});"
"}}\n"
"h1, h2, h3, h4 {{"
" color: rgb({hColR},{hColG},{hColB});"
"}}\n"
"a {{"
" color: rgb({aColR},{aColG},{aColB});"
"}}\n"
"pre {{"
" color: rgb({cColR},{cColG},{cColB});"
" font-size: {preSize}pt;"
"}}\n"
"mark {{"
" color: rgb({eColR},{eColG},{eColB});"
"}}\n"
"table {{"
" margin: 10px 0px;"
"}}\n"
"td {{"
" padding: 0px 4px;"
"}}\n"
).format(
textSize = self.mainConf.textSize,
preSize = self.mainConf.textSize*0.9,
tColR = self.theTheme.colText[0],
tColG = self.theTheme.colText[1],
tColB = self.theTheme.colText[2],
hColR = self.theTheme.colHead[0],
hColG = self.theTheme.colHead[1],
hColB = self.theTheme.colHead[2],
cColR = self.theTheme.colComm[0],
cColG = self.theTheme.colComm[1],
cColB = self.theTheme.colComm[2],
eColR = self.theTheme.colEmph[0],
eColG = self.theTheme.colEmph[1],
eColB = self.theTheme.colEmph[2],
aColR = self.theTheme.colLink[0],
aColG = self.theTheme.colLink[1],
aColB = self.theTheme.colLink[2],
))
self.qDocument = self.document()
self.setMinimumWidth(300)
self.initViewer()
theOpt = QTextOption()
if self.mainConf.doJustify:
theOpt.setAlignment(Qt.AlignJustify)
self.theQDoc.setDefaultTextOption(theOpt)
self.qDocument.setDefaultTextOption(theOpt)
logger.debug("DocViewer initialisation complete")
@@ -102,20 +59,27 @@ class GuiDocViewer(QTextBrowser):
"""Set editor settings from main config.
"""
self._makeStyleSheet()
# Set Font
theFont = QFont()
if self.mainConf.textFont is None:
# If none is defined, set the default back to config
self.mainConf.textFont = self.theQDoc.defaultFont().family()
self.mainConf.textFont = self.qDocument.defaultFont().family()
theFont.setFamily(self.mainConf.textFont)
theFont.setPointSize(self.mainConf.textSize)
self.setFont(theFont)
self.theQDoc.setDocumentMargin(self.mainConf.textMargin)
docPalette = self.palette()
docPalette.setColor(QPalette.Base, QColor(*self.theTheme.colBack))
docPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText))
self.setPalette(docPalette)
self.qDocument.setDocumentMargin(self.mainConf.textMargin)
theOpt = QTextOption()
if self.mainConf.doJustify:
theOpt.setAlignment(Qt.AlignJustify)
self.theQDoc.setDefaultTextOption(theOpt)
self.qDocument.setDefaultTextOption(theOpt)
# If we have a document open, we should reload it in case the font changed
if self.theHandle is not None:
@@ -162,4 +126,56 @@ class GuiDocViewer(QTextBrowser):
return True
##
# Internal Functions
##
def _makeStyleSheet(self):
self.qDocument.setDefaultStyleSheet((
"body {{"
" font-size: {textSize}pt;"
" color: rgb({tColR},{tColG},{tColB});"
"}}\n"
"h1, h2, h3, h4 {{"
" color: rgb({hColR},{hColG},{hColB});"
"}}\n"
"a {{"
" color: rgb({aColR},{aColG},{aColB});"
"}}\n"
"pre {{"
" color: rgb({cColR},{cColG},{cColB});"
" font-size: {preSize}pt;"
"}}\n"
"mark {{"
" color: rgb({eColR},{eColG},{eColB});"
"}}\n"
"table {{"
" margin: 10px 0px;"
"}}\n"
"td {{"
" padding: 0px 4px;"
"}}\n"
).format(
textSize = self.mainConf.textSize,
preSize = self.mainConf.textSize*0.9,
tColR = self.theTheme.colText[0],
tColG = self.theTheme.colText[1],
tColB = self.theTheme.colText[2],
hColR = self.theTheme.colHead[0],
hColG = self.theTheme.colHead[1],
hColB = self.theTheme.colHead[2],
cColR = self.theTheme.colComm[0],
cColG = self.theTheme.colComm[1],
cColB = self.theTheme.colComm[2],
eColR = self.theTheme.colEmph[0],
eColG = self.theTheme.colEmph[1],
eColB = self.theTheme.colEmph[2],
aColR = self.theTheme.colLink[0],
aColG = self.theTheme.colLink[1],
aColB = self.theTheme.colLink[2],
))
return True
# END Class GuiDocViewer
+19 -4
View File
@@ -104,8 +104,8 @@ class GuiMainMenu(QMenuBar):
return True
def _showAbout(self):
msgBox = QMessageBox()
msgBox.about(self.theParent, "About %s" % nw.__package__, (
listPrefix = "&nbsp;&nbsp;&bull;&nbsp;&nbsp;"
aboutMsg = (
"<h3>About {name:s}</h3>"
"<p>Version: {version:s}<br>Release Date: {date:s}</p>"
"<p>{name:s} is a markdown-like text editor designed for organising and writing novels. "
@@ -121,8 +121,23 @@ class GuiMainMenu(QMenuBar):
date = nw.__date__,
copyright = nw.__copyright__,
website = nw.__url__,
credits = "".join(["&nbsp;&nbsp;&bull;&nbsp;&nbsp;%s<br/>" % x for x in nw.__credits__]),
))
credits = "<br/>".join(["%s%s" % (listPrefix, x) for x in nw.__credits__]),
)
theTheme = self.theParent.theTheme
if theTheme.themeCredit != "" or theTheme.syntaxCredit != "":
aboutMsg += "<h4>GUI Theme and Syntax Highlighting</h4>"
aboutMsg += "<p>"
if theTheme.themeCredit != "":
aboutMsg += "%s%s by %s<br/>" % (
listPrefix, theTheme.themeName, theTheme.themeCredit
)
if theTheme.syntaxCredit != "":
aboutMsg += "%s%s by %s<br/>" % (
listPrefix, theTheme.syntaxName, theTheme.syntaxCredit
)
aboutMsg += "</p>"
msgBox = QMessageBox()
msgBox.about(self.theParent, "About %s" % nw.__package__, aboutMsg)
return True
def _showAboutQt(self):
-4
View File
@@ -58,7 +58,6 @@ class GuiMain(QMainWindow):
self.resize(*self.mainConf.winGeometry)
self._setWindowTitle()
self.setWindowIcon(QIcon(path.join(self.mainConf.appRoot, nwFiles.APP_ICON)))
self.theTheme.updateTheme()
# Main GUI Elements
self.statusBar = GuiMainStatus(self)
@@ -114,9 +113,6 @@ class GuiMain(QMainWindow):
self.setStatusBar(self.statusBar)
self.statusBar.showMessage("Ready")
# Load Theme StyleSheet
self.setStyleSheet(self.theTheme.cssData)
# Set Up Autosaving Project Timer
self.asProjTimer = QTimer()
self.asProjTimer.timeout.connect(self._autoSaveProject)