Fix linting errors in the main code
This commit is contained in:
@@ -37,7 +37,7 @@ from novelwriter.core.item import NWItem
|
||||
from novelwriter.enum import nwItemClass
|
||||
from novelwriter.types import QtAlignRight
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
if TYPE_CHECKING:
|
||||
from novelwriter.core.tree import NWTree
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -89,7 +89,7 @@ class ProjectNode:
|
||||
C_ACTIVE = 2
|
||||
C_STATUS = 3
|
||||
|
||||
__slots__ = ("_item", "_children", "_parent", "_row", "_cache", "_flags", "_count")
|
||||
__slots__ = ("_cache", "_children", "_count", "_flags", "_item", "_parent", "_row")
|
||||
|
||||
def __init__(self, item: NWItem) -> None:
|
||||
self._item = item
|
||||
@@ -162,7 +162,7 @@ class ProjectNode:
|
||||
|
||||
def updateCount(self, propagate: bool = True) -> None:
|
||||
"""Update counts, and propagate upwards in the tree."""
|
||||
self._count = self._item.wordCount + sum(c._count for c in self._children)
|
||||
self._count = self._item.wordCount + sum(c._count for c in self._children) # noqa: SLF001
|
||||
self._cache[C_COUNT_TEXT] = f"{self._count:n}"
|
||||
if propagate and (parent := self._parent):
|
||||
parent.updateCount()
|
||||
@@ -257,13 +257,13 @@ class ProjectNode:
|
||||
"""Recursively add all nodes to a list."""
|
||||
for node in self._children:
|
||||
children.append(node)
|
||||
node._recursiveAppendChildren(children)
|
||||
node._recursiveAppendChildren(children) # noqa: SLF001
|
||||
return
|
||||
|
||||
def _refreshChildrenPos(self) -> None:
|
||||
"""Update the row value on all children."""
|
||||
for n, child in enumerate(self._children):
|
||||
child._row = n
|
||||
child._row = n # noqa: SLF001
|
||||
child.item.setOrder(n)
|
||||
return
|
||||
|
||||
@@ -290,12 +290,12 @@ class ProjectModel(QAbstractItemModel):
|
||||
methods needed primarily by the project tree GUI component.
|
||||
"""
|
||||
|
||||
__slots__ = ("_tree", "_root")
|
||||
__slots__ = ("_root", "_tree")
|
||||
|
||||
def __init__(self, tree: NWTree) -> None:
|
||||
super().__init__()
|
||||
self._tree = tree
|
||||
self._root = ProjectNode(NWItem(tree._project, INV_ROOT))
|
||||
self._root = ProjectNode(NWItem(tree.project, INV_ROOT))
|
||||
self._root.item.setName("Invisible Root")
|
||||
logger.debug("Ready: ProjectModel")
|
||||
return
|
||||
@@ -391,10 +391,10 @@ class ProjectModel(QAbstractItemModel):
|
||||
) -> bool:
|
||||
"""Process mime data drop."""
|
||||
if self.canDropMimeData(data, action, row, column, parent):
|
||||
items = []
|
||||
for handle in decodeMimeHandles(data):
|
||||
if (index := self.indexFromHandle(handle)).isValid():
|
||||
items.append(index)
|
||||
items = [
|
||||
index for handle in decodeMimeHandles(data)
|
||||
if (index := self.indexFromHandle(handle)).isValid()
|
||||
]
|
||||
self.multiMove(items, parent, row)
|
||||
return True
|
||||
return False
|
||||
@@ -490,7 +490,7 @@ class ProjectModel(QAbstractItemModel):
|
||||
if temp := self.removeChild(index.parent(), index.row()):
|
||||
self.insertChild(temp, target, pos)
|
||||
for child in reversed(node.allChildren()):
|
||||
node._updateRelationships(child)
|
||||
node._updateRelationships(child) # noqa: SLF001
|
||||
child.item.notifyToRefresh()
|
||||
node.item.notifyToRefresh()
|
||||
return
|
||||
@@ -501,16 +501,15 @@ class ProjectModel(QAbstractItemModel):
|
||||
|
||||
def clear(self) -> None:
|
||||
"""Clear the project model."""
|
||||
self._root._children.clear()
|
||||
self._root.children.clear()
|
||||
return
|
||||
|
||||
def allExpanded(self) -> list[QModelIndex]:
|
||||
"""Return a list of all expanded items."""
|
||||
expanded = []
|
||||
for node in self._root.allChildren():
|
||||
if node._item.isExpanded:
|
||||
expanded.append(self.createIndex(node.row(), 0, node))
|
||||
return expanded
|
||||
return [
|
||||
self.createIndex(node.row(), 0, node) for node in self._root.allChildren()
|
||||
if node.item.isExpanded
|
||||
]
|
||||
|
||||
def trashSelection(self, indices: list[QModelIndex]) -> bool:
|
||||
"""Check if a selection of indices are all in trash or not."""
|
||||
|
||||
Reference in New Issue
Block a user