Make the Importance and Status tabs look consistent with Auto-Replace

This commit is contained in:
Veronica K. B. Olsen
2021-02-27 16:49:54 +01:00
parent 4136328a36
commit bfa8f97e7e
4 changed files with 90 additions and 64 deletions
+2
View File
@@ -91,6 +91,8 @@ class OptionState():
"winWidth", "winWidth",
"winHeight", "winHeight",
"replaceColW", "replaceColW",
"statusColW",
"importColW",
}, },
"GuiProjectDetails": { "GuiProjectDetails": {
"winWidth", "winWidth",
+88 -51
View File
@@ -31,8 +31,8 @@ from PyQt5.QtCore import Qt, QLocale
from PyQt5.QtGui import QIcon, QPixmap, QColor, QBrush from PyQt5.QtGui import QIcon, QPixmap, QColor, QBrush
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QHBoxLayout, QVBoxLayout, QLineEdit, QPlainTextEdit, QLabel, QWidget, QHBoxLayout, QVBoxLayout, QLineEdit, QPlainTextEdit, QLabel, QWidget,
QDialogButtonBox, QListWidget, QPushButton, QListWidgetItem, QColorDialog, QDialogButtonBox, QPushButton, QColorDialog, QTreeWidget, QTreeWidgetItem,
QAbstractItemView, QTreeWidget, QTreeWidgetItem, QComboBox QComboBox
) )
from nw.constants import nwAlert from nw.constants import nwAlert
@@ -143,10 +143,14 @@ class GuiProjectSettings(PagedDialog):
winWidth = self.mainConf.rpxInt(self.width()) winWidth = self.mainConf.rpxInt(self.width())
winHeight = self.mainConf.rpxInt(self.height()) winHeight = self.mainConf.rpxInt(self.height())
replaceColW = self.mainConf.rpxInt(self.tabReplace.listBox.columnWidth(0)) 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", "winWidth", winWidth)
self.optState.setValue("GuiProjectSettings", "winHeight", winHeight) self.optState.setValue("GuiProjectSettings", "winHeight", winHeight)
self.optState.setValue("GuiProjectSettings", "replaceColW", replaceColW) self.optState.setValue("GuiProjectSettings", "replaceColW", replaceColW)
self.optState.setValue("GuiProjectSettings", "statusColW", statusColW)
self.optState.setValue("GuiProjectSettings", "importColW", importColW)
return return
@@ -243,14 +247,21 @@ class GuiProjectEditStatus(QWidget):
self.mainConf = nw.CONFIG self.mainConf = nw.CONFIG
self.theParent = theParent self.theParent = theParent
self.theProject = theProject self.theProject = theProject
self.optState = theProject.optState
self.theTheme = theParent.theTheme self.theTheme = theParent.theTheme
if isStatus: if isStatus:
self.theStatus = self.theProject.statusItems self.theStatus = self.theProject.statusItems
pageLabel = self.tr("Novel File Status Levels") pageLabel = self.tr("Novel File Status Levels")
colSetting = "statusColW"
else: else:
self.theStatus = self.theProject.importItems self.theStatus = self.theProject.importItems
pageLabel = self.tr("Note File Importance Levels") pageLabel = self.tr("Note File Importance Levels")
colSetting = "importColW"
wCol0 = self.mainConf.pxInt(
self.optState.getInt("GuiProjectSettings", colSetting, 130)
)
self.colData = [] self.colData = []
self.colCounts = [] self.colCounts = []
@@ -262,23 +273,32 @@ class GuiProjectEditStatus(QWidget):
# The List # The List
# ======== # ========
self.listBox = QListWidget() self.listBox = QTreeWidget()
self.listBox.setDragDropMode(QAbstractItemView.InternalMove) self.listBox.setHeaderLabels([
self.tr("Label"),
self.tr("Usage"),
])
self.listBox.itemSelectionChanged.connect(self._selectedItem) self.listBox.itemSelectionChanged.connect(self._selectedItem)
self.listBox.model().rowsMoved.connect(self._rowsMoved) self.listBox.setColumnWidth(0, wCol0)
self.listBox.setIndentation(0)
for iName, iCol, nUse in self.theStatus: for iName, iCol, nUse in self.theStatus:
self._addItem(iName, iCol, iName, nUse) self._addItem(iName, iCol, iName, nUse)
# The Controls # List Controls
# ============ # =============
self.newButton = QPushButton(self.tr("New")) self.addButton = QPushButton(self.theTheme.getIcon("add"), "")
self.newButton.clicked.connect(self._newItem) self.addButton.setToolTip(self.tr("Add new entry"))
self.addButton.clicked.connect(self._newItem)
self.delButton = QPushButton(self.tr("Delete")) self.delButton = QPushButton(self.theTheme.getIcon("remove"), "")
self.delButton.setToolTip(self.tr("Delete selected entry"))
self.delButton.clicked.connect(self._delItem) self.delButton.clicked.connect(self._delItem)
# Edit Form
# =========
self.editName = QLineEdit() self.editName = QLineEdit()
self.editName.setMaxLength(40) self.editName.setMaxLength(40)
self.editName.setEnabled(False) self.editName.setEnabled(False)
@@ -296,23 +316,27 @@ class GuiProjectEditStatus(QWidget):
# Assemble # Assemble
# ======== # ========
self.mainForm = QVBoxLayout() self.listControls = QVBoxLayout()
self.mainForm.addWidget(self.newButton) self.listControls.addWidget(self.addButton)
self.mainForm.addWidget(self.delButton) self.listControls.addWidget(self.delButton)
self.mainForm.addStretch(1) self.listControls.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.mainBox = QHBoxLayout() 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.addWidget(self.listBox)
self.mainBox.addLayout(self.mainForm) self.mainBox.addLayout(self.editBox)
self.innerBox = QHBoxLayout()
self.innerBox.addLayout(self.mainBox)
self.innerBox.addLayout(self.listControls)
self.outerBox = QVBoxLayout() self.outerBox = QVBoxLayout()
self.outerBox.addWidget(QLabel("<b>%s</b>" % pageLabel)) self.outerBox.addWidget(QLabel("<b>%s</b>" % pageLabel))
self.outerBox.addLayout(self.mainBox) self.outerBox.addLayout(self.innerBox)
self.setLayout(self.outerBox) self.setLayout(self.outerBox)
@@ -323,9 +347,9 @@ class GuiProjectEditStatus(QWidget):
""" """
if self.colChanged: if self.colChanged:
newList = [] newList = []
for n in range(self.listBox.count()): for n in range(self.listBox.topLevelItemCount()):
nItem = self.listBox.item(n) nItem = self.listBox.topLevelItem(n)
nIdx = nItem.data(Qt.UserRole) nIdx = nItem.data(0, Qt.UserRole)
newList.append(self.colData[nIdx]) newList.append(self.colData[nIdx])
return newList return newList
@@ -354,7 +378,8 @@ class GuiProjectEditStatus(QWidget):
"""Create a new status item. """Create a new status item.
""" """
newItem = self._addItem(self.tr("New Item"), (0, 0, 0), None, 0) newItem = self._addItem(self.tr("New Item"), (0, 0, 0), None, 0)
newItem.setBackground(QBrush(QColor(0, 255, 0, 80))) newItem.setBackground(0, QBrush(QColor(0, 255, 0, 70)))
newItem.setBackground(1, QBrush(QColor(0, 255, 0, 70)))
self.colChanged = True self.colChanged = True
return return
@@ -363,8 +388,8 @@ class GuiProjectEditStatus(QWidget):
""" """
selItem = self._getSelectedItem() selItem = self._getSelectedItem()
if selItem is not None: if selItem is not None:
iRow = self.listBox.row(selItem) iRow = self.listBox.indexFromItem(selItem)
selIdx = selItem.data(Qt.UserRole) selIdx = selItem.data(0, Qt.UserRole)
if self.colCounts[selIdx] == 0: if self.colCounts[selIdx] == 0:
self.listBox.takeItem(iRow) self.listBox.takeItem(iRow)
self.colChanged = True self.colChanged = True
@@ -379,7 +404,7 @@ class GuiProjectEditStatus(QWidget):
""" """
selItem = self._getSelectedItem() selItem = self._getSelectedItem()
if selItem is not None: if selItem is not None:
selIdx = selItem.data(Qt.UserRole) selIdx = selItem.data(0, Qt.UserRole)
self.colData[selIdx] = ( self.colData[selIdx] = (
self.editName.text().strip(), self.editName.text().strip(),
self.selColour.red(), self.selColour.red(),
@@ -387,12 +412,10 @@ class GuiProjectEditStatus(QWidget):
self.selColour.blue(), self.selColour.blue(),
self.colData[selIdx][4] self.colData[selIdx][4]
) )
selItem.setText(self.tr("{0} [{1}]").format( selItem.setText(0, self.colData[selIdx][0])
self.colData[selIdx][0], self.colCounts[selIdx]) selItem.setText(1, self._usageString(self.colCounts[selIdx]))
) selItem.setIcon(0, self.colButton.icon())
selItem.setIcon(self.colButton.icon())
self.editName.setEnabled(False) self.editName.setEnabled(False)
self.editName.setText("")
self.colChanged = True self.colChanged = True
return return
@@ -402,11 +425,12 @@ class GuiProjectEditStatus(QWidget):
""" """
newIcon = QPixmap(self.iPx, self.iPx) newIcon = QPixmap(self.iPx, self.iPx)
newIcon.fill(QColor(*iCol)) newIcon.fill(QColor(*iCol))
newItem = QListWidgetItem() newItem = QTreeWidgetItem()
newItem.setText(self.tr("{0} [{1}]").format(iName, nUse)) newItem.setText(0, iName)
newItem.setIcon(QIcon(newIcon)) newItem.setText(1, self._usageString(nUse))
newItem.setData(Qt.UserRole, len(self.colData)) newItem.setIcon(0, QIcon(newIcon))
self.listBox.addItem(newItem) newItem.setData(0, Qt.UserRole, len(self.colData))
self.listBox.addTopLevelItem(newItem)
self.colData.append((iName, iCol[0], iCol[1], iCol[2], oName)) self.colData.append((iName, iCol[0], iCol[1], iCol[2], oName))
self.colCounts.append(nUse) self.colCounts.append(nUse)
return newItem return newItem
@@ -417,7 +441,7 @@ class GuiProjectEditStatus(QWidget):
""" """
selItem = self._getSelectedItem() selItem = self._getSelectedItem()
if selItem is not None: if selItem is not None:
selIdx = selItem.data(Qt.UserRole) selIdx = selItem.data(0, Qt.UserRole)
selVal = self.colData[selIdx] selVal = self.colData[selIdx]
self.selColour = QColor(selVal[1], selVal[2], selVal[3]) self.selColour = QColor(selVal[1], selVal[2], selVal[3])
newIcon = QPixmap(self.iPx, self.iPx) newIcon = QPixmap(self.iPx, self.iPx)
@@ -448,6 +472,16 @@ class GuiProjectEditStatus(QWidget):
self.colChanged = True self.colChanged = True
return 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 # END Class GuiProjectEditStatus
class GuiProjectEditReplace(QWidget): class GuiProjectEditReplace(QWidget):
@@ -463,7 +497,7 @@ class GuiProjectEditReplace(QWidget):
self.arChanged = False self.arChanged = False
wCol0 = self.mainConf.pxInt( 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") pageLabel = self.tr("Text Replace List for Preview and Export")
@@ -486,8 +520,19 @@ class GuiProjectEditReplace(QWidget):
self.listBox.sortByColumn(0, Qt.AscendingOrder) self.listBox.sortByColumn(0, Qt.AscendingOrder)
self.listBox.setSortingEnabled(True) self.listBox.setSortingEnabled(True)
# Controls # 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 = QLineEdit()
self.editKey.setPlaceholderText(self.tr("Select item to edit")) self.editKey.setPlaceholderText(self.tr("Select item to edit"))
@@ -502,14 +547,6 @@ class GuiProjectEditReplace(QWidget):
self.saveButton.setToolTip(self.tr("Save entry")) self.saveButton.setToolTip(self.tr("Save entry"))
self.saveButton.clicked.connect(self._saveEntry) self.saveButton.clicked.connect(self._saveEntry)
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)
# Assemble # Assemble
# ======== # ========
-1
View File
@@ -29,7 +29,6 @@ from nw.common import (
makeFileNameSafe, isHandle, isTitleTag, isItemClass, isItemType, makeFileNameSafe, isHandle, isTitleTag, isItemClass, isItemType,
isItemLayout, numberToRoman isItemLayout, numberToRoman
) )
from tools import cmpList
@pytest.mark.base @pytest.mark.base
def testBaseCommon_CheckString(): def testBaseCommon_CheckString():
-12
View File
@@ -72,18 +72,6 @@ def cmpFiles(fileOne, fileTwo, ignoreLines=None):
return not diffFound 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): def getGuiItem(theName):
"""Returns a QtWidget based on its objectName. """Returns a QtWidget based on its objectName.
""" """