Merge branch 'master' of github.com:vkbo/novelWriter
This commit is contained in:
+32
-1
@@ -19,7 +19,8 @@ def checkString(checkValue, defaultValue, allowNone=False):
|
|||||||
if allowNone:
|
if allowNone:
|
||||||
if checkValue == None: return None
|
if checkValue == None: return None
|
||||||
if checkValue == "None": return None
|
if checkValue == "None": return None
|
||||||
if isinstance(checkValue,str): return str(checkValue)
|
if isinstance(checkValue,str):
|
||||||
|
return str(checkValue)
|
||||||
return defaultValue
|
return defaultValue
|
||||||
|
|
||||||
def checkInt(checkValue, defaultValue, allowNone=False):
|
def checkInt(checkValue, defaultValue, allowNone=False):
|
||||||
@@ -50,3 +51,33 @@ def checkBool(checkValue, defaultValue, allowNone=False):
|
|||||||
else:
|
else:
|
||||||
return defaultValue
|
return defaultValue
|
||||||
return defaultValue
|
return defaultValue
|
||||||
|
|
||||||
|
def colRange(rgbStart, rgbEnd, nStep):
|
||||||
|
|
||||||
|
if len(rgbStart) != 3 and len(rgbEnd) != 3 and nStep < 1:
|
||||||
|
logger.error("Cannot create colour range from given parameters")
|
||||||
|
return None
|
||||||
|
|
||||||
|
if nStep == 1:
|
||||||
|
return rgbStart
|
||||||
|
elif nStep == 2:
|
||||||
|
return [rgbStart, rgbEnd]
|
||||||
|
|
||||||
|
dC = [0,0,0]
|
||||||
|
for c in range(3):
|
||||||
|
cA = rgbStart[c]
|
||||||
|
cB = rgbEnd[c]
|
||||||
|
dC[c] = (cB-cA)/(nStep-1)
|
||||||
|
print(dC)
|
||||||
|
retCol = [rgbStart]
|
||||||
|
for n in range(nStep):
|
||||||
|
if n > 0 and n < nStep:
|
||||||
|
retCol.append([
|
||||||
|
int(retCol[n-1][0] + dC[0]),
|
||||||
|
int(retCol[n-1][1] + dC[1]),
|
||||||
|
int(retCol[n-1][2] + dC[2]),
|
||||||
|
])
|
||||||
|
retCol[-1] = rgbEnd
|
||||||
|
print(retCol)
|
||||||
|
|
||||||
|
return retCol
|
||||||
|
|||||||
+11
-3
@@ -71,11 +71,19 @@ class GuiDocDetails(QFrame):
|
|||||||
colTwo = [""]*4
|
colTwo = [""]*4
|
||||||
else:
|
else:
|
||||||
itemStatus = nwItem.itemStatus
|
itemStatus = nwItem.itemStatus
|
||||||
if itemStatus < 0 or itemStatus >= len(self.theParent.statusLabels):
|
if nwItem.itemClass == nwItemClass.NOVEL:
|
||||||
itemStatus = 0
|
if itemStatus < 0 or itemStatus >= len(self.theParent.statusLabels):
|
||||||
|
statusLabel = self.theParent.statusLabels[0]
|
||||||
|
else:
|
||||||
|
statusLabel = self.theParent.statusLabels[itemStatus]
|
||||||
|
else:
|
||||||
|
if itemStatus < 0 or itemStatus >= len(self.theParent.importLabels):
|
||||||
|
statusLabel = self.theParent.importLabels[0]
|
||||||
|
else:
|
||||||
|
statusLabel = self.theParent.importLabels[itemStatus]
|
||||||
colTwo = [
|
colTwo = [
|
||||||
nwItem.itemName,
|
nwItem.itemName,
|
||||||
self.theParent.statusLabels[itemStatus],
|
statusLabel,
|
||||||
nwLabels.CLASS_NAME[nwItem.itemClass],
|
nwLabels.CLASS_NAME[nwItem.itemClass],
|
||||||
nwLabels.LAYOUT_NAME[nwItem.itemLayout],
|
nwLabels.LAYOUT_NAME[nwItem.itemLayout],
|
||||||
]
|
]
|
||||||
|
|||||||
+13
-5
@@ -19,9 +19,8 @@ from PyQt5.QtGui import QIcon, QFont, QColor
|
|||||||
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QAbstractItemView, QInputDialog, QLineEdit, QApplication
|
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QAbstractItemView, QInputDialog, QLineEdit, QApplication
|
||||||
|
|
||||||
from nw.project.item import NWItem
|
from nw.project.item import NWItem
|
||||||
from nw.enum import nwItemType, nwItemClass
|
from nw.enum import nwItemType, nwItemClass, nwAlert
|
||||||
from nw.constants import nwLabels
|
from nw.constants import nwLabels
|
||||||
from nw.enum import nwAlert
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -256,6 +255,7 @@ class GuiDocTree(QTreeWidget):
|
|||||||
trItem = self._getTreeItem(tHandle)
|
trItem = self._getTreeItem(tHandle)
|
||||||
nwItem = self.theProject.getItem(tHandle)
|
nwItem = self.theProject.getItem(tHandle)
|
||||||
tName = nwItem.itemName
|
tName = nwItem.itemName
|
||||||
|
tClass = nwItem.itemClass
|
||||||
tHandle = nwItem.itemHandle
|
tHandle = nwItem.itemHandle
|
||||||
pHandle = nwItem.parHandle
|
pHandle = nwItem.parHandle
|
||||||
|
|
||||||
@@ -263,12 +263,20 @@ class GuiDocTree(QTreeWidget):
|
|||||||
if nwItem.itemType == nwItemType.FILE:
|
if nwItem.itemType == nwItemType.FILE:
|
||||||
tStatus += "."+nwLabels.LAYOUT_FLAG[nwItem.itemLayout]
|
tStatus += "."+nwLabels.LAYOUT_FLAG[nwItem.itemLayout]
|
||||||
nStatus = nwItem.itemStatus
|
nStatus = nwItem.itemStatus
|
||||||
if nStatus < 0 or nStatus >= len(self.theParent.statusIcons):
|
if tClass == nwItemClass.NOVEL:
|
||||||
nStatus = 0
|
if nStatus < 0 or nStatus >= len(self.theParent.statusIcons):
|
||||||
|
flagIcon = self.theParent.statusIcons[0]
|
||||||
|
else:
|
||||||
|
flagIcon = self.theParent.statusIcons[nStatus]
|
||||||
|
else:
|
||||||
|
if nStatus < 0 or nStatus >= len(self.theParent.importIcons):
|
||||||
|
flagIcon = self.theParent.importIcons[0]
|
||||||
|
else:
|
||||||
|
flagIcon = self.theParent.importIcons[nStatus]
|
||||||
|
|
||||||
trItem.setText(self.C_NAME,tName)
|
trItem.setText(self.C_NAME,tName)
|
||||||
trItem.setText(self.C_FLAGS,tStatus)
|
trItem.setText(self.C_FLAGS,tStatus)
|
||||||
trItem.setIcon(self.C_FLAGS,self.theParent.statusIcons[nStatus])
|
trItem.setIcon(self.C_FLAGS,flagIcon)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
+10
-4
@@ -54,10 +54,16 @@ class GuiItemEditor(QDialog):
|
|||||||
self.editStatus = QComboBox()
|
self.editStatus = QComboBox()
|
||||||
self.editLayout = QComboBox()
|
self.editLayout = QComboBox()
|
||||||
|
|
||||||
for n in range(len(self.theParent.statusLabels)):
|
if self.theItem.itemClass == nwItemClass.NOVEL:
|
||||||
self.editStatus.addItem(
|
for n in range(len(self.theParent.statusLabels)):
|
||||||
self.theParent.statusIcons[n], self.theParent.statusLabels[n], n
|
self.editStatus.addItem(
|
||||||
)
|
self.theParent.statusIcons[n], self.theParent.statusLabels[n], n
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
for n in range(len(self.theParent.statusLabels)):
|
||||||
|
self.editStatus.addItem(
|
||||||
|
self.theParent.importIcons[n], self.theParent.importLabels[n], n
|
||||||
|
)
|
||||||
|
|
||||||
self.validLayouts = []
|
self.validLayouts = []
|
||||||
if self.theItem.itemType == nwItemType.FILE:
|
if self.theItem.itemType == nwItemType.FILE:
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ class GuiMain(QMainWindow):
|
|||||||
# Minor Gui Elements
|
# Minor Gui Elements
|
||||||
self.statusIcons = []
|
self.statusIcons = []
|
||||||
self.statusLabels = []
|
self.statusLabels = []
|
||||||
|
self.importIcons = []
|
||||||
|
self.importLabels = []
|
||||||
|
|
||||||
# Assemble Main Window
|
# Assemble Main Window
|
||||||
self.stackPane = QStackedWidget()
|
self.stackPane = QStackedWidget()
|
||||||
@@ -87,6 +89,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.treeView.itemDoubleClicked.connect(self._treeDoubleClick)
|
self.treeView.itemDoubleClicked.connect(self._treeDoubleClick)
|
||||||
self.treeView.buildTree()
|
self.treeView.buildTree()
|
||||||
self._makeStatusIcons()
|
self._makeStatusIcons()
|
||||||
|
self._makeImportIcons()
|
||||||
|
|
||||||
# Set Main Window Elements
|
# Set Main Window Elements
|
||||||
self.setMenuBar(self.mainMenu)
|
self.setMenuBar(self.mainMenu)
|
||||||
@@ -179,6 +182,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.treeView.buildTree()
|
self.treeView.buildTree()
|
||||||
self._setWindowTitle(self.theProject.projName)
|
self._setWindowTitle(self.theProject.projName)
|
||||||
self._makeStatusIcons()
|
self._makeStatusIcons()
|
||||||
|
self._makeImportIcons()
|
||||||
self.docEditor.setPwl(path.join(self.theProject.projMeta,"wordlist.txt"))
|
self.docEditor.setPwl(path.join(self.theProject.projMeta,"wordlist.txt"))
|
||||||
self.docEditor.setSpellCheck(self.theProject.spellCheck)
|
self.docEditor.setSpellCheck(self.theProject.spellCheck)
|
||||||
self.mainMenu.updateMenu()
|
self.mainMenu.updateMenu()
|
||||||
@@ -370,6 +374,16 @@ class GuiMain(QMainWindow):
|
|||||||
self.statusLabels.append(sLabel)
|
self.statusLabels.append(sLabel)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _makeImportIcons(self):
|
||||||
|
self.importIcons = []
|
||||||
|
self.importLabels = []
|
||||||
|
for sLabel, sR, sG, sB in self.theProject.importCols:
|
||||||
|
theIcon = QPixmap(32,32)
|
||||||
|
theIcon.fill(QColor(sR,sG,sB))
|
||||||
|
self.importIcons.append(QIcon(theIcon))
|
||||||
|
self.importLabels.append(sLabel)
|
||||||
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Events
|
# Events
|
||||||
##
|
##
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ class NWProject():
|
|||||||
self.projMeta = None
|
self.projMeta = None
|
||||||
self.projCache = None
|
self.projCache = None
|
||||||
self.projFile = None
|
self.projFile = None
|
||||||
self.statusCols = None
|
|
||||||
|
|
||||||
# Project Meta
|
# Project Meta
|
||||||
self.projName = None
|
self.projName = None
|
||||||
@@ -55,6 +54,8 @@ class NWProject():
|
|||||||
|
|
||||||
# Project Settings
|
# Project Settings
|
||||||
self.spellCheck = False
|
self.spellCheck = False
|
||||||
|
self.statusCols = None
|
||||||
|
self.importCols = None
|
||||||
|
|
||||||
# Set Defaults
|
# Set Defaults
|
||||||
self.clearProject()
|
self.clearProject()
|
||||||
@@ -147,6 +148,12 @@ class NWProject():
|
|||||||
("Draft", 200,150, 0),
|
("Draft", 200,150, 0),
|
||||||
("Finished", 50,200, 0),
|
("Finished", 50,200, 0),
|
||||||
]
|
]
|
||||||
|
self.importCols = [
|
||||||
|
("None", 100,100,100),
|
||||||
|
("Minor", 200, 50, 0),
|
||||||
|
("Major", 200,150, 0),
|
||||||
|
("Main", 50,200, 0),
|
||||||
|
]
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
+12
-1
@@ -3,6 +3,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from os import path, mkdir
|
from os import path, mkdir
|
||||||
|
from itertools import chain
|
||||||
|
|
||||||
def ensureDir(theDir):
|
def ensureDir(theDir):
|
||||||
if not path.isdir(theDir):
|
if not path.isdir(theDir):
|
||||||
@@ -28,7 +29,7 @@ def cmpFiles(fileOne, fileTwo, ignoreLines=[]):
|
|||||||
if n+1 in ignoreLines:
|
if n+1 in ignoreLines:
|
||||||
print("Ignoring line %d" % (n+1))
|
print("Ignoring line %d" % (n+1))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if lnOne != lnTwo:
|
if lnOne != lnTwo:
|
||||||
print("Diff on line %d:" % (n+1))
|
print("Diff on line %d:" % (n+1))
|
||||||
print(" << '%s'" % lnOne)
|
print(" << '%s'" % lnOne)
|
||||||
@@ -39,3 +40,13 @@ def cmpFiles(fileOne, fileTwo, ignoreLines=[]):
|
|||||||
foTwo.close()
|
foTwo.close()
|
||||||
|
|
||||||
return not diffFound
|
return not diffFound
|
||||||
|
|
||||||
|
def cmpList(listOne, listTwo):
|
||||||
|
flatOne = list(chain.from_iterable([listOne]))
|
||||||
|
flatTwo = list(chain.from_iterable([listTwo]))
|
||||||
|
if len(flatOne) != len(flatTwo):
|
||||||
|
return False
|
||||||
|
for i in range(len(flatOne)):
|
||||||
|
if flatOne[i] != flatTwo[i]:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""novelWriter Common Class Tester
|
||||||
|
"""
|
||||||
|
|
||||||
|
import nw
|
||||||
|
from nw.common import *
|
||||||
|
from nwtools import cmpList
|
||||||
|
|
||||||
|
def testCheckString():
|
||||||
|
assert checkString(None, "NotNone",True) is None
|
||||||
|
assert checkString("None","NotNone",True) is None
|
||||||
|
assert checkString("None","NotNone",False) == "None"
|
||||||
|
assert checkString(None, "NotNone",False) == "NotNone"
|
||||||
|
assert checkString(1, "NotNone",False) == "NotNone"
|
||||||
|
assert checkString(1.0, "NotNone",False) == "NotNone"
|
||||||
|
assert checkString(True, "NotNone",False) == "NotNone"
|
||||||
|
|
||||||
|
def testCheckInt():
|
||||||
|
assert checkInt(None, 3,True) is None
|
||||||
|
assert checkInt("None",3,True) is None
|
||||||
|
assert checkInt(None, 3,False) == 3
|
||||||
|
assert checkInt(1, 3,False) == 1
|
||||||
|
assert checkInt(1.0, 3,False) == 1
|
||||||
|
assert checkInt(True, 3,False) == 1
|
||||||
|
|
||||||
|
def testCheckBool():
|
||||||
|
assert checkBool(None, 3, True) is None
|
||||||
|
assert checkBool("None", 3, True) is None
|
||||||
|
assert checkBool("True", False,False) == True
|
||||||
|
assert checkBool("False",True, False) == False
|
||||||
|
assert checkBool("Boo", None, False) is None
|
||||||
|
assert checkBool(0, None, False) == False
|
||||||
|
assert checkBool(1, None, False) == True
|
||||||
|
assert checkBool(2, None, False) is None
|
||||||
|
assert checkBool(0.0, None, False) is None
|
||||||
|
assert checkBool(1.0, None, False) is None
|
||||||
|
assert checkBool(2.0, None, False) is None
|
||||||
|
|
||||||
|
def testColRange():
|
||||||
|
assert colRange([0,0], [0,0], 0) is None
|
||||||
|
assert cmpList(colRange([200,50,0], [50,200,0], 1), [200,50,0])
|
||||||
|
assert cmpList(colRange([200,50,0], [50,200,0], 2), [[200,50,0],[50,200,0]])
|
||||||
|
assert cmpList(colRange([200,50,0], [50,200,0], 3), [[200,50,0],[125,125,0],[50,200,0]])
|
||||||
|
assert cmpList(colRange([200,50,0], [50,200,0], 4), [[200,50,0],[150,100,0],[100,150,0],[50,200,0]])
|
||||||
|
assert cmpList(colRange([200,50,0], [50,200,0], 5), [[200,50,0],[162,87,0],[124,124,0],[86,161,0],[50,200,0]])
|
||||||
Reference in New Issue
Block a user