New root folder location (#1487)

This commit is contained in:
Veronica Berglyd Olsen
2023-07-28 23:23:46 +02:00
committed by GitHub
5 changed files with 36 additions and 30 deletions
+10 -2
View File
@@ -25,7 +25,7 @@ from __future__ import annotations
import logging
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Literal, overload
from PyQt5.QtGui import QIcon
@@ -308,7 +308,15 @@ class NWItem:
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
the current item based on its class.
"""
+4 -4
View File
@@ -93,14 +93,14 @@ class NWTree:
"""Returns a copy of the list of all the active handles."""
return self._treeOrder.copy()
@overload
@overload # pragma: no cover
def create(self, label: str, parent: None, itemType: Literal[nwItemType.ROOT],
itemClass: nwItemClass) -> str: # pragma: no cover
itemClass: nwItemClass) -> str:
pass
@overload
@overload # pragma: no cover
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
def create(self, label, parent, itemType, itemClass=nwItemClass.NO_CLASS):
+1 -1
View File
@@ -3034,7 +3034,7 @@ class GuiDocEditFooter(QWidget):
sIcon = QPixmap()
sText = ""
else:
theStatus, theIcon = self._theItem.getImportStatus()
theStatus, theIcon = self._theItem.getImportStatus(incIcon=True)
sIcon = theIcon.pixmap(self.sPx, self.sPx)
sText = f"{theStatus} / {self._theItem.describeMe()}"
+1 -1
View File
@@ -263,7 +263,7 @@ class GuiItemDetails(QWidget):
# Status
# ======
theStatus, theIcon = nwItem.getImportStatus()
theStatus, theIcon = nwItem.getImportStatus(incIcon=True)
self.statusIcon.setPixmap(theIcon.pixmap(iPx, iPx))
self.statusData.setText(theStatus)
+20 -22
View File
@@ -457,7 +457,7 @@ class GuiProjectTree(QTreeWidget):
D_HANDLE = Qt.ItemDataRole.UserRole
D_WORDS = Qt.ItemDataRole.UserRole + 1
def __init__(self, projView: GuiProjectView):
def __init__(self, projView: GuiProjectView) -> None:
super().__init__(parent=projView)
logger.debug("Create: GuiProjectTree")
@@ -531,36 +531,33 @@ class GuiProjectTree(QTreeWidget):
return
def initSettings(self):
"""Set or update tree widget settings.
"""
def initSettings(self) -> None:
"""Set or update tree widget settings."""
# Scroll bars
if CONFIG.hideVScroll:
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
else:
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
if CONFIG.hideHScroll:
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
else:
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
return
##
# Class Methods
##
def clearTree(self):
"""Clear the GUI content and the related map.
"""
def clearTree(self) -> None:
"""Clear the GUI content and the related map."""
self.clear()
self._treeMap = {}
self._lastMove = {}
self._timeChanged = 0
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
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
@@ -576,18 +573,21 @@ class GuiProjectTree(QTreeWidget):
if itemType == nwItemType.ROOT and isinstance(itemClass, nwItemClass):
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):
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(
"Did not find anywhere to add the file or folder!"
), nwAlert.ERROR)
return False
# Collect some information about the selected item that
pItem = self.theProject.tree[sHandle]
# Collect some information about the selected item
qItem = self._getTreeItem(sHandle)
sLevel = nwHeaders.H_LEVEL.get(pItem.mainHeading, 0)
sIsParent = False if qItem is None else qItem.childCount() > 0
@@ -658,9 +658,8 @@ class GuiProjectTree(QTreeWidget):
return True
def revealNewTreeItem(
self, tHandle: str, nHandle: str | None = None, wordCount: bool = False
) -> bool:
def revealNewTreeItem(self, tHandle: str, nHandle: str | None = None,
wordCount: bool = False) -> bool:
"""Reveal a newly added project item in the project tree."""
nwItem = self.theProject.tree[tHandle]
if not nwItem:
@@ -971,7 +970,7 @@ class GuiProjectTree(QTreeWidget):
if trItem is None or nwItem is None:
return
itemStatus, statusIcon = nwItem.getImportStatus()
itemStatus, statusIcon = nwItem.getImportStatus(incIcon=True)
hLevel = nwItem.mainHeading
itemIcon = self.mainTheme.getItemIcon(
nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel
@@ -1452,10 +1451,9 @@ class GuiProjectTree(QTreeWidget):
return 0
return int(tItem.data(self.C_DATA, self.D_WORDS))
def _getTreeItem(self, tHandle):
"""Return the QTreeWidgetItem of a given item handle.
"""
return self._treeMap.get(tHandle, None)
def _getTreeItem(self, tHandle: str | None) -> QTreeWidgetItem | None:
"""Return the QTreeWidgetItem of a given item handle."""
return self._treeMap.get(tHandle, None) if tHandle else None
def _toggleItemActive(self, tHandle):
"""Toggle the active status of an item.
@@ -1698,7 +1696,7 @@ class GuiProjectTree(QTreeWidget):
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
starting at a given QTreeWidgetItem.
"""