Merge pull request #695 from vkbo/projsettings_update

Project Settings update
This commit is contained in:
Veronica Berglyd Olsen
2021-02-27 17:37:01 +01:00
committed by GitHub
8 changed files with 355 additions and 287 deletions
+83 -57
View File
@@ -1,74 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="2.0" language="en_US" sourcelanguage="en_GB">
<!DOCTYPE TS>
<TS version="2.1" language="en_US" sourcelanguage="en_GB">
<context>
<name>Common</name>
<message>
<location filename="../nw/common.py" line="270"/>
<location filename="../nw/common.py" line="240"/>
<source>in the future</source>
<translation></translation>
</message>
<message>
<location filename="../nw/common.py" line="274"/>
<location filename="../nw/common.py" line="244"/>
<source>just now</source>
<translation></translation>
</message>
<message>
<location filename="../nw/common.py" line="278"/>
<location filename="../nw/common.py" line="248"/>
<source>a minute ago</source>
<translation></translation>
</message>
<message>
<location filename="../nw/common.py" line="282"/>
<location filename="../nw/common.py" line="252"/>
<source>{0} minutes ago</source>
<translation></translation>
</message>
<message>
<location filename="../nw/common.py" line="286"/>
<location filename="../nw/common.py" line="256"/>
<source>an hour ago</source>
<translation></translation>
</message>
<message>
<location filename="../nw/common.py" line="290"/>
<location filename="../nw/common.py" line="260"/>
<source>{0} hours ago</source>
<translation></translation>
</message>
<message>
<location filename="../nw/common.py" line="294"/>
<location filename="../nw/common.py" line="264"/>
<source>a day ago</source>
<translation></translation>
</message>
<message>
<location filename="../nw/common.py" line="298"/>
<location filename="../nw/common.py" line="268"/>
<source>{0} days ago</source>
<translation></translation>
</message>
<message>
<location filename="../nw/common.py" line="302"/>
<location filename="../nw/common.py" line="272"/>
<source>a week ago</source>
<translation></translation>
</message>
<message>
<location filename="../nw/common.py" line="306"/>
<location filename="../nw/common.py" line="276"/>
<source>{0} weeks ago</source>
<translation></translation>
</message>
<message>
<location filename="../nw/common.py" line="310"/>
<location filename="../nw/common.py" line="280"/>
<source>a month ago</source>
<translation></translation>
</message>
<message>
<location filename="../nw/common.py" line="314"/>
<location filename="../nw/common.py" line="284"/>
<source>{0} months ago</source>
<translation></translation>
</message>
<message>
<location filename="../nw/common.py" line="318"/>
<location filename="../nw/common.py" line="288"/>
<source>a year ago</source>
<translation></translation>
</message>
<message>
<location filename="../nw/common.py" line="322"/>
<location filename="../nw/common.py" line="292"/>
<source>{0} years ago</source>
<translation></translation>
</message>
@@ -3537,57 +3538,57 @@
<context>
<name>GuiProjectEditMain</name>
<message>
<location filename="../nw/gui/projsettings.py" line="169"/>
<location filename="../nw/gui/projsettings.py" line="173"/>
<source>Project Settings</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="178"/>
<location filename="../nw/gui/projsettings.py" line="182"/>
<source>Working title</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="178"/>
<location filename="../nw/gui/projsettings.py" line="182"/>
<source>Should be set only once.</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="188"/>
<location filename="../nw/gui/projsettings.py" line="192"/>
<source>Novel title</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="188"/>
<location filename="../nw/gui/projsettings.py" line="192"/>
<source>Change whenever you want!</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="198"/>
<location filename="../nw/gui/projsettings.py" line="202"/>
<source>Author(s)</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="198"/>
<location filename="../nw/gui/projsettings.py" line="202"/>
<source>One name per line.</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="207"/>
<location filename="../nw/gui/projsettings.py" line="211"/>
<source>Default</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="214"/>
<location filename="../nw/gui/projsettings.py" line="218"/>
<source>Spell check language</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="228"/>
<location filename="../nw/gui/projsettings.py" line="232"/>
<source>Overrides main preferences.</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="228"/>
<location filename="../nw/gui/projsettings.py" line="232"/>
<source>No backup on close</source>
<translation></translation>
</message>
@@ -3595,91 +3596,116 @@
<context>
<name>GuiProjectEditReplace</name>
<message>
<location filename="../nw/gui/projsettings.py" line="455"/>
<location filename="../nw/gui/projsettings.py" line="508"/>
<source>Keyword</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="455"/>
<location filename="../nw/gui/projsettings.py" line="508"/>
<source>Replace With</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="475"/>
<location filename="../nw/gui/projsettings.py" line="547"/>
<source>Save entry</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="476"/>
<location filename="../nw/gui/projsettings.py" line="527"/>
<source>Add new entry</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="477"/>
<location filename="../nw/gui/projsettings.py" line="531"/>
<source>Delete selected entry</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="494"/>
<location filename="../nw/gui/projsettings.py" line="502"/>
<source>Text Replace List for Preview and Export</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="538"/>
<source>Select item to edit</source>
<translation></translation>
</message>
</context>
<context>
<name>GuiProjectEditStatus</name>
<message>
<location filename="../nw/gui/projsettings.py" line="274"/>
<source>New</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="275"/>
<source>Delete</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="276"/>
<location filename="../nw/gui/projsettings.py" line="313"/>
<source>Save</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="279"/>
<location filename="../nw/gui/projsettings.py" line="309"/>
<source>Colour</source>
<translation>Color</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="290"/>
<source>Name</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="300"/>
<location filename="../nw/gui/projsettings.py" line="255"/>
<source>Novel File Status Levels</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="302"/>
<location filename="../nw/gui/projsettings.py" line="259"/>
<source>Note File Importance Levels</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="327"/>
<location filename="../nw/gui/projsettings.py" line="366"/>
<source>Select Colour</source>
<translation>Select Color</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="341"/>
<location filename="../nw/gui/projsettings.py" line="380"/>
<source>New Item</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="357"/>
<source>Cannot delete status item that is in use.</source>
<location filename="../nw/gui/projsettings.py" line="277"/>
<source>Label</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="389"/>
<source>{0} [{1}]</source>
<location filename="../nw/gui/projsettings.py" line="277"/>
<source>Usage</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="292"/>
<source>Add new entry</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="296"/>
<source>Delete selected entry</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="305"/>
<source>Select item to edit</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="397"/>
<source>Cannot delete a status item that is in use.</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="479"/>
<source>Not in use</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="481"/>
<source>Used once</source>
<translation></translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="483"/>
<source>Used by {0} items</source>
<translation></translation>
</message>
</context>
+85 -59
View File
@@ -1,74 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="2.0" language="nb_NO" sourcelanguage="en_GB">
<!DOCTYPE TS>
<TS version="2.1" language="nb_NO" sourcelanguage="en_GB">
<context>
<name>Common</name>
<message>
<location filename="../nw/common.py" line="274"/>
<location filename="../nw/common.py" line="244"/>
<source>just now</source>
<translation> nettopp</translation>
</message>
<message>
<location filename="../nw/common.py" line="278"/>
<location filename="../nw/common.py" line="248"/>
<source>a minute ago</source>
<translation>for et minutt siden</translation>
</message>
<message>
<location filename="../nw/common.py" line="286"/>
<location filename="../nw/common.py" line="256"/>
<source>an hour ago</source>
<translation>for en time siden</translation>
</message>
<message>
<location filename="../nw/common.py" line="294"/>
<location filename="../nw/common.py" line="264"/>
<source>a day ago</source>
<translation>for en dag siden</translation>
</message>
<message>
<location filename="../nw/common.py" line="302"/>
<location filename="../nw/common.py" line="272"/>
<source>a week ago</source>
<translation>for en uke siden</translation>
</message>
<message>
<location filename="../nw/common.py" line="310"/>
<location filename="../nw/common.py" line="280"/>
<source>a month ago</source>
<translation>for en måned siden</translation>
</message>
<message>
<location filename="../nw/common.py" line="318"/>
<location filename="../nw/common.py" line="288"/>
<source>a year ago</source>
<translation>for et år siden</translation>
</message>
<message>
<location filename="../nw/common.py" line="282"/>
<location filename="../nw/common.py" line="252"/>
<source>{0} minutes ago</source>
<translation>for {0} minutter siden</translation>
</message>
<message>
<location filename="../nw/common.py" line="290"/>
<location filename="../nw/common.py" line="260"/>
<source>{0} hours ago</source>
<translation>for {0} timer siden</translation>
</message>
<message>
<location filename="../nw/common.py" line="298"/>
<location filename="../nw/common.py" line="268"/>
<source>{0} days ago</source>
<translation>for {0} dager siden</translation>
</message>
<message>
<location filename="../nw/common.py" line="306"/>
<location filename="../nw/common.py" line="276"/>
<source>{0} weeks ago</source>
<translation>for {0} uker siden</translation>
</message>
<message>
<location filename="../nw/common.py" line="314"/>
<location filename="../nw/common.py" line="284"/>
<source>{0} months ago</source>
<translation>for {0} måneder siden</translation>
</message>
<message>
<location filename="../nw/common.py" line="322"/>
<location filename="../nw/common.py" line="292"/>
<source>{0} years ago</source>
<translation>for {0} år siden</translation>
</message>
<message>
<location filename="../nw/common.py" line="270"/>
<location filename="../nw/common.py" line="240"/>
<source>in the future</source>
<translation>i fremtiden</translation>
</message>
@@ -3537,57 +3538,57 @@
<context>
<name>GuiProjectEditMain</name>
<message>
<location filename="../nw/gui/projsettings.py" line="169"/>
<location filename="../nw/gui/projsettings.py" line="173"/>
<source>Project Settings</source>
<translation>Prosjektinnstillinger</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="178"/>
<location filename="../nw/gui/projsettings.py" line="182"/>
<source>Working title</source>
<translation>Arbeidstittel</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="178"/>
<location filename="../nw/gui/projsettings.py" line="182"/>
<source>Should be set only once.</source>
<translation>Bør bare settes én gang.</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="188"/>
<location filename="../nw/gui/projsettings.py" line="192"/>
<source>Novel title</source>
<translation>Bokens tittel</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="188"/>
<location filename="../nw/gui/projsettings.py" line="192"/>
<source>Change whenever you want!</source>
<translation>Kan endres når som helst!</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="198"/>
<location filename="../nw/gui/projsettings.py" line="202"/>
<source>Author(s)</source>
<translation>Forfatter(e)</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="198"/>
<location filename="../nw/gui/projsettings.py" line="202"/>
<source>One name per line.</source>
<translation>Ett navn per linje.</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="207"/>
<location filename="../nw/gui/projsettings.py" line="211"/>
<source>Default</source>
<translation>Ingen valg</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="214"/>
<location filename="../nw/gui/projsettings.py" line="218"/>
<source>Spell check language</source>
<translation>Språk for stavekontroll</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="228"/>
<location filename="../nw/gui/projsettings.py" line="232"/>
<source>Overrides main preferences.</source>
<translation>Overstyrer valg i innstillinger.</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="228"/>
<location filename="../nw/gui/projsettings.py" line="232"/>
<source>No backup on close</source>
<translation>Slå av sikkerhetskopi</translation>
</message>
@@ -3595,92 +3596,117 @@
<context>
<name>GuiProjectEditReplace</name>
<message>
<location filename="../nw/gui/projsettings.py" line="455"/>
<location filename="../nw/gui/projsettings.py" line="508"/>
<source>Keyword</source>
<translation>Kodeord</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="455"/>
<location filename="../nw/gui/projsettings.py" line="508"/>
<source>Replace With</source>
<translation>Erstatt med</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="475"/>
<location filename="../nw/gui/projsettings.py" line="547"/>
<source>Save entry</source>
<translation>Lagre tekst</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="476"/>
<location filename="../nw/gui/projsettings.py" line="527"/>
<source>Add new entry</source>
<translation>Legg til ny</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="477"/>
<location filename="../nw/gui/projsettings.py" line="531"/>
<source>Delete selected entry</source>
<translation>Slett valgte element</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="494"/>
<location filename="../nw/gui/projsettings.py" line="502"/>
<source>Text Replace List for Preview and Export</source>
<translation>Erstatningsliste for forhåndsvisning og eksport</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="538"/>
<source>Select item to edit</source>
<translation>Velg enhet å redigere</translation>
</message>
</context>
<context>
<name>GuiProjectEditStatus</name>
<message>
<location filename="../nw/gui/projsettings.py" line="274"/>
<source>New</source>
<translation>Ny</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="275"/>
<source>Delete</source>
<translation>Slett</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="276"/>
<location filename="../nw/gui/projsettings.py" line="313"/>
<source>Save</source>
<translation>Lagre</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="279"/>
<location filename="../nw/gui/projsettings.py" line="309"/>
<source>Colour</source>
<translation>Farge</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="290"/>
<source>Name</source>
<translation>Navn</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="300"/>
<location filename="../nw/gui/projsettings.py" line="255"/>
<source>Novel File Status Levels</source>
<translation>Statusnivåer i roman-filer</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="302"/>
<location filename="../nw/gui/projsettings.py" line="259"/>
<source>Note File Importance Levels</source>
<translation>Viktighetsnivåer i notatfiler</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="327"/>
<location filename="../nw/gui/projsettings.py" line="366"/>
<source>Select Colour</source>
<translation>Velg farge</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="341"/>
<location filename="../nw/gui/projsettings.py" line="380"/>
<source>New Item</source>
<translation>Legg til</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="357"/>
<source>Cannot delete status item that is in use.</source>
<translation>Kan ikke slette statusnivåer som er i bruk.</translation>
<location filename="../nw/gui/projsettings.py" line="277"/>
<source>Label</source>
<translation>Navn</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="389"/>
<source>{0} [{1}]</source>
<translation></translation>
<location filename="../nw/gui/projsettings.py" line="277"/>
<source>Usage</source>
<translation>Bruk</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="292"/>
<source>Add new entry</source>
<translation>Legg til ny</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="296"/>
<source>Delete selected entry</source>
<translation>Slett valgte element</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="305"/>
<source>Select item to edit</source>
<translation>Velg enhet å redigere</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="397"/>
<source>Cannot delete a status item that is in use.</source>
<translation>Kan ikke slette status som er i bruk.</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="479"/>
<source>Not in use</source>
<translation>Ikke i bruk</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="481"/>
<source>Used once</source>
<translation>Brukt ett sted</translation>
</message>
<message>
<location filename="../nw/gui/projsettings.py" line="483"/>
<source>Used by {0} items</source>
<translation>Brukt {0} steder</translation>
</message>
</context>
<context>
-30
View File
@@ -150,36 +150,6 @@ def hexToInt(value, default=0):
return default
return default
def colRange(rgbStart, rgbEnd, nStep):
"""Generate a range of colours from one RGB value to another.
"""
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)
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
return retCol
def formatInt(theInt):
"""Formats an integer with k, M, G etc.
"""
+2
View File
@@ -91,6 +91,8 @@ class OptionState():
"winWidth",
"winHeight",
"replaceColW",
"statusColW",
"importColW",
},
"GuiProjectDetails": {
"winWidth",
+166 -83
View File
@@ -31,8 +31,8 @@ from PyQt5.QtCore import Qt, QLocale
from PyQt5.QtGui import QIcon, QPixmap, QColor, QBrush
from PyQt5.QtWidgets import (
QHBoxLayout, QVBoxLayout, QLineEdit, QPlainTextEdit, QLabel, QWidget,
QDialogButtonBox, QListWidget, QPushButton, QListWidgetItem, QColorDialog,
QAbstractItemView, QTreeWidget, QTreeWidgetItem, QComboBox
QDialogButtonBox, QPushButton, QColorDialog, QTreeWidget, QTreeWidgetItem,
QComboBox
)
from nw.constants import nwAlert
@@ -143,10 +143,14 @@ class GuiProjectSettings(PagedDialog):
winWidth = self.mainConf.rpxInt(self.width())
winHeight = self.mainConf.rpxInt(self.height())
replaceColW = self.mainConf.rpxInt(self.tabReplace.listBox.columnWidth(0))
statusColW = self.mainConf.rpxInt(self.tabStatus.listBox.columnWidth(0))
importColW = self.mainConf.rpxInt(self.tabImport.listBox.columnWidth(0))
self.optState.setValue("GuiProjectSettings", "winWidth", winWidth)
self.optState.setValue("GuiProjectSettings", "winHeight", winHeight)
self.optState.setValue("GuiProjectSettings", "replaceColW", replaceColW)
self.optState.setValue("GuiProjectSettings", "statusColW", statusColW)
self.optState.setValue("GuiProjectSettings", "importColW", importColW)
return
@@ -169,7 +173,7 @@ class GuiProjectEditMain(QWidget):
self.mainForm.addGroupLabel(self.tr("Project Settings"))
xW = self.mainConf.pxInt(250)
xH = self.mainConf.pxInt(80)
xH = round(4.8*self.theParent.theTheme.fontPixelSize)
self.editName = QLineEdit()
self.editName.setMaxLength(200)
@@ -192,7 +196,7 @@ class GuiProjectEditMain(QWidget):
)
self.editAuthors = QPlainTextEdit()
self.editAuthors.setMinimumHeight(xH)
self.editAuthors.setMaximumHeight(xH)
self.editAuthors.setMaximumWidth(xW)
self.editAuthors.setPlainText("\n".join(self.theProject.bookAuthors))
self.mainForm.addRow(
@@ -237,17 +241,30 @@ class GuiProjectEditMain(QWidget):
class GuiProjectEditStatus(QWidget):
COL_LABEL = 0
COL_USAGE = 1
def __init__(self, theParent, theProject, isStatus):
QWidget.__init__(self, theParent)
self.mainConf = nw.CONFIG
self.theParent = theParent
self.theProject = theProject
self.optState = theProject.optState
self.theTheme = theParent.theTheme
if isStatus:
self.theStatus = self.theProject.statusItems
pageLabel = self.tr("Novel File Status Levels")
colSetting = "statusColW"
else:
self.theStatus = self.theProject.importItems
pageLabel = self.tr("Note File Importance Levels")
colSetting = "importColW"
wCol0 = self.mainConf.pxInt(
self.optState.getInt("GuiProjectSettings", colSetting, 130)
)
self.colData = []
self.colCounts = []
@@ -256,64 +273,89 @@ class GuiProjectEditStatus(QWidget):
self.iPx = self.theTheme.baseIconSize
self.outerBox = QVBoxLayout()
self.mainBox = QHBoxLayout()
self.mainForm = QVBoxLayout()
# The List
# ========
self.listBox = QListWidget()
self.listBox.setDragDropMode(QAbstractItemView.InternalMove)
self.listBox = QTreeWidget()
self.listBox.setHeaderLabels([
self.tr("Label"),
self.tr("Usage"),
])
self.listBox.itemSelectionChanged.connect(self._selectedItem)
self.listBox.model().rowsMoved.connect(self._rowsMoved)
self.listBox.setColumnWidth(self.COL_LABEL, wCol0)
self.listBox.setIndentation(0)
for iName, iCol, nUse in self.theStatus:
self._addItem(iName, iCol, iName, nUse)
# List Controls
# =============
self.addButton = QPushButton(self.theTheme.getIcon("add"), "")
self.addButton.setToolTip(self.tr("Add new entry"))
self.addButton.clicked.connect(self._newItem)
self.delButton = QPushButton(self.theTheme.getIcon("remove"), "")
self.delButton.setToolTip(self.tr("Delete selected entry"))
self.delButton.clicked.connect(self._delItem)
# Edit Form
# =========
self.editName = QLineEdit()
self.editName.setMaxLength(40)
self.editName.setEnabled(False)
self.newButton = QPushButton(self.tr("New"))
self.delButton = QPushButton(self.tr("Delete"))
self.saveButton = QPushButton(self.tr("Save"))
self.colPixmap = QPixmap(self.iPx, self.iPx)
self.colPixmap.fill(QColor(120, 120, 120))
self.colButton = QPushButton(QIcon(self.colPixmap), self.tr("Colour"))
self.colButton.setIconSize(self.colPixmap.rect().size())
self.editName.setPlaceholderText(self.tr("Select item to edit"))
self.newButton.clicked.connect(self._newItem)
self.delButton.clicked.connect(self._delItem)
self.saveButton.clicked.connect(self._saveItem)
self.colPixmap = QPixmap(self.iPx, self.iPx)
self.colPixmap.fill(QColor(120, 120, 120))
self.colButton = QPushButton(QIcon(self.colPixmap), self.tr("Colour"))
self.colButton.setIconSize(self.colPixmap.rect().size())
self.colButton.clicked.connect(self._selectColour)
self.mainForm.addWidget(self.newButton)
self.mainForm.addWidget(self.delButton)
self.mainForm.addStretch(1)
self.mainForm.addWidget(QLabel("<b>%s</b>" % self.tr("Name")))
self.mainForm.addWidget(self.editName)
self.mainForm.addWidget(self.colButton)
self.mainForm.addStretch(1)
self.mainForm.addWidget(self.saveButton)
self.saveButton = QPushButton(self.tr("Save"))
self.saveButton.clicked.connect(self._saveItem)
# Assemble
# ========
self.listControls = QVBoxLayout()
self.listControls.addWidget(self.addButton)
self.listControls.addWidget(self.delButton)
self.listControls.addStretch(1)
self.editBox = QHBoxLayout()
self.editBox.addWidget(self.editName)
self.editBox.addWidget(self.colButton)
self.editBox.addWidget(self.saveButton)
self.mainBox = QVBoxLayout()
self.mainBox.addWidget(self.listBox)
self.mainBox.addLayout(self.mainForm)
self.mainBox.addLayout(self.editBox)
if isStatus:
self.outerBox.addWidget(QLabel("<b>%s</b>" % self.tr("Novel File Status Levels")))
else:
self.outerBox.addWidget(QLabel("<b>%s</b>" % self.tr("Note File Importance Levels")))
self.outerBox.addLayout(self.mainBox)
self.innerBox = QHBoxLayout()
self.innerBox.addLayout(self.mainBox)
self.innerBox.addLayout(self.listControls)
self.outerBox = QVBoxLayout()
self.outerBox.addWidget(QLabel("<b>%s</b>" % pageLabel))
self.outerBox.addLayout(self.innerBox)
self.setLayout(self.outerBox)
return
def getNewList(self):
"""Return list of entries.
"""
if self.colChanged:
newList = []
for n in range(self.listBox.count()):
nItem = self.listBox.item(n)
nIdx = nItem.data(Qt.UserRole)
for n in range(self.listBox.topLevelItemCount()):
nItem = self.listBox.topLevelItem(n)
nIdx = nItem.data(self.COL_LABEL, Qt.UserRole)
newList.append(self.colData[nIdx])
return newList
return None
##
@@ -339,7 +381,8 @@ class GuiProjectEditStatus(QWidget):
"""Create a new status item.
"""
newItem = self._addItem(self.tr("New Item"), (0, 0, 0), None, 0)
newItem.setBackground(QBrush(QColor(0, 255, 0, 80)))
newItem.setBackground(self.COL_LABEL, QBrush(QColor(0, 255, 0, 70)))
newItem.setBackground(self.COL_USAGE, QBrush(QColor(0, 255, 0, 70)))
self.colChanged = True
return
@@ -348,14 +391,14 @@ class GuiProjectEditStatus(QWidget):
"""
selItem = self._getSelectedItem()
if selItem is not None:
iRow = self.listBox.row(selItem)
selIdx = selItem.data(Qt.UserRole)
iRow = self.listBox.indexOfTopLevelItem(selItem)
selIdx = selItem.data(self.COL_LABEL, Qt.UserRole)
if self.colCounts[selIdx] == 0:
self.listBox.takeItem(iRow)
self.listBox.takeTopLevelItem(iRow)
self.colChanged = True
else:
self.theParent.makeAlert(
self.tr("Cannot delete status item that is in use."), nwAlert.ERROR
self.tr("Cannot delete a status item that is in use."), nwAlert.ERROR
)
return
@@ -364,7 +407,7 @@ class GuiProjectEditStatus(QWidget):
"""
selItem = self._getSelectedItem()
if selItem is not None:
selIdx = selItem.data(Qt.UserRole)
selIdx = selItem.data(self.COL_LABEL, Qt.UserRole)
self.colData[selIdx] = (
self.editName.text().strip(),
self.selColour.red(),
@@ -372,12 +415,12 @@ class GuiProjectEditStatus(QWidget):
self.selColour.blue(),
self.colData[selIdx][4]
)
selItem.setText(self.tr("{0} [{1}]").format(
self.colData[selIdx][0], self.colCounts[selIdx])
)
selItem.setIcon(self.colButton.icon())
selItem.setText(self.COL_LABEL, self.colData[selIdx][0])
selItem.setText(self.COL_USAGE, self._usageString(self.colCounts[selIdx]))
selItem.setIcon(self.COL_LABEL, self.colButton.icon())
self.editName.setEnabled(False)
self.colChanged = True
return
def _addItem(self, iName, iCol, oName, nUse):
@@ -385,11 +428,12 @@ class GuiProjectEditStatus(QWidget):
"""
newIcon = QPixmap(self.iPx, self.iPx)
newIcon.fill(QColor(*iCol))
newItem = QListWidgetItem()
newItem.setText(self.tr("{0} [{1}]").format(iName, nUse))
newItem.setIcon(QIcon(newIcon))
newItem.setData(Qt.UserRole, len(self.colData))
self.listBox.addItem(newItem)
newItem = QTreeWidgetItem()
newItem.setText(self.COL_LABEL, iName)
newItem.setText(self.COL_USAGE, self._usageString(nUse))
newItem.setIcon(self.COL_LABEL, QIcon(newIcon))
newItem.setData(self.COL_LABEL, Qt.UserRole, len(self.colData))
self.listBox.addTopLevelItem(newItem)
self.colData.append((iName, iCol[0], iCol[1], iCol[2], oName))
self.colCounts.append(nUse)
return newItem
@@ -400,7 +444,7 @@ class GuiProjectEditStatus(QWidget):
"""
selItem = self._getSelectedItem()
if selItem is not None:
selIdx = selItem.data(Qt.UserRole)
selIdx = selItem.data(self.COL_LABEL, Qt.UserRole)
selVal = self.colData[selIdx]
self.selColour = QColor(selVal[1], selVal[2], selVal[3])
newIcon = QPixmap(self.iPx, self.iPx)
@@ -410,6 +454,7 @@ class GuiProjectEditStatus(QWidget):
self.editName.setEnabled(True)
self.editName.selectAll()
self.editName.setFocus()
return
##
@@ -425,16 +470,28 @@ class GuiProjectEditStatus(QWidget):
return None
def _rowsMoved(self):
"""A row has been moved, so sett the changed flag.
"""A row has been moved, so set the changed flag.
"""
logger.verbose("A drag move event occurred")
self.colChanged = True
return
def _usageString(self, nUse):
"""Generate usage string.
"""
if nUse == 0:
return self.tr("Not in use")
elif nUse == 1:
return self.tr("Used once")
else:
return self.tr("Used by {0} items").format(nUse)
# END Class GuiProjectEditStatus
class GuiProjectEditReplace(QWidget):
COL_KEY = 0
COL_REPL = 1
def __init__(self, theParent, theProject):
QWidget.__init__(self, theParent)
@@ -445,57 +502,82 @@ class GuiProjectEditReplace(QWidget):
self.optState = theProject.optState
self.arChanged = False
self.outerBox = QVBoxLayout()
self.bottomBox = QHBoxLayout()
wCol0 = self.mainConf.pxInt(
self.optState.getInt("GuiProjectSettings", "replaceColW", 100)
self.optState.getInt("GuiProjectSettings", "replaceColW", 130)
)
pageLabel = self.tr("Text Replace List for Preview and Export")
# List Box
# ========
self.listBox = QTreeWidget()
self.listBox.setHeaderLabels([
self.tr("Keyword"),
self.tr("Replace With"),
])
self.listBox.itemSelectionChanged.connect(self._selectedItem)
self.listBox.setColumnWidth(0, wCol0)
self.listBox.setColumnWidth(self.COL_KEY, wCol0)
self.listBox.setIndentation(0)
for aKey, aVal in self.theProject.autoReplace.items():
newItem = QTreeWidgetItem(["<%s>" % aKey, aVal])
self.listBox.addTopLevelItem(newItem)
self.listBox.sortByColumn(0, Qt.AscendingOrder)
self.listBox.sortByColumn(self.COL_KEY, Qt.AscendingOrder)
self.listBox.setSortingEnabled(True)
self.editKey = QLineEdit()
self.editValue = QLineEdit()
self.saveButton = QPushButton(self.theTheme.getIcon("done"), "")
self.addButton = QPushButton(self.theTheme.getIcon("add"), "")
self.delButton = QPushButton(self.theTheme.getIcon("remove"), "")
self.saveButton.setToolTip(self.tr("Save entry"))
self.addButton.setToolTip(self.tr("Add new entry"))
self.delButton.setToolTip(self.tr("Delete selected entry"))
# List Controls
# =============
self.addButton = QPushButton(self.theTheme.getIcon("add"), "")
self.addButton.setToolTip(self.tr("Add new entry"))
self.addButton.clicked.connect(self._addEntry)
self.delButton = QPushButton(self.theTheme.getIcon("remove"), "")
self.delButton.setToolTip(self.tr("Delete selected entry"))
self.delButton.clicked.connect(self._delEntry)
# Edit Form
# =========
self.editKey = QLineEdit()
self.editKey.setPlaceholderText(self.tr("Select item to edit"))
self.editKey.setEnabled(False)
self.editKey.setMaxLength(40)
self.editValue = QLineEdit()
self.editValue.setEnabled(False)
self.editValue.setMaxLength(80)
self.saveButton = QPushButton("Save")
self.saveButton.setToolTip(self.tr("Save entry"))
self.saveButton.clicked.connect(self._saveEntry)
self.addButton.clicked.connect(self._addEntry)
self.delButton.clicked.connect(self._delEntry)
self.bottomBox.addWidget(self.editKey, 2)
self.bottomBox.addWidget(self.editValue, 3)
self.bottomBox.addWidget(self.saveButton)
self.bottomBox.addWidget(self.addButton)
self.bottomBox.addWidget(self.delButton)
# Assemble
# ========
self.listControls = QVBoxLayout()
self.listControls.addWidget(self.addButton)
self.listControls.addWidget(self.delButton)
self.listControls.addStretch(1)
self.editBox = QHBoxLayout()
self.editBox.addWidget(self.editKey, 4)
self.editBox.addWidget(self.editValue, 5)
self.editBox.addWidget(self.saveButton, 0)
self.mainBox = QVBoxLayout()
self.mainBox.addWidget(self.listBox)
self.mainBox.addLayout(self.editBox)
self.innerBox = QHBoxLayout()
self.innerBox.addLayout(self.mainBox)
self.innerBox.addLayout(self.listControls)
self.outerBox = QVBoxLayout()
self.outerBox.addWidget(QLabel("<b>%s</b>" % pageLabel))
self.outerBox.addLayout(self.innerBox)
self.outerBox.addWidget(
QLabel("<b>%s</b>" % self.tr("Text Replace List for Preview and Export"))
)
self.outerBox.addWidget(self.listBox)
self.outerBox.addLayout(self.bottomBox)
self.setLayout(self.outerBox)
return
@@ -510,6 +592,7 @@ class GuiProjectEditReplace(QWidget):
aVal = tItem.text(1)
if len(aKey) > 0:
newList[aKey] = aVal
return newList
##
@@ -545,8 +628,8 @@ class GuiProjectEditReplace(QWidget):
saveKey = self._stripNotAllowed(newKey)
if len(saveKey) > 0 and len(newVal) > 0:
selItem.setText(0, "<%s>" % saveKey)
selItem.setText(1, newVal)
selItem.setText(self.COL_KEY, "<%s>" % saveKey)
selItem.setText(self.COL_REPL, newVal)
self.editKey.clear()
self.editValue.clear()
self.editKey.setEnabled(False)
+1 -30
View File
@@ -24,12 +24,11 @@ import time
import pytest
from nw.common import (
checkString, checkBool, checkInt, colRange, formatInt, transferCase,
checkString, checkBool, checkInt, formatInt, transferCase,
fuzzyTime, checkHandle, formatTimeStamp, formatTime, hexToInt,
makeFileNameSafe, isHandle, isTitleTag, isItemClass, isItemType,
isItemLayout, numberToRoman
)
from tools import cmpList
@pytest.mark.base
def testBaseCommon_CheckString():
@@ -191,34 +190,6 @@ def testBaseCommon_HexToInt():
# END Test testBaseCommon_HexToInt
@pytest.mark.base
def testBaseCommon_ColRange():
"""Test the colRange function.
"""
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]]
)
# END Test testBaseCommon_ColRange
@pytest.mark.base
def testBaseCommon_FormatTimeStamp():
"""Test the formatTimeStamp function.
+18 -14
View File
@@ -29,7 +29,7 @@ from tools import cmpFiles, getGuiItem
from PyQt5.QtGui import QColor
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (
QDialog, QAction, QMessageBox, QColorDialog, QListWidgetItem
QDialog, QAction, QMessageBox, QColorDialog, QTreeWidgetItem
)
from nw.gui import GuiProjectSettings
@@ -110,7 +110,7 @@ def testGuiProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDi
assert projEdit.tabStatus.colChanged is False
assert projEdit.tabStatus.getNewList() is None
assert projEdit.tabStatus.listBox.count() == 4
assert projEdit.tabStatus.listBox.topLevelItemCount() == 4
# Fake drag'n'drop should change changed status
projEdit.tabStatus._rowsMoved()
@@ -119,30 +119,32 @@ def testGuiProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDi
projEdit.tabStatus.listBox.clearSelection()
assert projEdit.tabStatus._getSelectedItem() is None
projEdit.tabStatus.listBox.item(0).setSelected(True)
assert isinstance(projEdit.tabStatus._getSelectedItem(), QListWidgetItem)
projEdit.tabStatus.listBox.topLevelItem(0).setSelected(True)
assert isinstance(projEdit.tabStatus._getSelectedItem(), QTreeWidgetItem)
# Can't delete the first item (it's in use)
projEdit.tabStatus.listBox.item(0).setSelected(True)
projEdit.tabStatus.listBox.clearSelection()
projEdit.tabStatus.listBox.topLevelItem(0).setSelected(True)
qtbot.mouseClick(projEdit.tabStatus.delButton, Qt.LeftButton)
assert projEdit.tabStatus.listBox.count() == 4
assert projEdit.tabStatus.listBox.topLevelItemCount() == 4
# Can delete the third item
projEdit.tabStatus.listBox.item(2).setSelected(True)
projEdit.tabStatus.listBox.clearSelection()
projEdit.tabStatus.listBox.topLevelItem(2).setSelected(True)
qtbot.mouseClick(projEdit.tabStatus.delButton, Qt.LeftButton)
assert projEdit.tabStatus.listBox.count() == 3
assert projEdit.tabStatus.listBox.topLevelItemCount() == 3
# Add a new item
monkeypatch.setattr(QColorDialog, "getColor", lambda *args: QColor(20, 30, 40))
qtbot.mouseClick(projEdit.tabStatus.newButton, Qt.LeftButton)
projEdit.tabStatus.listBox.item(3).setSelected(True)
qtbot.mouseClick(projEdit.tabStatus.addButton, Qt.LeftButton)
projEdit.tabStatus.listBox.topLevelItem(3).setSelected(True)
for n in range(8):
qtbot.keyClick(projEdit.tabStatus.editName, Qt.Key_Backspace, delay=typeDelay)
for c in "Final":
qtbot.keyClick(projEdit.tabStatus.editName, c, delay=typeDelay)
qtbot.mouseClick(projEdit.tabStatus.colButton, Qt.LeftButton)
qtbot.mouseClick(projEdit.tabStatus.saveButton, Qt.LeftButton)
assert projEdit.tabStatus.listBox.count() == 4
assert projEdit.tabStatus.listBox.topLevelItemCount() == 4
qtbot.wait(stepDelay)
assert projEdit.tabStatus.colChanged is True
@@ -157,10 +159,12 @@ def testGuiProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDi
# ==============
projEdit._tabBox.setCurrentWidget(projEdit.tabImport)
projEdit.tabImport.listBox.item(3).setSelected(True)
projEdit.tabStatus.listBox.clearSelection()
projEdit.tabImport.listBox.topLevelItem(3).setSelected(True)
qtbot.mouseClick(projEdit.tabImport.delButton, Qt.LeftButton)
qtbot.mouseClick(projEdit.tabImport.newButton, Qt.LeftButton)
projEdit.tabImport.listBox.item(3).setSelected(True)
qtbot.mouseClick(projEdit.tabImport.addButton, Qt.LeftButton)
projEdit.tabStatus.listBox.clearSelection()
projEdit.tabImport.listBox.topLevelItem(3).setSelected(True)
for n in range(8):
qtbot.keyClick(projEdit.tabImport.editName, Qt.Key_Backspace, delay=typeDelay)
for c in "Final":
-14
View File
@@ -23,8 +23,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import shutil
from itertools import chain
from PyQt5.QtWidgets import qApp
def cmpFiles(fileOne, fileTwo, ignoreLines=None):
@@ -72,18 +70,6 @@ def cmpFiles(fileOne, fileTwo, ignoreLines=None):
return not diffFound
def cmpList(listOne, listTwo):
"""Compare two iterable objects.
"""
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
def getGuiItem(theName):
"""Returns a QtWidget based on its objectName.
"""