Added a theme class that loads the theme from config

This commit is contained in:
Veronica K. B. Olsen
2019-05-18 20:48:19 +02:00
parent 48da59321b
commit a2a6fd60bc
7 changed files with 156 additions and 24 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ class GuiDocEditor(QTextEdit):
# Core Elements
self.theDoc = self.document()
self.theDict = enchant.Dict(self.mainConf.spellLanguage)
self.hLight = GuiDocHighlighter(self.theDoc)
self.hLight = GuiDocHighlighter(self.theDoc, self.theParent.theTheme)
self.hLight.setDict(self.theDict)
# Context Menu
+12 -12
View File
@@ -20,27 +20,27 @@ logger = logging.getLogger(__name__)
class GuiDocHighlighter(QSyntaxHighlighter):
def __init__(self, theDoc):
def __init__(self, theDoc, theTheme):
QSyntaxHighlighter.__init__(self, theDoc)
logger.debug("Initialising DocHighlighter ...")
self.mainConf = nw.CONFIG
self.theDoc = theDoc
self.theTheme = theTheme
self.theDict = None
self.spellCheck = False
self.hRules = []
self.colHead = QColor( 0,155,200)
self.colHeadH = QColor( 0,105,135)
self.colEmph = QColor(200,120, 0)
self.colDialN = QColor(200, 46, 0)
self.colDialD = QColor(184,200, 0)
self.colDialS = QColor(136,200, 0)
self.colComm = QColor(150,150,150)
self.colKey = QColor(200, 46, 0)
self.colVal = QColor(184,200, 0)
self.colSpell = QColor(200, 46, 0)
self.colHead = QColor(*self.theTheme.colHead)
self.colHeadH = QColor(*self.theTheme.colHeadH)
self.colEmph = QColor(*self.theTheme.colEmph)
self.colDialN = QColor(*self.theTheme.colDialN)
self.colDialD = QColor(*self.theTheme.colDialD)
self.colDialS = QColor(*self.theTheme.colDialS)
self.colComm = QColor(*self.theTheme.colComm)
self.colKey = QColor(*self.theTheme.colKey)
self.colVal = QColor(*self.theTheme.colVal)
self.colSpell = QColor(*self.theTheme.colSpell)
self.hStyles = {
"header1" : self._makeFormat(self.colHead, "bold",1.8),
+8 -6
View File
@@ -27,14 +27,16 @@ class GuiDocViewer(QTextBrowser):
# Class Variables
self.mainConf = nw.CONFIG
self.theParent = theParent
self.theTheme = theParent.theTheme
self.theDoc = self.document()
self.theDoc.setDefaultStyleSheet("""
h1, h2, h3, h4 {
color: rgb(0,155,200);
}
""")
self.theDoc.setDefaultStyleSheet((
"h1, h2, h3, h4 {{"
" color: rgb({0},{1},{2});"
"}}"
).format(
*self.theTheme.colHead
))
self.theDoc.setDocumentMargin(self.mainConf.textMargin[0])
self.setMinimumWidth(300)
+4 -5
View File
@@ -18,6 +18,7 @@ from PyQt5.QtWidgets import QWidget, QMainWindow, QVBoxLayout, QFrame, QSpl
from PyQt5.QtGui import QIcon, QPixmap, QColor
from PyQt5.QtCore import Qt, QTimer
from nw.theme import Theme
from nw.gui.doctree import GuiDocTree
from nw.gui.doceditor import GuiDocEditor
from nw.gui.docviewer import GuiDocViewer
@@ -42,12 +43,14 @@ class GuiMain(QMainWindow):
logger.debug("Initialising GUI ...")
self.mainConf = nw.CONFIG
self.theTheme = Theme()
self.theProject = NWProject(self)
self.theDocument = NWDoc(self.theProject, self)
self.resize(*self.mainConf.winGeometry)
self._setWindowTitle()
self.setWindowIcon(QIcon(path.join(self.mainConf.appPath,"..","novelWriter.svg")))
self.theTheme.loadTheme()
# Main GUI Elements
self.docEditor = GuiDocEditor(self)
@@ -107,11 +110,7 @@ class GuiMain(QMainWindow):
self.statusBar.showMessage("Ready")
# Load Theme StyleSheet
cssFile = path.join(self.mainConf.themePath,self.mainConf.guiTheme+".css")
if path.isfile(cssFile):
with open(cssFile,mode="r") as inFile:
theCss = inFile.read()
self.setStyleSheet(theCss)
self.setStyleSheet(self.theTheme.cssData)
self.asProjTimer = QTimer()
self.asProjTimer.setInterval(int(self.mainConf.autoSaveProj*1000))