From 9b0890c9b72243aa5ef35b374bca53469a716504 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 11 May 2025 18:32:10 +0200 Subject: [PATCH] Improve accessibility labels for novel and project trees --- novelwriter/core/itemmodel.py | 28 ++++++++++++++++------------ novelwriter/core/novelmodel.py | 2 ++ novelwriter/gui/noveltree.py | 1 + novelwriter/gui/projtree.py | 1 + novelwriter/gui/search.py | 1 + 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/novelwriter/core/itemmodel.py b/novelwriter/core/itemmodel.py index 6fb2580a..ac7cb738 100644 --- a/novelwriter/core/itemmodel.py +++ b/novelwriter/core/itemmodel.py @@ -45,16 +45,18 @@ logger = logging.getLogger(__name__) INV_ROOT = "invisibleRoot" C_FACTOR = 0x0100 -C_LABEL_TEXT = 0x0000 | Qt.ItemDataRole.DisplayRole -C_LABEL_ICON = 0x0000 | Qt.ItemDataRole.DecorationRole -C_LABEL_FONT = 0x0000 | Qt.ItemDataRole.FontRole -C_COUNT_TEXT = 0x0100 | Qt.ItemDataRole.DisplayRole -C_COUNT_ICON = 0x0100 | Qt.ItemDataRole.DecorationRole -C_COUNT_ALIGN = 0x0100 | Qt.ItemDataRole.TextAlignmentRole -C_ACTIVE_ICON = 0x0200 | Qt.ItemDataRole.DecorationRole -C_ACTIVE_TIP = 0x0200 | Qt.ItemDataRole.ToolTipRole -C_STATUS_ICON = 0x0300 | Qt.ItemDataRole.DecorationRole -C_STATUS_TIP = 0x0300 | Qt.ItemDataRole.ToolTipRole +C_LABEL_TEXT = 0x0000 | Qt.ItemDataRole.DisplayRole +C_LABEL_ICON = 0x0000 | Qt.ItemDataRole.DecorationRole +C_LABEL_FONT = 0x0000 | Qt.ItemDataRole.FontRole +C_COUNT_TEXT = 0x0100 | Qt.ItemDataRole.DisplayRole +C_COUNT_ICON = 0x0100 | Qt.ItemDataRole.DecorationRole +C_COUNT_ALIGN = 0x0100 | Qt.ItemDataRole.TextAlignmentRole +C_ACTIVE_ICON = 0x0200 | Qt.ItemDataRole.DecorationRole +C_ACTIVE_TIP = 0x0200 | Qt.ItemDataRole.ToolTipRole +C_ACTIVE_ACCESS = 0x0200 | Qt.ItemDataRole.AccessibleTextRole +C_STATUS_ICON = 0x0300 | Qt.ItemDataRole.DecorationRole +C_STATUS_TIP = 0x0300 | Qt.ItemDataRole.ToolTipRole +C_STATUS_ACCESS = 0x0300 | Qt.ItemDataRole.AccessibleTextRole NODE_FLAGS = Qt.ItemFlag.ItemIsEnabled NODE_FLAGS |= Qt.ItemFlag.ItemIsSelectable @@ -150,13 +152,15 @@ class ProjectNode: # Active aText, aIcon = self._item.getActiveStatus() - self._cache[C_ACTIVE_TIP] = aText self._cache[C_ACTIVE_ICON] = aIcon + self._cache[C_ACTIVE_TIP] = aText + self._cache[C_ACTIVE_ACCESS] = aText # Status sText, sIcon = self._item.getImportStatus() - self._cache[C_STATUS_TIP] = sText self._cache[C_STATUS_ICON] = sIcon + self._cache[C_STATUS_TIP] = sText + self._cache[C_STATUS_ACCESS] = sText return diff --git a/novelwriter/core/novelmodel.py b/novelwriter/core/novelmodel.py index e5b49b15..0447f526 100644 --- a/novelwriter/core/novelmodel.py +++ b/novelwriter/core/novelmodel.py @@ -46,6 +46,7 @@ R_TEXT = Qt.ItemDataRole.DisplayRole R_ICON = Qt.ItemDataRole.DecorationRole R_ALIGN = Qt.ItemDataRole.TextAlignmentRole R_TIP = Qt.ItemDataRole.ToolTipRole +R_ACCESS = Qt.ItemDataRole.AccessibleTextRole R_HANDLE = 0xff01 R_KEY = 0xff02 @@ -217,6 +218,7 @@ class NovelModel(QAbstractTableModel): text = ", ".join(refs) data[C_FACTOR*2 | R_TEXT] = text data[C_FACTOR*2 | R_TIP] = f"{self._extraLabel}: {text}" + data[C_FACTOR*2 | R_ACCESS] = f"{self._extraLabel}: {text}" data[C_FACTOR*3 | R_ICON] = self._more data[R_HANDLE] = handle data[R_KEY] = key diff --git a/novelwriter/gui/noveltree.py b/novelwriter/gui/noveltree.py index ac98cd83..ad071e3e 100644 --- a/novelwriter/gui/noveltree.py +++ b/novelwriter/gui/noveltree.py @@ -298,6 +298,7 @@ class GuiNovelToolBar(QWidget): self.novelValue.setHandle(rootHandle) SHARED.project.data.setLastHandle(rootHandle, "novel") self.novelView.setCurrentNovel(rootHandle) + self.novelView.novelTree.setAccessibleName(self.novelValue.currentText()) return def setLastColType(self, colType: nwNovelExtra, doRefresh: bool = True) -> None: diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py index 11c8b909..4565e315 100644 --- a/novelwriter/gui/projtree.py +++ b/novelwriter/gui/projtree.py @@ -254,6 +254,7 @@ class GuiProjectToolBar(QWidget): self.viewLabel.setFont(SHARED.theme.guiFontB) self.viewLabel.setContentsMargins(0, 0, 0, 0) self.viewLabel.setSizePolicy(QtSizeExpanding, QtSizeExpanding) + self.projTree.setAccessibleName(self.viewLabel.text()) # Quick Links self.mQuick = QMenu(self) diff --git a/novelwriter/gui/search.py b/novelwriter/gui/search.py index 323b2200..51bf1a15 100644 --- a/novelwriter/gui/search.py +++ b/novelwriter/gui/search.py @@ -125,6 +125,7 @@ class GuiProjectSearch(QWidget): self.searchResult.setAllColumnsShowFocus(True) self.searchResult.itemDoubleClicked.connect(self._searchResultDoubleClicked) self.searchResult.itemSelectionChanged.connect(self._searchResultSelected) + self.searchResult.setAccessibleName(self.viewLabel.text()) if header := self.searchResult.header(): header.setStretchLastSection(False)