New root folder location (#1487)
This commit is contained in:
@@ -25,7 +25,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any, Literal, overload
|
||||||
|
|
||||||
from PyQt5.QtGui import QIcon
|
from PyQt5.QtGui import QIcon
|
||||||
|
|
||||||
@@ -308,7 +308,15 @@ class NWItem:
|
|||||||
|
|
||||||
return trConst(nwLabels.ITEM_DESCRIPTION.get(descKey, ""))
|
return trConst(nwLabels.ITEM_DESCRIPTION.get(descKey, ""))
|
||||||
|
|
||||||
def getImportStatus(self, incIcon: bool = True) -> tuple[str, QIcon | None]:
|
@overload # pragma: no cover
|
||||||
|
def getImportStatus(self, incIcon: Literal[True] = True) -> tuple[str, QIcon]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@overload # pragma: no cover
|
||||||
|
def getImportStatus(self, incIcon: Literal[False]) -> tuple[str, None]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def getImportStatus(self, incIcon=True):
|
||||||
"""Return the relevant importance or status label and icon for
|
"""Return the relevant importance or status label and icon for
|
||||||
the current item based on its class.
|
the current item based on its class.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -93,14 +93,14 @@ class NWTree:
|
|||||||
"""Returns a copy of the list of all the active handles."""
|
"""Returns a copy of the list of all the active handles."""
|
||||||
return self._treeOrder.copy()
|
return self._treeOrder.copy()
|
||||||
|
|
||||||
@overload
|
@overload # pragma: no cover
|
||||||
def create(self, label: str, parent: None, itemType: Literal[nwItemType.ROOT],
|
def create(self, label: str, parent: None, itemType: Literal[nwItemType.ROOT],
|
||||||
itemClass: nwItemClass) -> str: # pragma: no cover
|
itemClass: nwItemClass) -> str:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@overload
|
@overload # pragma: no cover
|
||||||
def create(self, label: str, parent: str | None, itemType: nwItemType,
|
def create(self, label: str, parent: str | None, itemType: nwItemType,
|
||||||
itemClass: nwItemClass = nwItemClass.NO_CLASS) -> str | None: # pragma: no cover
|
itemClass: nwItemClass = nwItemClass.NO_CLASS) -> str | None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def create(self, label, parent, itemType, itemClass=nwItemClass.NO_CLASS):
|
def create(self, label, parent, itemType, itemClass=nwItemClass.NO_CLASS):
|
||||||
|
|||||||
@@ -3034,7 +3034,7 @@ class GuiDocEditFooter(QWidget):
|
|||||||
sIcon = QPixmap()
|
sIcon = QPixmap()
|
||||||
sText = ""
|
sText = ""
|
||||||
else:
|
else:
|
||||||
theStatus, theIcon = self._theItem.getImportStatus()
|
theStatus, theIcon = self._theItem.getImportStatus(incIcon=True)
|
||||||
sIcon = theIcon.pixmap(self.sPx, self.sPx)
|
sIcon = theIcon.pixmap(self.sPx, self.sPx)
|
||||||
sText = f"{theStatus} / {self._theItem.describeMe()}"
|
sText = f"{theStatus} / {self._theItem.describeMe()}"
|
||||||
|
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ class GuiItemDetails(QWidget):
|
|||||||
# Status
|
# Status
|
||||||
# ======
|
# ======
|
||||||
|
|
||||||
theStatus, theIcon = nwItem.getImportStatus()
|
theStatus, theIcon = nwItem.getImportStatus(incIcon=True)
|
||||||
self.statusIcon.setPixmap(theIcon.pixmap(iPx, iPx))
|
self.statusIcon.setPixmap(theIcon.pixmap(iPx, iPx))
|
||||||
self.statusData.setText(theStatus)
|
self.statusData.setText(theStatus)
|
||||||
|
|
||||||
|
|||||||
+20
-22
@@ -457,7 +457,7 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
D_HANDLE = Qt.ItemDataRole.UserRole
|
D_HANDLE = Qt.ItemDataRole.UserRole
|
||||||
D_WORDS = Qt.ItemDataRole.UserRole + 1
|
D_WORDS = Qt.ItemDataRole.UserRole + 1
|
||||||
|
|
||||||
def __init__(self, projView: GuiProjectView):
|
def __init__(self, projView: GuiProjectView) -> None:
|
||||||
super().__init__(parent=projView)
|
super().__init__(parent=projView)
|
||||||
|
|
||||||
logger.debug("Create: GuiProjectTree")
|
logger.debug("Create: GuiProjectTree")
|
||||||
@@ -531,36 +531,33 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def initSettings(self):
|
def initSettings(self) -> None:
|
||||||
"""Set or update tree widget settings.
|
"""Set or update tree widget settings."""
|
||||||
"""
|
|
||||||
# Scroll bars
|
# Scroll bars
|
||||||
if CONFIG.hideVScroll:
|
if CONFIG.hideVScroll:
|
||||||
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||||
else:
|
else:
|
||||||
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
||||||
|
|
||||||
if CONFIG.hideHScroll:
|
if CONFIG.hideHScroll:
|
||||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||||
else:
|
else:
|
||||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Class Methods
|
# Class Methods
|
||||||
##
|
##
|
||||||
|
|
||||||
def clearTree(self):
|
def clearTree(self) -> None:
|
||||||
"""Clear the GUI content and the related map.
|
"""Clear the GUI content and the related map."""
|
||||||
"""
|
|
||||||
self.clear()
|
self.clear()
|
||||||
self._treeMap = {}
|
self._treeMap = {}
|
||||||
self._lastMove = {}
|
self._lastMove = {}
|
||||||
self._timeChanged = 0
|
self._timeChanged = 0
|
||||||
return
|
return
|
||||||
|
|
||||||
def newTreeItem(self, itemType, itemClass=None, hLevel=1, isNote=False):
|
def newTreeItem(self, itemType: nwItemType, itemClass: nwItemClass | None = None,
|
||||||
|
hLevel: int = 1, isNote: bool = False) -> bool:
|
||||||
"""Add new item to the tree, with a given itemType (and
|
"""Add new item to the tree, with a given itemType (and
|
||||||
itemClass if Root), and attach it to the selected handle. Also
|
itemClass if Root), and attach it to the selected handle. Also
|
||||||
make sure the item is added in a place it can be added, and that
|
make sure the item is added in a place it can be added, and that
|
||||||
@@ -576,18 +573,21 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
if itemType == nwItemType.ROOT and isinstance(itemClass, nwItemClass):
|
if itemType == nwItemType.ROOT and isinstance(itemClass, nwItemClass):
|
||||||
|
|
||||||
tHandle = self.theProject.newRoot(itemClass)
|
tHandle = self.theProject.newRoot(itemClass)
|
||||||
|
sHandle = self.getSelectedHandle()
|
||||||
|
pItem = self.theProject.tree[sHandle] if sHandle else None
|
||||||
|
nHandle = pItem.itemRoot if pItem else None
|
||||||
|
|
||||||
elif itemType in (nwItemType.FILE, nwItemType.FOLDER):
|
elif itemType in (nwItemType.FILE, nwItemType.FOLDER):
|
||||||
|
|
||||||
sHandle = self.getSelectedHandle()
|
sHandle = self.getSelectedHandle()
|
||||||
if sHandle is None or sHandle not in self.theProject.tree:
|
pItem = self.theProject.tree[sHandle] if sHandle else None
|
||||||
|
if sHandle is None or pItem is None:
|
||||||
self.mainGui.makeAlert(self.tr(
|
self.mainGui.makeAlert(self.tr(
|
||||||
"Did not find anywhere to add the file or folder!"
|
"Did not find anywhere to add the file or folder!"
|
||||||
), nwAlert.ERROR)
|
), nwAlert.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Collect some information about the selected item that
|
# Collect some information about the selected item
|
||||||
pItem = self.theProject.tree[sHandle]
|
|
||||||
qItem = self._getTreeItem(sHandle)
|
qItem = self._getTreeItem(sHandle)
|
||||||
sLevel = nwHeaders.H_LEVEL.get(pItem.mainHeading, 0)
|
sLevel = nwHeaders.H_LEVEL.get(pItem.mainHeading, 0)
|
||||||
sIsParent = False if qItem is None else qItem.childCount() > 0
|
sIsParent = False if qItem is None else qItem.childCount() > 0
|
||||||
@@ -658,9 +658,8 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def revealNewTreeItem(
|
def revealNewTreeItem(self, tHandle: str, nHandle: str | None = None,
|
||||||
self, tHandle: str, nHandle: str | None = None, wordCount: bool = False
|
wordCount: bool = False) -> bool:
|
||||||
) -> bool:
|
|
||||||
"""Reveal a newly added project item in the project tree."""
|
"""Reveal a newly added project item in the project tree."""
|
||||||
nwItem = self.theProject.tree[tHandle]
|
nwItem = self.theProject.tree[tHandle]
|
||||||
if not nwItem:
|
if not nwItem:
|
||||||
@@ -971,7 +970,7 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
if trItem is None or nwItem is None:
|
if trItem is None or nwItem is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
itemStatus, statusIcon = nwItem.getImportStatus()
|
itemStatus, statusIcon = nwItem.getImportStatus(incIcon=True)
|
||||||
hLevel = nwItem.mainHeading
|
hLevel = nwItem.mainHeading
|
||||||
itemIcon = self.mainTheme.getItemIcon(
|
itemIcon = self.mainTheme.getItemIcon(
|
||||||
nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel
|
nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel
|
||||||
@@ -1452,10 +1451,9 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
return 0
|
return 0
|
||||||
return int(tItem.data(self.C_DATA, self.D_WORDS))
|
return int(tItem.data(self.C_DATA, self.D_WORDS))
|
||||||
|
|
||||||
def _getTreeItem(self, tHandle):
|
def _getTreeItem(self, tHandle: str | None) -> QTreeWidgetItem | None:
|
||||||
"""Return the QTreeWidgetItem of a given item handle.
|
"""Return the QTreeWidgetItem of a given item handle."""
|
||||||
"""
|
return self._treeMap.get(tHandle, None) if tHandle else None
|
||||||
return self._treeMap.get(tHandle, None)
|
|
||||||
|
|
||||||
def _toggleItemActive(self, tHandle):
|
def _toggleItemActive(self, tHandle):
|
||||||
"""Toggle the active status of an item.
|
"""Toggle the active status of an item.
|
||||||
@@ -1698,7 +1696,7 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _scanChildren(self, itemList: list, tItem: QTreeWidgetItem, tIndex: int):
|
def _scanChildren(self, itemList: list, tItem: QTreeWidgetItem, tIndex: int) -> list[str]:
|
||||||
"""This is a recursive function returning all items in a tree
|
"""This is a recursive function returning all items in a tree
|
||||||
starting at a given QTreeWidgetItem.
|
starting at a given QTreeWidgetItem.
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user