Update accessibility for switches, settings and trees (#2337)

This commit is contained in:
Veronica Berglyd Olsen
2025-05-11 19:07:37 +02:00
committed by GitHub
18 changed files with 186 additions and 114 deletions
+16 -12
View File
@@ -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
+2
View File
@@ -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"<b>{self._extraLabel}:</b> {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
+2 -1
View File
@@ -73,8 +73,9 @@ class GuiDocMerge(NDialog):
self.listBox.setDragDropMode(QAbstractItemView.DragDropMode.InternalMove)
# Merge Options
self.trashLabel = QLabel(self.tr("Move merged items to Trash"), self)
self.trashSwitch = NSwitch(self, height=iPx)
self.trashLabel = QLabel(self.tr("Move merged items to Trash"), self)
self.trashLabel.setBuddy(self.trashSwitch)
self.optBox = QGridLayout()
self.optBox.addWidget(self.trashLabel, 0, 0)
+6 -3
View File
@@ -90,16 +90,19 @@ class GuiDocSplit(NDialog):
self.splitLevel.currentIndexChanged.connect(self._reloadList)
# Split Options
self.folderLabel = QLabel(self.tr("Split into a new folder"), self)
self.folderSwitch = NSwitch(self, height=iPx)
self.folderSwitch.setChecked(intoFolder)
self.folderLabel = QLabel(self.tr("Split into a new folder"), self)
self.folderLabel.setBuddy(self.folderSwitch)
self.hierarchyLabel = QLabel(self.tr("Create document hierarchy"), self)
self.hierarchySwitch = NSwitch(self, height=iPx)
self.hierarchySwitch.setChecked(docHierarchy)
self.hierarchyLabel = QLabel(self.tr("Create document hierarchy"), self)
self.hierarchyLabel.setBuddy(self.hierarchySwitch)
self.trashLabel = QLabel(self.tr("Move split document to Trash"), self)
self.trashSwitch = NSwitch(self, height=iPx)
self.trashLabel = QLabel(self.tr("Move split document to Trash"), self)
self.trashLabel.setBuddy(self.trashSwitch)
self.optBox = QGridLayout()
self.optBox.addWidget(self.folderLabel, 0, 0)
+11 -8
View File
@@ -43,11 +43,14 @@ class GuiEditLabel(NDialog):
self.setWindowTitle(self.tr("Item Label"))
# Item Label
self.labelValue = QLineEdit(self)
self.labelValue.setMinimumWidth(220)
self.labelValue.setMaxLength(200)
self.labelValue.setText(text)
self.labelValue.selectAll()
self.edtValue = QLineEdit(self)
self.edtValue.setMinimumWidth(220)
self.edtValue.setMaxLength(200)
self.edtValue.setText(text)
self.edtValue.selectAll()
self.lblValue = QLabel(self.tr("Label"), self)
self.lblValue.setBuddy(self.lblValue)
# Buttons
self.buttonBox = QDialogButtonBox(QtDialogOk | QtDialogCancel, self)
@@ -56,8 +59,8 @@ class GuiEditLabel(NDialog):
# Assemble
self.innerBox = QHBoxLayout()
self.innerBox.addWidget(QLabel(self.tr("Label"), self), 0)
self.innerBox.addWidget(self.labelValue, 1)
self.innerBox.addWidget(self.lblValue, 0)
self.innerBox.addWidget(self.edtValue, 1)
self.innerBox.setSpacing(12)
self.outerBox = QVBoxLayout()
@@ -77,7 +80,7 @@ class GuiEditLabel(NDialog):
@property
def itemLabel(self) -> str:
return self.labelValue.text()
return self.edtValue.text()
@classmethod
def getLabel(cls, parent: QWidget, text: str) -> tuple[str, bool]:
+1
View File
@@ -80,6 +80,7 @@ class GuiPreferences(NDialog):
# SideBar
self.sidebar = NPagedSideBar(self)
self.sidebar.setLabelColor(SHARED.theme.helpText)
self.sidebar.setAccessibleName(self.titleLabel.text())
self.sidebar.buttonClicked.connect(self._sidebarClicked)
# Form
+3
View File
@@ -86,6 +86,7 @@ class GuiProjectSettings(NDialog):
# SideBar
self.sidebar = NPagedSideBar(self)
self.sidebar.setLabelColor(SHARED.theme.helpText)
self.sidebar.setAccessibleName(self.titleLabel.text())
self.sidebar.addButton(self.tr("Settings"), self.PAGE_SETTINGS)
self.sidebar.addButton(self.tr("Status"), self.PAGE_STATUS)
self.sidebar.addButton(self.tr("Importance"), self.PAGE_IMPORT)
@@ -349,6 +350,7 @@ class _StatusPage(NFixedPage):
self.listBox.setHeaderLabels([self.tr("Label"), self.tr("Usage")])
self.listBox.setColumnWidth(self.C_LABEL, wCol0)
self.listBox.setIndentation(0)
self.listBox.setAccessibleName(pageLabel)
self.listBox.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
self.listBox.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
self.listBox.itemSelectionChanged.connect(self._onSelectionChanged)
@@ -686,6 +688,7 @@ class _ReplacePage(NFixedPage):
self.listBox.setHeaderLabels([self.tr("Keyword"), self.tr("Replace With")])
self.listBox.setColumnWidth(self.C_KEY, wCol0)
self.listBox.setIndentation(0)
self.listBox.setAccessibleName(self.pageTitle.text())
self.listBox.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
self.listBox.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
self.listBox.itemSelectionChanged.connect(self._onSelectionChanged)
+6 -2
View File
@@ -211,7 +211,8 @@ class NScrollableForm(QScrollArea):
else:
qWidget = widget
qLabel = QLabel(label or "", self)
text = label or ""
qLabel = QLabel(text, self)
qLabel.setIndent(self._indent)
qLabel.setBuddy(qWidget)
@@ -227,6 +228,7 @@ class NScrollableForm(QScrollArea):
row.addLayout(labelBox, stretch[0])
if editable:
self._editable[editable] = qHelp
text = f"{text}: {helpText}"
else:
row.addWidget(qLabel, stretch[0])
@@ -235,6 +237,7 @@ class NScrollableForm(QScrollArea):
box.addWidget(qWidget, 1)
box.addWidget(QLabel(unit, self), 0)
row.addLayout(box, stretch[1])
text = f"{text} Unit: {unit}"
elif isinstance(button, QAbstractButton):
box = QHBoxLayout()
box.addWidget(qWidget, 1)
@@ -243,10 +246,11 @@ class NScrollableForm(QScrollArea):
else:
row.addWidget(qWidget, stretch[1])
self._first = False
self._layout.addLayout(row)
if label:
self._index[label.strip()] = qWidget
self._first = False
qLabel.setAccessibleName(text)
return
+16 -15
View File
@@ -23,12 +23,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from __future__ import annotations
from PyQt6.QtCore import QPropertyAnimation, Qt, pyqtProperty # pyright: ignore
from PyQt6.QtGui import QEnterEvent, QMouseEvent, QPainter, QPaintEvent, QResizeEvent
from PyQt6.QtCore import QPropertyAnimation, Qt, pyqtProperty, pyqtSlot # pyright: ignore
from PyQt6.QtGui import QEnterEvent, QPainter, QPaintEvent, QResizeEvent
from PyQt6.QtWidgets import QAbstractButton, QWidget
from novelwriter import SHARED
from novelwriter.types import QtMouseLeft, QtNoPen, QtPaintAntiAlias, QtSizeFixed
from novelwriter.types import QtNoPen, QtPaintAntiAlias, QtSizeFixed
class NSwitch(QAbstractButton):
@@ -50,6 +50,8 @@ class NSwitch(QAbstractButton):
self.setFixedHeight(self._xH)
self._offset = self._xR
self.clicked.connect(self._onClick)
return
##
@@ -94,7 +96,7 @@ class NSwitch(QAbstractButton):
painter.setRenderHint(QtPaintAntiAlias, True)
painter.setOpacity(1.0 if self.isEnabled() else 0.5)
painter.setPen(palette.mid().color())
painter.setPen(palette.highlight().color() if self.hasFocus() else palette.mid().color())
painter.setBrush(palette.highlight() if self.isChecked() else palette.alternateBase())
painter.drawRoundedRect(0, 0, self._xW, self._xH, self._xR, self._xR)
@@ -106,19 +108,18 @@ class NSwitch(QAbstractButton):
return
def mouseReleaseEvent(self, event: QMouseEvent) -> None:
"""Animate the switch on mouse release."""
super().mouseReleaseEvent(event)
if event.button() == QtMouseLeft:
anim = QPropertyAnimation(self, b"offset", self)
anim.setDuration(120)
anim.setStartValue(self._offset)
anim.setEndValue((self._xW - self._xR) if self.isChecked() else self._xR)
anim.start()
return
def enterEvent(self, event: QEnterEvent) -> None:
"""Change the cursor when hovering the button."""
self.setCursor(Qt.CursorShape.PointingHandCursor)
super().enterEvent(event)
return
@pyqtSlot(bool)
def _onClick(self, checked: bool) -> None:
"""Animate the toggle action."""
anim = QPropertyAnimation(self, b"offset", self)
anim.setDuration(120)
anim.setStartValue(self._offset)
anim.setEndValue((self._xW - self._xR) if checked else self._xR)
anim.start()
return
+1
View File
@@ -100,6 +100,7 @@ class NSwitchBox(QScrollArea):
switch.toggled.connect(lambda state: self._emitSwitchSignal(identifier, state))
self._content.addWidget(switch, self._index, 2, QtAlignRight)
label.setBuddy(switch)
self._widgets.append(switch)
self._bumpIndex()
+1
View File
@@ -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:
+1
View File
@@ -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)
+1
View File
@@ -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)
+2 -1
View File
@@ -75,8 +75,9 @@ class GuiLipsum(NDialog):
self.paraCount.setMaximum(100)
self.paraCount.setValue(5)
self.randLabel = QLabel(self.tr("Randomise order"), self)
self.randSwitch = NSwitch(self)
self.randLabel = QLabel(self.tr("Randomise order"), self)
self.randLabel.setBuddy(self.randSwitch)
self.formBox = QGridLayout()
self.formBox.addWidget(self.headLabel, 0, 0, 1, 2, QtAlignLeft)
+34 -13
View File
@@ -104,6 +104,7 @@ class GuiBuildSettings(NToolDialog):
# SideBar
self.sidebar = NPagedSideBar(self)
self.sidebar.setLabelColor(SHARED.theme.helpText)
self.sidebar.setAccessibleName(self.titleLabel.text())
self.sidebar.addLabel(self.tr("General"))
self.sidebar.addButton(self.tr("Selection"), self.OPT_FILTERS)
@@ -564,9 +565,10 @@ class _HeadingsTab(NScrollablePage):
self.fmtPart.setReadOnly(True)
self.btnPart = NIconToolButton(self, iSz, "edit", "green")
self.btnPart.clicked.connect(qtLambda(self._editHeading, self.EDIT_TITLE))
self.swtPart = NSwitch(self, height=iPx)
self.hdePart = QLabel(trHide, self)
self.hdePart.setIndent(6)
self.swtPart = NSwitch(self, height=iPx)
self.hdePart.setBuddy(self.swtPart)
self.formatBox.addWidget(self.lblPart, 0, 0)
self.formatBox.addWidget(self.fmtPart, 0, 1)
@@ -580,9 +582,10 @@ class _HeadingsTab(NScrollablePage):
self.fmtChapter.setReadOnly(True)
self.btnChapter = NIconToolButton(self, iSz, "edit", "green")
self.btnChapter.clicked.connect(qtLambda(self._editHeading, self.EDIT_CHAPTER))
self.swtChapter = NSwitch(self, height=iPx)
self.hdeChapter = QLabel(trHide, self)
self.hdeChapter.setIndent(6)
self.swtChapter = NSwitch(self, height=iPx)
self.hdeChapter.setBuddy(self.swtChapter)
self.formatBox.addWidget(self.lblChapter, 1, 0)
self.formatBox.addWidget(self.fmtChapter, 1, 1)
@@ -596,9 +599,10 @@ class _HeadingsTab(NScrollablePage):
self.fmtUnnumbered.setReadOnly(True)
self.btnUnnumbered = NIconToolButton(self, iSz, "edit", "green")
self.btnUnnumbered.clicked.connect(qtLambda(self._editHeading, self.EDIT_UNNUM))
self.swtUnnumbered = NSwitch(self, height=iPx)
self.hdeUnnumbered = QLabel(trHide, self)
self.hdeUnnumbered.setIndent(6)
self.swtUnnumbered = NSwitch(self, height=iPx)
self.hdeUnnumbered.setBuddy(self.swtUnnumbered)
self.formatBox.addWidget(self.lblUnnumbered, 2, 0)
self.formatBox.addWidget(self.fmtUnnumbered, 2, 1)
@@ -612,9 +616,10 @@ class _HeadingsTab(NScrollablePage):
self.fmtScene.setReadOnly(True)
self.btnScene = NIconToolButton(self, iSz, "edit", "green")
self.btnScene.clicked.connect(qtLambda(self._editHeading, self.EDIT_SCENE))
self.swtScene = NSwitch(self, height=iPx)
self.hdeScene = QLabel(trHide, self)
self.hdeScene.setIndent(6)
self.swtScene = NSwitch(self, height=iPx)
self.hdeScene.setBuddy(self.swtScene)
self.formatBox.addWidget(self.lblScene, 3, 0)
self.formatBox.addWidget(self.fmtScene, 3, 1)
@@ -628,9 +633,10 @@ class _HeadingsTab(NScrollablePage):
self.fmtAScene.setReadOnly(True)
self.btnAScene = NIconToolButton(self, iSz, "edit", "green")
self.btnAScene.clicked.connect(qtLambda(self._editHeading, self.EDIT_HSCENE))
self.swtAScene = NSwitch(self, height=iPx)
self.hdeAScene = QLabel(trHide, self)
self.hdeAScene.setIndent(6)
self.swtAScene = NSwitch(self, height=iPx)
self.hdeAScene.setBuddy(self.swtAScene)
self.formatBox.addWidget(self.lblAScene, 4, 0)
self.formatBox.addWidget(self.fmtAScene, 4, 1)
@@ -644,9 +650,10 @@ class _HeadingsTab(NScrollablePage):
self.fmtSection.setReadOnly(True)
self.btnSection = NIconToolButton(self, iSz, "edit", "green")
self.btnSection.clicked.connect(qtLambda(self._editHeading, self.EDIT_SECTION))
self.swtSection = NSwitch(self, height=iPx)
self.hdeSection = QLabel(trHide, self)
self.hdeSection.setIndent(6)
self.swtSection = NSwitch(self, height=iPx)
self.hdeSection.setBuddy(self.swtSection)
self.formatBox.addWidget(self.lblSection, 5, 0)
self.formatBox.addWidget(self.fmtSection, 5, 1)
@@ -704,44 +711,59 @@ class _HeadingsTab(NScrollablePage):
# Layout Matrix
# =============
trCentre = self.tr("Centre")
trBreak = self.tr("Page Break")
self.layoutMatrix = QGridLayout()
self.layoutMatrix.setVerticalSpacing(12)
self.layoutMatrix.setHorizontalSpacing(12)
self.layoutMatrix.addWidget(QLabel(self.tr("Centre"), self), 0, 1)
self.layoutMatrix.addWidget(QLabel(self.tr("Page Break"), self), 0, 2)
self.layoutMatrix.addWidget(QLabel(trCentre, self), 0, 1)
self.layoutMatrix.addWidget(QLabel(trBreak, self), 0, 2)
# Title Layout
self.lblTitle = QLabel(self._build.getLabel("headings.styleTitle"), self)
trLabel = self._build.getLabel("headings.styleTitle")
self.lblTitle = QLabel(trLabel, self)
self.centerTitle = NSwitch(self, height=iPx)
self.centerTitle.setAccessibleName(f"{trLabel}: {trCentre}")
self.breakTitle = NSwitch(self, height=iPx)
self.breakTitle.setAccessibleName(f"{trLabel}: {trBreak}")
self.layoutMatrix.addWidget(self.lblTitle, 1, 0)
self.layoutMatrix.addWidget(self.centerTitle, 1, 1, QtAlignCenter)
self.layoutMatrix.addWidget(self.breakTitle, 1, 2, QtAlignCenter)
# Partition Layout
self.lblPart = QLabel(self._build.getLabel("headings.stylePart"), self)
trLabel = self._build.getLabel("headings.stylePart")
self.lblPart = QLabel(trLabel, self)
self.centerPart = NSwitch(self, height=iPx)
self.centerPart.setAccessibleName(f"{trLabel}: {trCentre}")
self.breakPart = NSwitch(self, height=iPx)
self.breakPart.setAccessibleName(f"{trLabel}: {trBreak}")
self.layoutMatrix.addWidget(self.lblPart, 2, 0)
self.layoutMatrix.addWidget(self.centerPart, 2, 1, QtAlignCenter)
self.layoutMatrix.addWidget(self.breakPart, 2, 2, QtAlignCenter)
# Chapter Layout
self.lblChapter = QLabel(self._build.getLabel("headings.styleChapter"), self)
trLabel = self._build.getLabel("headings.styleChapter")
self.lblChapter = QLabel(trLabel, self)
self.centerChapter = NSwitch(self, height=iPx)
self.centerChapter.setAccessibleName(f"{trLabel}: {trCentre}")
self.breakChapter = NSwitch(self, height=iPx)
self.breakChapter.setAccessibleName(f"{trLabel}: {trBreak}")
self.layoutMatrix.addWidget(self.lblChapter, 3, 0)
self.layoutMatrix.addWidget(self.centerChapter, 3, 1, QtAlignCenter)
self.layoutMatrix.addWidget(self.breakChapter, 3, 2, QtAlignCenter)
# Scene Layout
self.lblScene = QLabel(self._build.getLabel("headings.styleScene"), self)
trLabel = self._build.getLabel("headings.styleScene")
self.lblScene = QLabel(trLabel, self)
self.centerScene = NSwitch(self, height=iPx)
self.centerScene.setAccessibleName(f"{trLabel}: {trCentre}")
self.breakScene = NSwitch(self, height=iPx)
self.breakScene.setAccessibleName(f"{trLabel}: {trBreak}")
self.layoutMatrix.addWidget(self.lblScene, 4, 0)
self.layoutMatrix.addWidget(self.centerScene, 4, 1, QtAlignCenter)
@@ -979,7 +1001,6 @@ class _FormattingTab(NScrollableForm):
# Note Headings
self.addNoteHead = NSwitch(self, height=iPx)
self.addRow(self._build.getLabel("text.addNoteHeadings"), self.addNoteHead)
# Text Format
+7 -6
View File
@@ -86,6 +86,7 @@ class GuiNovelDetails(NNonBlockingDialog):
# SideBar
self.sidebar = NPagedSideBar(self)
self.sidebar.setLabelColor(SHARED.theme.helpText)
self.sidebar.setAccessibleName(self.titleLabel.text())
self.sidebar.addButton(self.tr("Overview"), self.PAGE_OVERVIEW)
self.sidebar.addButton(self.tr("Contents"), self.PAGE_CONTENTS)
self.sidebar.setSelected(self.PAGE_OVERVIEW)
@@ -356,16 +357,14 @@ class _ContentsPage(NFixedPage):
countFrom = options.getInt("GuiNovelDetails", "countFrom", 1)
clearDouble = options.getBool("GuiNovelDetails", "clearDouble", True)
self.wpLabel = QLabel(self.tr("Words per page"), self)
self.wpValue = QSpinBox(self)
self.wpValue.setMinimum(10)
self.wpValue.setMaximum(1000)
self.wpValue.setSingleStep(10)
self.wpValue.setValue(wordsPerPage)
self.wpValue.valueChanged.connect(self._populateTree)
self.poLabel = QLabel(self.tr("First page offset"), self)
self.wpLabel = QLabel(self.tr("Words per page"), self)
self.wpLabel.setBuddy(self.wpValue)
self.poValue = QSpinBox(self)
self.poValue.setMinimum(1)
@@ -373,12 +372,14 @@ class _ContentsPage(NFixedPage):
self.poValue.setSingleStep(1)
self.poValue.setValue(countFrom)
self.poValue.valueChanged.connect(self._populateTree)
self.dblLabel = QLabel(self.tr("Chapters on odd pages"), self)
self.poLabel = QLabel(self.tr("First page offset"), self)
self.poLabel.setBuddy(self.poValue)
self.dblValue = NSwitch(self, height=iPx)
self.dblValue.setChecked(clearDouble)
self.dblValue.clicked.connect(self._populateTree)
self.dblLabel = QLabel(self.tr("Chapters on odd pages"), self)
self.dblLabel.setBuddy(self.dblValue)
self.optionsBox = QGridLayout()
self.optionsBox.addWidget(self.wpLabel, 0, 0)
+67 -44
View File
@@ -183,59 +183,82 @@ class GuiWritingStats(NToolDialog):
# Filter Options
iPx = SHARED.theme.baseIconHeight
self.filterBox = QGroupBox(self.tr("Filters"), self)
self.filterForm = QGridLayout(self)
self.filterForm.setRowStretch(6, 1)
self.filterBox = QGroupBox(self.tr("Filters"), self)
self.filterBox.setLayout(self.filterForm)
self.incNovel = NSwitch(self, height=iPx)
self.incNovel.setChecked(
# Include Novel Files
self.swtIncNovel = NSwitch(self, height=iPx)
self.swtIncNovel.setChecked(
pOptions.getBool("GuiWritingStats", "incNovel", True)
)
self.incNovel.clicked.connect(self._updateListBox)
self.swtIncNovel.clicked.connect(self._updateListBox)
self.lblIncNovel = QLabel(self.tr("Count novel files"), self)
self.lblIncNovel.setBuddy(self.swtIncNovel)
self.incNotes = NSwitch(self, height=iPx)
self.incNotes.setChecked(
self.filterForm.addWidget(self.lblIncNovel, 0, 0)
self.filterForm.addWidget(self.swtIncNovel, 0, 1)
# Include Note Files
self.swtIncNotes = NSwitch(self, height=iPx)
self.swtIncNotes.setChecked(
pOptions.getBool("GuiWritingStats", "incNotes", True)
)
self.incNotes.clicked.connect(self._updateListBox)
self.swtIncNotes.clicked.connect(self._updateListBox)
self.lblIncNotes = QLabel(self.tr("Count note files"), self)
self.lblIncNotes.setBuddy(self.swtIncNotes)
self.hideZeros = NSwitch(self, height=iPx)
self.hideZeros.setChecked(
self.filterForm.addWidget(self.lblIncNotes, 1, 0)
self.filterForm.addWidget(self.swtIncNotes, 1, 1)
# Hide Zero Counts
self.swtHideZeros = NSwitch(self, height=iPx)
self.swtHideZeros.setChecked(
pOptions.getBool("GuiWritingStats", "hideZeros", True)
)
self.hideZeros.clicked.connect(self._updateListBox)
self.swtHideZeros.clicked.connect(self._updateListBox)
self.lblHideZeros = QLabel(self.tr("Hide zero word count"), self)
self.lblHideZeros.setBuddy(self.swtHideZeros)
self.hideNegative = NSwitch(self, height=iPx)
self.hideNegative.setChecked(
self.filterForm.addWidget(self.lblHideZeros, 2, 0)
self.filterForm.addWidget(self.swtHideZeros, 2, 1)
# Hide Negative Counts
self.swtHideNegative = NSwitch(self, height=iPx)
self.swtHideNegative.setChecked(
pOptions.getBool("GuiWritingStats", "hideNegative", False)
)
self.hideNegative.clicked.connect(self._updateListBox)
self.swtHideNegative.clicked.connect(self._updateListBox)
self.lblHideNegative = QLabel(self.tr("Hide negative word count"), self)
self.lblHideNegative.setBuddy(self.swtHideNegative)
self.groupByDay = NSwitch(self, height=iPx)
self.groupByDay.setChecked(
self.filterForm.addWidget(self.lblHideNegative, 3, 0)
self.filterForm.addWidget(self.swtHideNegative, 3, 1)
# Group Entries
self.swtGroupByDay = NSwitch(self, height=iPx)
self.swtGroupByDay.setChecked(
pOptions.getBool("GuiWritingStats", "groupByDay", False)
)
self.groupByDay.clicked.connect(self._updateListBox)
self.swtGroupByDay.clicked.connect(self._updateListBox)
self.lblGroupByDay = QLabel(self.tr("Group entries by day"), self)
self.lblGroupByDay.setBuddy(self.swtGroupByDay)
self.showIdleTime = NSwitch(self, height=iPx)
self.showIdleTime.setChecked(
self.filterForm.addWidget(self.lblGroupByDay, 4, 0)
self.filterForm.addWidget(self.swtGroupByDay, 4, 1)
# Show Idle
self.swtShowIdleTime = NSwitch(self, height=iPx)
self.swtShowIdleTime.setChecked(
pOptions.getBool("GuiWritingStats", "showIdleTime", False)
)
self.showIdleTime.clicked.connect(self._updateListBox)
self.swtShowIdleTime.clicked.connect(self._updateListBox)
self.lblShowIdleTime = QLabel(self.tr("Show idle time"), self)
self.lblShowIdleTime.setBuddy(self.swtShowIdleTime)
self.filterForm.addWidget(QLabel(self.tr("Count novel files"), self), 0, 0)
self.filterForm.addWidget(QLabel(self.tr("Count note files"), self), 1, 0)
self.filterForm.addWidget(QLabel(self.tr("Hide zero word count"), self), 2, 0)
self.filterForm.addWidget(QLabel(self.tr("Hide negative word count"), self), 3, 0)
self.filterForm.addWidget(QLabel(self.tr("Group entries by day"), self), 4, 0)
self.filterForm.addWidget(QLabel(self.tr("Show idle time"), self), 5, 0)
self.filterForm.addWidget(self.incNovel, 0, 1)
self.filterForm.addWidget(self.incNotes, 1, 1)
self.filterForm.addWidget(self.hideZeros, 2, 1)
self.filterForm.addWidget(self.hideNegative, 3, 1)
self.filterForm.addWidget(self.groupByDay, 4, 1)
self.filterForm.addWidget(self.showIdleTime, 5, 1)
self.filterForm.setRowStretch(6, 1)
self.filterForm.addWidget(self.lblShowIdleTime, 5, 0)
self.filterForm.addWidget(self.swtShowIdleTime, 5, 1)
# Settings
self.histMax = QSpinBox(self)
@@ -325,12 +348,12 @@ class GuiWritingStats(NToolDialog):
sortCol = self.listBox.sortColumn()
sortOrder = header.sortIndicatorOrder() if header else 0
incNovel = self.incNovel.isChecked()
incNotes = self.incNotes.isChecked()
hideZeros = self.hideZeros.isChecked()
hideNegative = self.hideNegative.isChecked()
groupByDay = self.groupByDay.isChecked()
showIdleTime = self.showIdleTime.isChecked()
incNovel = self.swtIncNovel.isChecked()
incNotes = self.swtIncNotes.isChecked()
hideZeros = self.swtHideZeros.isChecked()
hideNegative = self.swtHideNegative.isChecked()
groupByDay = self.swtGroupByDay.isChecked()
showIdleTime = self.swtShowIdleTime.isChecked()
histMax = self.histMax.value()
logger.debug("Saving State: GuiWritingStats")
@@ -487,11 +510,11 @@ class GuiWritingStats(NToolDialog):
self.listBox.clear()
self.timeFilter = 0.0
incNovel = self.incNovel.isChecked()
incNotes = self.incNotes.isChecked()
hideZeros = self.hideZeros.isChecked()
hideNegative = self.hideNegative.isChecked()
groupByDay = self.groupByDay.isChecked()
incNovel = self.swtIncNovel.isChecked()
incNotes = self.swtIncNotes.isChecked()
hideZeros = self.swtHideZeros.isChecked()
hideNegative = self.swtHideNegative.isChecked()
groupByDay = self.swtGroupByDay.isChecked()
histMax = self.histMax.value()
# Group the data
@@ -563,7 +586,7 @@ class GuiWritingStats(NToolDialog):
# Populate the list
mTrans = Qt.TransformationMode.FastTransformation
mAspect = Qt.AspectRatioMode.IgnoreAspectRatio
showIdleTime = self.showIdleTime.isChecked()
showIdleTime = self.swtShowIdleTime.isChecked()
for _, sStart, sDiff, nWords, _, _, sIdle in self.filterData:
if showIdleTime:
+9 -9
View File
@@ -261,7 +261,7 @@ def testToolWritingStats_Filters(qtbot, monkeypatch, nwGUI, projPath, tstPaths):
assert item.text(sessLog.C_COUNT) == f"{200:n}"
# No Novel Files
qtbot.mouseClick(sessLog.incNovel, QtMouseLeft)
qtbot.mouseClick(sessLog.swtIncNovel, QtMouseLeft)
assert sessLog._saveData(sessLog.FMT_JSON)
jsonStats = tstPaths.tmpDir / "sessionStats.json"
@@ -329,8 +329,8 @@ def testToolWritingStats_Filters(qtbot, monkeypatch, nwGUI, projPath, tstPaths):
]
# No Note Files
qtbot.mouseClick(sessLog.incNovel, QtMouseLeft)
qtbot.mouseClick(sessLog.incNotes, QtMouseLeft)
qtbot.mouseClick(sessLog.swtIncNovel, QtMouseLeft)
qtbot.mouseClick(sessLog.swtIncNotes, QtMouseLeft)
assert sessLog._saveData(sessLog.FMT_JSON)
jsonStats = tstPaths.tmpDir / "sessionStats.json"
@@ -398,8 +398,8 @@ def testToolWritingStats_Filters(qtbot, monkeypatch, nwGUI, projPath, tstPaths):
]
# No Negative Entries
qtbot.mouseClick(sessLog.incNotes, QtMouseLeft)
qtbot.mouseClick(sessLog.hideNegative, QtMouseLeft)
qtbot.mouseClick(sessLog.swtIncNotes, QtMouseLeft)
qtbot.mouseClick(sessLog.swtHideNegative, QtMouseLeft)
assert sessLog._saveData(sessLog.FMT_JSON)
jsonStats = tstPaths.tmpDir / "sessionStats.json"
@@ -439,8 +439,8 @@ def testToolWritingStats_Filters(qtbot, monkeypatch, nwGUI, projPath, tstPaths):
]
# Un-hide Zero Entries
qtbot.mouseClick(sessLog.hideNegative, QtMouseLeft)
qtbot.mouseClick(sessLog.hideZeros, QtMouseLeft)
qtbot.mouseClick(sessLog.swtHideNegative, QtMouseLeft)
qtbot.mouseClick(sessLog.swtHideZeros, QtMouseLeft)
assert sessLog._saveData(sessLog.FMT_JSON)
jsonStats = tstPaths.tmpDir / "sessionStats.json"
@@ -526,14 +526,14 @@ def testToolWritingStats_Filters(qtbot, monkeypatch, nwGUI, projPath, tstPaths):
assert item is not None
assert item.text(sessLog.C_IDLE) == "4 %"
qtbot.mouseClick(sessLog.showIdleTime, QtMouseLeft)
qtbot.mouseClick(sessLog.swtShowIdleTime, QtMouseLeft)
item = sessLog.listBox.topLevelItem(7)
assert item is not None
assert item.text(sessLog.C_IDLE) == "00:01:10"
# Group by Day
qtbot.mouseClick(sessLog.groupByDay, QtMouseLeft)
qtbot.mouseClick(sessLog.swtGroupByDay, QtMouseLeft)
assert sessLog._saveData(sessLog.FMT_JSON)
jsonStats = tstPaths.tmpDir / "sessionStats.json"