Add sorting capability to status and importance labels
This commit is contained in:
+26
-36
@@ -1072,46 +1072,14 @@ class NWProject():
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def setStatusColours(self, newCols, delCols):
|
def setStatusColours(self, newCols, delCols):
|
||||||
"""Update the list of novel file status flags. Also iterate
|
"""Update the list of novel file status flags.
|
||||||
through the project and replace keys that have been renamed.
|
|
||||||
"""
|
"""
|
||||||
if not (newCols or delCols):
|
return self._setStatusImport(newCols, delCols, self.statusItems)
|
||||||
return False
|
|
||||||
|
|
||||||
for entry in newCols:
|
|
||||||
key = entry.get("key", None)
|
|
||||||
name = entry.get("name", "")
|
|
||||||
cols = entry.get("cols", (100, 100, 100))
|
|
||||||
if name:
|
|
||||||
self.statusItems.write(key, name, cols)
|
|
||||||
|
|
||||||
for key in delCols:
|
|
||||||
self.statusItems.remove(key)
|
|
||||||
|
|
||||||
self.setProjectChanged(True)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def setImportColours(self, newCols, delCols):
|
def setImportColours(self, newCols, delCols):
|
||||||
"""Update the list of note file importance flags. Also iterate
|
"""Update the list of note file importance flags.
|
||||||
through the project and replace keys that have been renamed.
|
|
||||||
"""
|
"""
|
||||||
if not (newCols or delCols):
|
return self._setStatusImport(newCols, delCols, self.importItems)
|
||||||
return False
|
|
||||||
|
|
||||||
for entry in newCols:
|
|
||||||
key = entry.get("key", None)
|
|
||||||
name = entry.get("name", "")
|
|
||||||
cols = entry.get("cols", (100, 100, 100))
|
|
||||||
if name:
|
|
||||||
self.importItems.write(key, name, cols)
|
|
||||||
|
|
||||||
for key in delCols:
|
|
||||||
self.importItems.remove(key)
|
|
||||||
|
|
||||||
self.setProjectChanged(True)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def setAutoReplace(self, autoReplace):
|
def setAutoReplace(self, autoReplace):
|
||||||
"""Update the auto-replace dictionary.
|
"""Update the auto-replace dictionary.
|
||||||
@@ -1251,6 +1219,28 @@ class NWProject():
|
|||||||
# Internal Functions
|
# Internal Functions
|
||||||
##
|
##
|
||||||
|
|
||||||
|
def _setStatusImport(self, new, delete, target):
|
||||||
|
"""Update the list of novel file status or importance flags, and
|
||||||
|
delete those that have been requested deleted.
|
||||||
|
"""
|
||||||
|
if not (new or delete):
|
||||||
|
return False
|
||||||
|
|
||||||
|
order = []
|
||||||
|
for entry in new:
|
||||||
|
key = entry.get("key", None)
|
||||||
|
name = entry.get("name", "")
|
||||||
|
cols = entry.get("cols", (100, 100, 100))
|
||||||
|
if name:
|
||||||
|
order.append(target.write(key, name, cols))
|
||||||
|
|
||||||
|
for key in delete:
|
||||||
|
target.remove(key)
|
||||||
|
|
||||||
|
target.reorder(order)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def _loadProjectLocalisation(self):
|
def _loadProjectLocalisation(self):
|
||||||
"""Load the language data for the current project language.
|
"""Load the language data for the current project language.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -167,6 +167,28 @@ class NWStatus():
|
|||||||
else:
|
else:
|
||||||
return self._defaultIcon
|
return self._defaultIcon
|
||||||
|
|
||||||
|
def reorder(self, order):
|
||||||
|
"""Reorder the items according to list.
|
||||||
|
"""
|
||||||
|
if len(order) != len(self._store):
|
||||||
|
logger.error("Length mismatch between new and old order")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if order == list(self._store.keys()):
|
||||||
|
return True
|
||||||
|
|
||||||
|
store = {}
|
||||||
|
for key in order:
|
||||||
|
if key in self._store:
|
||||||
|
store[key] = self._store[key]
|
||||||
|
else:
|
||||||
|
logger.error("Unknown key '%s' in order", key)
|
||||||
|
return False
|
||||||
|
|
||||||
|
self._store = store
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def resetCounts(self):
|
def resetCounts(self):
|
||||||
"""Clear the counts of references to the status entries.
|
"""Clear the counts of references to the status entries.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -306,6 +306,12 @@ class GuiProjectEditStatus(QWidget):
|
|||||||
self.delButton = QPushButton(self.theTheme.getIcon("remove"), "")
|
self.delButton = QPushButton(self.theTheme.getIcon("remove"), "")
|
||||||
self.delButton.clicked.connect(self._delItem)
|
self.delButton.clicked.connect(self._delItem)
|
||||||
|
|
||||||
|
self.upButton = QPushButton(self.theTheme.getIcon("up"), "")
|
||||||
|
self.upButton.clicked.connect(lambda: self._moveItem(-1))
|
||||||
|
|
||||||
|
self.dnButton = QPushButton(self.theTheme.getIcon("down"), "")
|
||||||
|
self.dnButton.clicked.connect(lambda: self._moveItem(1))
|
||||||
|
|
||||||
# Edit Form
|
# Edit Form
|
||||||
# =========
|
# =========
|
||||||
|
|
||||||
@@ -315,7 +321,7 @@ class GuiProjectEditStatus(QWidget):
|
|||||||
self.editName.setPlaceholderText(self.tr("Select item to edit"))
|
self.editName.setPlaceholderText(self.tr("Select item to edit"))
|
||||||
|
|
||||||
self.colPixmap = QPixmap(self.iPx, self.iPx)
|
self.colPixmap = QPixmap(self.iPx, self.iPx)
|
||||||
self.colPixmap.fill(QColor(120, 120, 120))
|
self.colPixmap.fill(QColor(100, 100, 100))
|
||||||
self.colButton = QPushButton(QIcon(self.colPixmap), self.tr("Colour"))
|
self.colButton = QPushButton(QIcon(self.colPixmap), self.tr("Colour"))
|
||||||
self.colButton.setIconSize(self.colPixmap.rect().size())
|
self.colButton.setIconSize(self.colPixmap.rect().size())
|
||||||
self.colButton.clicked.connect(self._selectColour)
|
self.colButton.clicked.connect(self._selectColour)
|
||||||
@@ -329,6 +335,8 @@ class GuiProjectEditStatus(QWidget):
|
|||||||
self.listControls = QVBoxLayout()
|
self.listControls = QVBoxLayout()
|
||||||
self.listControls.addWidget(self.addButton)
|
self.listControls.addWidget(self.addButton)
|
||||||
self.listControls.addWidget(self.delButton)
|
self.listControls.addWidget(self.delButton)
|
||||||
|
self.listControls.addWidget(self.upButton)
|
||||||
|
self.listControls.addWidget(self.dnButton)
|
||||||
self.listControls.addStretch(1)
|
self.listControls.addStretch(1)
|
||||||
|
|
||||||
self.editBox = QHBoxLayout()
|
self.editBox = QHBoxLayout()
|
||||||
@@ -390,7 +398,7 @@ class GuiProjectEditStatus(QWidget):
|
|||||||
def _newItem(self):
|
def _newItem(self):
|
||||||
"""Create a new status item.
|
"""Create a new status item.
|
||||||
"""
|
"""
|
||||||
newItem = self._addItem(None, self.tr("New Item"), (0, 0, 0), 0)
|
newItem = self._addItem(None, self.tr("New Item"), (100, 100, 100), 0)
|
||||||
newItem.setBackground(self.COL_LABEL, QBrush(QColor(0, 255, 0, 70)))
|
newItem.setBackground(self.COL_LABEL, QBrush(QColor(0, 255, 0, 70)))
|
||||||
newItem.setBackground(self.COL_USAGE, QBrush(QColor(0, 255, 0, 70)))
|
newItem.setBackground(self.COL_USAGE, QBrush(QColor(0, 255, 0, 70)))
|
||||||
self.colChanged = True
|
self.colChanged = True
|
||||||
@@ -445,23 +453,47 @@ class GuiProjectEditStatus(QWidget):
|
|||||||
|
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
def _moveItem(self, step):
|
||||||
|
"""Move and item up or down step.
|
||||||
|
"""
|
||||||
|
selItem = self._getSelectedItem()
|
||||||
|
if selItem is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
tIndex = self.listBox.indexOfTopLevelItem(selItem)
|
||||||
|
nChild = self.listBox.topLevelItemCount()
|
||||||
|
nIndex = tIndex + step
|
||||||
|
if nIndex < 0 or nIndex >= nChild:
|
||||||
|
return False
|
||||||
|
|
||||||
|
cItem = self.listBox.takeTopLevelItem(tIndex)
|
||||||
|
self.listBox.insertTopLevelItem(nIndex, cItem)
|
||||||
|
self.listBox.clearSelection()
|
||||||
|
|
||||||
|
cItem.setSelected(True)
|
||||||
|
self.colChanged = True
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
def _selectedItem(self):
|
def _selectedItem(self):
|
||||||
"""Extract the info of a selected item and populate the settings
|
"""Extract the info of a selected item and populate the settings
|
||||||
boxes and button.
|
boxes and button.
|
||||||
"""
|
"""
|
||||||
selItem = self._getSelectedItem()
|
selItem = self._getSelectedItem()
|
||||||
if selItem is not None:
|
if selItem is None:
|
||||||
cols = selItem.data(self.COL_LABEL, self.COL_ROLE)
|
return
|
||||||
name = selItem.text(self.COL_LABEL)
|
|
||||||
|
|
||||||
pixmap = QPixmap(self.iPx, self.iPx)
|
cols = selItem.data(self.COL_LABEL, self.COL_ROLE)
|
||||||
pixmap.fill(QColor(*cols))
|
name = selItem.text(self.COL_LABEL)
|
||||||
self.selColour = QColor(*cols)
|
|
||||||
self.editName.setText(name)
|
pixmap = QPixmap(self.iPx, self.iPx)
|
||||||
self.colButton.setIcon(QIcon(pixmap))
|
pixmap.fill(QColor(*cols))
|
||||||
self.editName.setEnabled(True)
|
self.selColour = QColor(*cols)
|
||||||
self.editName.selectAll()
|
self.editName.setText(name)
|
||||||
self.editName.setFocus()
|
self.colButton.setIcon(QIcon(pixmap))
|
||||||
|
self.editName.setEnabled(True)
|
||||||
|
self.editName.selectAll()
|
||||||
|
self.editName.setFocus()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -477,12 +509,6 @@ class GuiProjectEditStatus(QWidget):
|
|||||||
return selItem[0]
|
return selItem[0]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _rowsMoved(self):
|
|
||||||
"""A row has been moved, so set the changed flag.
|
|
||||||
"""
|
|
||||||
self.colChanged = True
|
|
||||||
return
|
|
||||||
|
|
||||||
def _usageString(self, nUse):
|
def _usageString(self, nUse):
|
||||||
"""Generate usage string.
|
"""Generate usage string.
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user