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)
+120 -47
View File
@@ -16,6 +16,9 @@ import nw
from os import path, listdir
from PyQt5.QtWidgets import qApp
from PyQt5.QtGui import QPalette, QColor
from nw.enum import nwAlert
logger = logging.getLogger(__name__)
@@ -24,48 +27,60 @@ class Theme:
def __init__(self, theParent):
self.mainConf = nw.CONFIG
self.theParent = theParent
self.guiPath = "gui"
self.syntaxPath = "syntax"
self.cssName = "styles.css"
self.confName = "theme.conf"
self.themeList = []
self.syntaxList = []
self.mainConf = nw.CONFIG
self.theParent = theParent
self.guiPalette = QPalette()
self.guiPath = "gui"
self.syntaxPath = "syntax"
self.cssName = "style.qss"
self.confName = "theme.conf"
self.themeList = []
self.syntaxList = []
# Loaded Theme Settings
## Main
self.themeName = "No Name"
## Syntax
self.colText = [ 0, 0, 0]
self.colLink = [ 0, 0, 0]
self.colHead = [ 0, 0, 0]
self.colHeadH = [ 0, 0, 0]
self.colEmph = [ 0, 0, 0]
self.colDialN = [ 0, 0, 0]
self.colDialD = [ 0, 0, 0]
self.colDialS = [ 0, 0, 0]
self.colComm = [ 0, 0, 0]
self.colKey = [ 0, 0, 0]
self.colVal = [ 0, 0, 0]
self.colSpell = [ 0, 0, 0]
self.colTagErr = [ 0, 0, 0]
self.colRepTag = [ 0, 0, 0]
## Theme
self.themeName = ""
self.themeAuthor = ""
self.themeCredit = ""
self.themeUrl = ""
## GUI
self.treeWCount = [ 0, 0, 0]
self.statNone = [120,120,120]
self.statUnsaved = [120,120, 40]
self.statSaved = [ 40,120, 0]
self.treeWCount = [ 0, 0, 0]
self.statNone = [120,120,120]
self.statUnsaved = [120,120, 40]
self.statSaved = [ 40,120, 0]
# Loaded Syntax Settings
## Main
self.syntaxName = ""
self.syntaxAuthor = ""
self.syntaxCredit = ""
self.syntaxUrl = ""
## Colours
self.colBack = [255,255,255]
self.colText = [ 0, 0, 0]
self.colLink = [ 0, 0, 0]
self.colHead = [ 0, 0, 0]
self.colHeadH = [ 0, 0, 0]
self.colEmph = [ 0, 0, 0]
self.colDialN = [ 0, 0, 0]
self.colDialD = [ 0, 0, 0]
self.colDialS = [ 0, 0, 0]
self.colComm = [ 0, 0, 0]
self.colKey = [ 0, 0, 0]
self.colVal = [ 0, 0, 0]
self.colSpell = [ 0, 0, 0]
self.colTagErr = [ 0, 0, 0]
self.colRepTag = [ 0, 0, 0]
# Changeable Settings
self.guiTheme = None
self.guiSyntax = None
self.themeRoot = None
self.cssFile = None
self.cssData = ""
self.guiTheme = None
self.guiSyntax = None
self.themeRoot = None
self.cssFile = None
self.updateTheme()
@@ -85,8 +100,6 @@ class Theme:
self.confFile = path.join(self.themePath,self.confName)
self.cssFile = path.join(self.themePath,self.cssName)
print(self.guiSyntax)
self.loadTheme()
self.loadSyntax()
@@ -97,14 +110,57 @@ class Theme:
logger.debug("Loading theme files")
# CSS File
cssData = ""
try:
if path.isfile(self.cssFile):
with open(self.cssFile,mode="r") as inFile:
self.cssData = inFile.read()
cssData = inFile.read()
except Exception as e:
logger.error("Could not load theme css file")
return False
# Config File
confParser = configparser.ConfigParser()
try:
confParser.read_file(open(self.confFile))
except Exception as e:
logger.error("Could not load theme settings from: %s" % self.confFile)
return False
## Main
cnfSec = "Main"
if confParser.has_section(cnfSec):
self.themeName = self._parseLine(confParser,cnfSec,"name", "")
self.themeAuthor = self._parseLine(confParser,cnfSec,"author","")
self.themeCredit = self._parseLine(confParser,cnfSec,"credit","")
self.themeUrl = self._parseLine(confParser,cnfSec,"url", "")
## Palette
cnfSec = "Palette"
if confParser.has_section(cnfSec):
self._setPalette(confParser,cnfSec,"window", QPalette.Window)
self._setPalette(confParser,cnfSec,"windowtext", QPalette.WindowText)
self._setPalette(confParser,cnfSec,"base", QPalette.Base)
self._setPalette(confParser,cnfSec,"alternatebase",QPalette.AlternateBase)
self._setPalette(confParser,cnfSec,"text", QPalette.Text)
self._setPalette(confParser,cnfSec,"tooltipbase", QPalette.ToolTipBase)
self._setPalette(confParser,cnfSec,"tooltiptext", QPalette.ToolTipText)
self._setPalette(confParser,cnfSec,"button", QPalette.Button)
self._setPalette(confParser,cnfSec,"buttontext", QPalette.ButtonText)
self._setPalette(confParser,cnfSec,"brighttext", QPalette.BrightText)
## GUI
cnfSec = "GUI"
if confParser.has_section(cnfSec):
self.treeWCount = self._loadColour(confParser,cnfSec,"treewordcount")
self.statNone = self._loadColour(confParser,cnfSec,"statusnone")
self.statUnsaved = self._loadColour(confParser,cnfSec,"statusunsaved")
self.statSaved = self._loadColour(confParser,cnfSec,"statussaved")
# Apply Styles
qApp.setStyleSheet(cssData)
qApp.setPalette(self.guiPalette)
return True
def loadSyntax(self):
@@ -119,11 +175,15 @@ class Theme:
## Main
cnfSec = "Main"
if confParser.has_section(cnfSec):
self.themeName = confParser.get(cnfSec,"name")
self.syntaxName = self._parseLine(confParser,cnfSec,"name","")
self.syntaxAuthor = self._parseLine(confParser,cnfSec,"author","")
self.syntaxCredit = self._parseLine(confParser,cnfSec,"credit","")
self.syntaxUrl = self._parseLine(confParser,cnfSec,"url", "")
## Syntax
cnfSec = "Syntax"
if confParser.has_section(cnfSec):
self.colBack = self._loadColour(confParser,cnfSec,"background")
self.colText = self._loadColour(confParser,cnfSec,"text")
self.colLink = self._loadColour(confParser,cnfSec,"link")
self.colHead = self._loadColour(confParser,cnfSec,"headertext")
@@ -139,14 +199,6 @@ class Theme:
self.colTagErr = self._loadColour(confParser,cnfSec,"tagerror")
self.colRepTag = self._loadColour(confParser,cnfSec,"replacetag")
## GUI
cnfSec = "GUI"
if confParser.has_section(cnfSec):
self.treeWCount = self._loadColour(confParser,cnfSec,"treewordcount")
self.statNone = self._loadColour(confParser,cnfSec,"statusnone")
self.statUnsaved = self._loadColour(confParser,cnfSec,"statusunsaved")
self.statSaved = self._loadColour(confParser,cnfSec,"statussaved")
logger.info("Loaded syntax colour theme '%s'" % self.guiSyntax)
return True
@@ -220,4 +272,25 @@ class Theme:
outData = [0,0,0]
return outData
def _setPalette(self, confParser, cnfSec, cnfName, paletteVal):
if confParser.has_option(cnfSec,cnfName):
inData = confParser.get(cnfSec,cnfName).split(",")
readCol = []
try:
readCol.append(int(inData[0]))
readCol.append(int(inData[1]))
readCol.append(int(inData[2]))
except:
logger.error("Could not load theme colours for '%s' from config file" % cnfName)
return
if len(readCol) == 3:
self.guiPalette.setColor(paletteVal, QColor(*readCol))
return
def _parseLine(self, confParser, cnfSec, cnfName, cnfDefault):
if confParser.has_section(cnfSec):
if confParser.has_option(cnfSec, cnfName):
return confParser.get(cnfSec, cnfName)
return cnfDefault
# End Class Theme
-21
View File
@@ -1,21 +0,0 @@
/**
* Default Theme: Dark
*/
* {
background-color: #999999;
}
QTextEdit {
background-color: #141414;
color: #c7cfd0;
}
QTextBrowser {
background-color: #141414;
color: #c7cfd0;
}
QTreeView, QHeaderView {
font-size: 13px;
}
+7
View File
@@ -0,0 +1,7 @@
/**
* Default Theme: Light
*/
QTreeView, QHeaderView {
font-size: 13px;
}
-17
View File
@@ -1,17 +0,0 @@
/**
* Default Theme: Light
*/
QTextEdit {
background-color: #ffffff;
color: #141414;
}
QTextBrowser {
background-color: #ffffff;
color: #141414;
}
QTreeView, QHeaderView {
font-size: 13px;
}
-1
View File
@@ -1,3 +1,2 @@
[Main]
name = Default System Theme
+7
View File
@@ -0,0 +1,7 @@
/**
* Default Theme: Dark
*/
QTreeView, QHeaderView {
font-size: 13px;
}
+23
View File
@@ -0,0 +1,23 @@
[Main]
name = Default Dark Theme
author = Veronica Berglyd Olsen
credit = Veronica Berglyd Olsen
url = https://github.com/vkbo/novelWriter
[Palette]
window = 54, 54, 54
windowtext = 174, 174, 174
base = 62, 62, 62
alternatebase = 67, 67, 67
text = 174, 174, 174
tooltipbase = 255, 255, 192
tooltiptext = 21, 21, 13
button = 62, 62, 62
buttontext = 174, 174, 174
brighttext = 174, 174, 174
[GUI]
treewordcount = 197, 200, 198
statusnone = 150, 152, 150
statussaved = 39, 135, 78
statusunsaved = 138, 32, 32
+1
View File
@@ -2,6 +2,7 @@
name = Default Dark
[Syntax]
background = 54, 54, 54
text = 199, 207, 208
link = 184, 200, 0
headertext = 0, 155, 200
+1
View File
@@ -2,6 +2,7 @@
name = Default Light
[Syntax]
background = 255, 255, 255
text = 0, 0, 0
link = 0, 0, 200
headertext = 0, 100, 00
+42
View File
@@ -0,0 +1,42 @@
##
# Theme: Tomorrow
# Source: https://github.com/chriskempson/tomorrow-theme
# Credit: Chris Kempson
##
# Colours:
# Background = 2d2d2d : 45, 45, 45
# Current Line = 393939 : 57, 57, 57
# Selection = 515151 : 81, 81, 81
# Foreground = cccccc : 204, 204, 204
# Comment = 999999 : 153, 153, 153
# Red = f2777a : 242, 119, 122
# Orange = f99157 : 249, 145, 57
# Yellow = ffcc66 : 255, 204, 102
# Green = 99cc99 : 153, 204, 153
# Aqua = 66cccc : 102, 204, 204
# Blue = 6699cc : 102, 153, 204
# Purple = cc99cc : 204, 153, 204
##
[Main]
name = Tomorrow
author = Veronica Berglyd Olsen
credit = Chris Kempson
url = https://github.com/chriskempson/tomorrow-theme
[Syntax]
background = 45, 45, 45
text = 204, 204, 204
link = 102, 153, 204
headertext = 102, 153, 204
headertag = 102, 153, 204
emphasis = 249, 145, 57
straightquotes = 242, 119, 122
doublequotes = 153, 204, 153
singlequotes = 255, 204, 102
hidden = 153, 153, 153
keyword = 242, 119, 122
value = 204, 153, 204
spellcheckline = 242, 119, 122
tagerror = 153, 204, 153
replacetag = 102, 204, 204
@@ -1,5 +1,5 @@
##
# Theme: Base16 Tomorrow Night
# Theme: Tomorrow Night
# Source: https://github.com/chriskempson/tomorrow-theme
# Credit: Chris Kempson
##
@@ -19,9 +19,13 @@
##
[Main]
name = Base16 Tomorrow Night
name = Tomorrow Night
author = Veronica Berglyd Olsen
credit = Chris Kempson
url = https://github.com/chriskempson/tomorrow-theme
[Syntax]
background = 29, 31, 33
text = 197, 200, 198
link = 129, 162, 190
headertext = 129, 162, 190
@@ -36,9 +40,3 @@ value = 178, 148, 187
spellcheckline = 204, 102, 102
tagerror = 181, 189, 104
replacetag = 138, 190, 183
[GUI]
treewordcount = 197, 200, 198
statusnone = 150, 152, 150
statussaved = 39, 135, 78
statusunsaved = 138, 32, 32
@@ -0,0 +1,42 @@
##
# Theme: Tomorrow Night Eighties
# Source: https://github.com/chriskempson/tomorrow-theme
# Credit: Chris Kempson
##
# Colours:
# Background = 2d2d2d : 45, 45, 45
# Current Line = 393939 : 57, 57, 57
# Selection = 515151 : 81, 81, 81
# Foreground = cccccc : 204, 204, 204
# Comment = 999999 : 153, 153, 153
# Red = f2777a : 242, 119, 122
# Orange = f99157 : 249, 145, 57
# Yellow = ffcc66 : 255, 204, 102
# Green = 99cc99 : 153, 204, 153
# Aqua = 66cccc : 102, 204, 204
# Blue = 6699cc : 102, 153, 204
# Purple = cc99cc : 204, 153, 204
##
[Main]
name = Tomorrow Night Eighties
author = Veronica Berglyd Olsen
credit = Chris Kempson
url = https://github.com/chriskempson/tomorrow-theme
[Syntax]
background = 45, 45, 45
text = 204, 204, 204
link = 102, 153, 204
headertext = 102, 153, 204
headertag = 102, 153, 204
emphasis = 249, 145, 57
straightquotes = 242, 119, 122
doublequotes = 153, 204, 153
singlequotes = 255, 204, 102
hidden = 153, 153, 153
keyword = 242, 119, 122
value = 204, 153, 204
spellcheckline = 242, 119, 122
tagerror = 153, 204, 153
replacetag = 102, 204, 204