Moved item status recrod keeping into a separate iterable class
This commit is contained in:
+1
-12
@@ -70,20 +70,9 @@ class GuiDocDetails(QFrame):
|
||||
if nwItem is None:
|
||||
colTwo = [""]*4
|
||||
else:
|
||||
itemStatus = nwItem.itemStatus
|
||||
if nwItem.itemClass == nwItemClass.NOVEL:
|
||||
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 = [
|
||||
nwItem.itemName,
|
||||
statusLabel,
|
||||
nwItem.itemStatus,
|
||||
nwLabels.CLASS_NAME[nwItem.itemClass],
|
||||
nwLabels.LAYOUT_NAME[nwItem.itemLayout],
|
||||
]
|
||||
|
||||
+3
-10
@@ -259,19 +259,12 @@ class GuiDocTree(QTreeWidget):
|
||||
tStatus = nwLabels.CLASS_FLAG[nwItem.itemClass]
|
||||
if nwItem.itemType == nwItemType.FILE:
|
||||
tStatus += "."+nwLabels.LAYOUT_FLAG[nwItem.itemLayout]
|
||||
nStatus = nwItem.itemStatus
|
||||
if tClass == nwItemClass.NOVEL:
|
||||
if nStatus < 0 or nStatus >= len(self.theParent.statusIcons):
|
||||
flagIcon = self.theParent.statusIcons[0]
|
||||
else:
|
||||
flagIcon = self.theParent.statusIcons[nStatus]
|
||||
flagIcon = self.theParent.statusIcons[nwItem.itemStatus]
|
||||
else:
|
||||
if nStatus < 0 or nStatus >= len(self.theParent.importIcons):
|
||||
flagIcon = self.theParent.importIcons[0]
|
||||
else:
|
||||
flagIcon = self.theParent.importIcons[nStatus]
|
||||
flagIcon = self.theParent.importIcons[nwItem.itemStatus]
|
||||
|
||||
trItem.setText(self.C_NAME,tName)
|
||||
trItem.setText(self.C_NAME, tName)
|
||||
trItem.setText(self.C_FLAGS,tStatus)
|
||||
trItem.setIcon(self.C_FLAGS,flagIcon)
|
||||
|
||||
|
||||
@@ -55,14 +55,14 @@ class GuiItemEditor(QDialog):
|
||||
self.editLayout = QComboBox()
|
||||
|
||||
if self.theItem.itemClass == nwItemClass.NOVEL:
|
||||
for n in range(len(self.theParent.statusLabels)):
|
||||
for sLabel, sCol in self.theProject.statusItems:
|
||||
self.editStatus.addItem(
|
||||
self.theParent.statusIcons[n], self.theParent.statusLabels[n], n
|
||||
self.theParent.statusIcons[sLabel], sLabel, sLabel
|
||||
)
|
||||
else:
|
||||
for n in range(len(self.theParent.statusLabels)):
|
||||
for sLabel, sCol in self.theProject.importItems:
|
||||
self.editStatus.addItem(
|
||||
self.theParent.importIcons[n], self.theParent.importLabels[n], n
|
||||
self.theParent.importIcons[sLabel], sLabel, sLabel
|
||||
)
|
||||
|
||||
self.validLayouts = []
|
||||
|
||||
+41
-18
@@ -13,9 +13,9 @@
|
||||
import logging
|
||||
import nw
|
||||
|
||||
from os import path
|
||||
from os import path
|
||||
|
||||
from PyQt5.QtGui import QIcon, QPixmap, QColor
|
||||
from PyQt5.QtGui import QIcon, QPixmap, QColor, QBrush
|
||||
from PyQt5.QtSvg import QSvgWidget
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialog, QHBoxLayout, QVBoxLayout, QFormLayout, QLineEdit, QPlainTextEdit, QLabel,
|
||||
@@ -23,6 +23,8 @@ from PyQt5.QtWidgets import (
|
||||
QColorDialog
|
||||
)
|
||||
|
||||
from nw.enum import nwChanged
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class GuiProjectEditor(QDialog):
|
||||
@@ -45,8 +47,8 @@ class GuiProjectEditor(QDialog):
|
||||
self.svgGradient.setFixedWidth(80)
|
||||
|
||||
self.tabMain = GuiProjectEditMain(self.theParent, self.theProject)
|
||||
self.tabStatus = GuiProjectEditStatus(self.theParent, self.theProject.statusCols)
|
||||
self.tabImport = GuiProjectEditStatus(self.theParent, self.theProject.importCols)
|
||||
self.tabStatus = GuiProjectEditStatus(self.theParent, self.theProject.statusItems)
|
||||
self.tabImport = GuiProjectEditStatus(self.theParent, self.theProject.importItems)
|
||||
|
||||
self.tabWidget = QTabWidget()
|
||||
self.tabWidget.addTab(self.tabMain, "Settings")
|
||||
@@ -80,10 +82,10 @@ class GuiProjectEditor(QDialog):
|
||||
self.theProject.setBookTitle(bookTitle)
|
||||
self.theProject.setBookAuthors(bookAuthors)
|
||||
|
||||
statusCol = self.tabStatus.getNewList()
|
||||
importCol = self.tabImport.getNewList()
|
||||
self.theProject.setStatusColours(statusCol)
|
||||
self.theProject.setImportColours(importCol)
|
||||
statusCol, statusChange = self.tabStatus.getNewList()
|
||||
importCol, importChange = self.tabImport.getNewList()
|
||||
self.theProject.setStatusColours(statusCol, statusChange)
|
||||
self.theProject.setImportColours(importCol, importChange)
|
||||
|
||||
self.close()
|
||||
|
||||
@@ -127,11 +129,12 @@ class GuiProjectEditMain(QWidget):
|
||||
|
||||
class GuiProjectEditStatus(QWidget):
|
||||
|
||||
def __init__(self, theParent, colList):
|
||||
def __init__(self, theParent, theStatus):
|
||||
QWidget.__init__(self, theParent)
|
||||
|
||||
self.theParent = theParent
|
||||
self.colList = colList.copy()
|
||||
self.theStatus = theStatus
|
||||
self.colNames = []
|
||||
self.colChanged = False
|
||||
|
||||
self.mainBox = QHBoxLayout()
|
||||
@@ -140,8 +143,9 @@ class GuiProjectEditStatus(QWidget):
|
||||
self.listBox = QListWidget()
|
||||
self.listBox.itemSelectionChanged.connect(self._selectedItem)
|
||||
|
||||
for iName, iR, iG, iB in self.colList:
|
||||
self._addItem(iName, iR, iG, iB)
|
||||
for iName, iCol in self.theStatus:
|
||||
self._addItem(iName, iCol)
|
||||
self.colNames.append(iName)
|
||||
|
||||
self.editName = QLineEdit()
|
||||
self.newButton = QPushButton("New")
|
||||
@@ -153,6 +157,7 @@ class GuiProjectEditStatus(QWidget):
|
||||
self.colButton.setIconSize(self.colPixmap.rect().size())
|
||||
|
||||
self.newButton.clicked.connect(self._newItem)
|
||||
self.delButton.clicked.connect(self._delItem)
|
||||
self.saveButton.clicked.connect(self._saveItem)
|
||||
self.colButton.clicked.connect(self._selectColour)
|
||||
|
||||
@@ -181,8 +186,8 @@ class GuiProjectEditStatus(QWidget):
|
||||
nImg = nItem.icon().pixmap(16,16).toImage()
|
||||
nCol = QColor(nImg.pixel(7,7))
|
||||
newList.append((nName,nCol.red(),nCol.green(),nCol.blue()))
|
||||
return newList
|
||||
return self.colList
|
||||
return newList, self.colNames
|
||||
return None, None
|
||||
|
||||
##
|
||||
# User Actions
|
||||
@@ -201,7 +206,25 @@ class GuiProjectEditStatus(QWidget):
|
||||
return
|
||||
|
||||
def _newItem(self):
|
||||
self._addItem("New Item", 0, 0, 0)
|
||||
newItem = self._addItem("New Item", (0, 0, 0))
|
||||
newItem.setBackground(QBrush(QColor(0,255,0,80)))
|
||||
self.colNames.append(None)
|
||||
self.colChanged = True
|
||||
return
|
||||
|
||||
def _delItem(self):
|
||||
selItem = self._getSelectedItem()
|
||||
colDel = QBrush(QColor(255,0,0,80))
|
||||
colNone = QBrush(QColor(0,0,0,0))
|
||||
if selItem is not None:
|
||||
sText = selItem.text()
|
||||
iRow = self.listBox.row(selItem)
|
||||
if sText == "** Delete **":
|
||||
selItem.setBackground(colNone)
|
||||
selItem.setText(self.colNames[iRow])
|
||||
else:
|
||||
selItem.setBackground(colDel)
|
||||
selItem.setText("** Delete **")
|
||||
return
|
||||
|
||||
def _saveItem(self):
|
||||
@@ -213,15 +236,15 @@ class GuiProjectEditStatus(QWidget):
|
||||
self.colChanged = True
|
||||
return
|
||||
|
||||
def _addItem(self, iName, iR, iG, iB):
|
||||
def _addItem(self, iName, iCol):
|
||||
logger.verbose("New item button clicked")
|
||||
newIcon = QPixmap(16,16)
|
||||
newIcon.fill(QColor(iR,iG,iB))
|
||||
newIcon.fill(QColor(*iCol))
|
||||
newItem = QListWidgetItem()
|
||||
newItem.setText(iName)
|
||||
newItem.setIcon(QIcon(newIcon))
|
||||
self.listBox.addItem(newItem)
|
||||
return
|
||||
return newItem
|
||||
|
||||
def _selectedItem(self):
|
||||
logger.verbose("Item selected")
|
||||
|
||||
+10
-16
@@ -61,10 +61,8 @@ class GuiMain(QMainWindow):
|
||||
self.statusBar = GuiMainStatus(self)
|
||||
|
||||
# Minor Gui Elements
|
||||
self.statusIcons = []
|
||||
self.statusLabels = []
|
||||
self.importIcons = []
|
||||
self.importLabels = []
|
||||
self.statusIcons = []
|
||||
self.importIcons = []
|
||||
|
||||
# Assemble Main Window
|
||||
self.treePane = QFrame()
|
||||
@@ -397,23 +395,19 @@ class GuiMain(QMainWindow):
|
||||
return True
|
||||
|
||||
def _makeStatusIcons(self):
|
||||
self.statusIcons = []
|
||||
self.statusLabels = []
|
||||
for sLabel, sR, sG, sB in self.theProject.statusCols:
|
||||
self.statusIcons = {}
|
||||
for sLabel, sCol in self.theProject.statusItems:
|
||||
theIcon = QPixmap(32,32)
|
||||
theIcon.fill(QColor(sR,sG,sB))
|
||||
self.statusIcons.append(QIcon(theIcon))
|
||||
self.statusLabels.append(sLabel)
|
||||
theIcon.fill(QColor(*sCol))
|
||||
self.statusIcons[sLabel] = QIcon(theIcon)
|
||||
return
|
||||
|
||||
def _makeImportIcons(self):
|
||||
self.importIcons = []
|
||||
self.importLabels = []
|
||||
for sLabel, sR, sG, sB in self.theProject.importCols:
|
||||
self.importIcons = {}
|
||||
for sLabel, sCol in self.theProject.importItems:
|
||||
theIcon = QPixmap(32,32)
|
||||
theIcon.fill(QColor(sR,sG,sB))
|
||||
self.importIcons.append(QIcon(theIcon))
|
||||
self.importLabels.append(sLabel)
|
||||
theIcon.fill(QColor(*sCol))
|
||||
self.importIcons[sLabel] = QIcon(theIcon)
|
||||
return
|
||||
|
||||
##
|
||||
|
||||
Reference in New Issue
Block a user