Update Qt namespace flags

This commit is contained in:
Veronica Berglyd Olsen
2024-04-03 19:28:39 +02:00
parent f95bbb8760
commit 46c5f1c10d
33 changed files with 212 additions and 174 deletions
+5 -4
View File
@@ -26,8 +26,8 @@ from __future__ import annotations
import logging import logging
from PyQt5.QtGui import QCloseEvent
from PyQt5.QtCore import Qt, pyqtSlot from PyQt5.QtCore import Qt, pyqtSlot
from PyQt5.QtGui import QCloseEvent
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAbstractItemView, QDialog, QDialogButtonBox, QGridLayout, QLabel, QAbstractItemView, QDialog, QDialogButtonBox, QGridLayout, QLabel,
QListWidget, QListWidgetItem, QVBoxLayout, QWidget QListWidget, QListWidgetItem, QVBoxLayout, QWidget
@@ -36,13 +36,14 @@ from PyQt5.QtWidgets import (
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.extensions.switch import NSwitch from novelwriter.extensions.switch import NSwitch
from novelwriter.extensions.configlayout import NColourLabel from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.types import QtUserRole
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class GuiDocMerge(QDialog): class GuiDocMerge(QDialog):
D_HANDLE = Qt.ItemDataRole.UserRole D_HANDLE = QtUserRole
def __init__(self, parent: QWidget, sHandle: str, itemList: list[str]) -> None: def __init__(self, parent: QWidget, sHandle: str, itemList: list[str]) -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
@@ -120,7 +121,7 @@ class GuiDocMerge(QDialog):
finalItems = [] finalItems = []
for i in range(self.listBox.count()): for i in range(self.listBox.count()):
item = self.listBox.item(i) item = self.listBox.item(i)
if item is not None and item.checkState() == Qt.Checked: if item is not None and item.checkState() == Qt.CheckState.Checked:
finalItems.append(item.data(self.D_HANDLE)) finalItems.append(item.data(self.D_HANDLE))
self._data["moveToTrash"] = self.trashSwitch.isChecked() self._data["moveToTrash"] = self.trashSwitch.isChecked()
@@ -175,7 +176,7 @@ class GuiDocMerge(QDialog):
newItem.setIcon(itemIcon) newItem.setIcon(itemIcon)
newItem.setText(nwItem.itemName) newItem.setText(nwItem.itemName)
newItem.setData(self.D_HANDLE, tHandle) newItem.setData(self.D_HANDLE, tHandle)
newItem.setCheckState(Qt.Checked) newItem.setCheckState(Qt.CheckState.Checked)
self.listBox.addItem(newItem) self.listBox.addItem(newItem)
+5 -4
View File
@@ -26,8 +26,8 @@ from __future__ import annotations
import logging import logging
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtGui import QCloseEvent from PyQt5.QtGui import QCloseEvent
from PyQt5.QtCore import Qt, pyqtSlot
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAbstractItemView, QComboBox, QDialog, QDialogButtonBox, QGridLayout, QAbstractItemView, QComboBox, QDialog, QDialogButtonBox, QGridLayout,
QLabel, QListWidget, QListWidgetItem, QVBoxLayout, QWidget QLabel, QListWidget, QListWidgetItem, QVBoxLayout, QWidget
@@ -36,15 +36,16 @@ from PyQt5.QtWidgets import (
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.extensions.switch import NSwitch from novelwriter.extensions.switch import NSwitch
from novelwriter.extensions.configlayout import NColourLabel from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.types import QtUserRole
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class GuiDocSplit(QDialog): class GuiDocSplit(QDialog):
LINE_ROLE = Qt.ItemDataRole.UserRole LINE_ROLE = QtUserRole
LEVEL_ROLE = Qt.ItemDataRole.UserRole + 1 LEVEL_ROLE = QtUserRole + 1
LABEL_ROLE = Qt.ItemDataRole.UserRole + 2 LABEL_ROLE = QtUserRole + 2
def __init__(self, parent: QWidget, sHandle: str) -> None: def __init__(self, parent: QWidget, sHandle: str) -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
+5 -4
View File
@@ -40,6 +40,7 @@ from novelwriter.extensions.configlayout import NColourLabel, NFixedPage, NScrol
from novelwriter.extensions.modified import NComboBox, NIconToolButton from novelwriter.extensions.modified import NComboBox, NIconToolButton
from novelwriter.extensions.pagedsidebar import NPagedSideBar from novelwriter.extensions.pagedsidebar import NPagedSideBar
from novelwriter.extensions.switch import NSwitch from novelwriter.extensions.switch import NSwitch
from novelwriter.types import QtUserRole
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -305,9 +306,9 @@ class _StatusPage(NFixedPage):
COL_LABEL = 0 COL_LABEL = 0
COL_USAGE = 1 COL_USAGE = 1
KEY_ROLE = Qt.ItemDataRole.UserRole KEY_ROLE = QtUserRole
COL_ROLE = Qt.ItemDataRole.UserRole + 1 COL_ROLE = QtUserRole + 1
NUM_ROLE = Qt.ItemDataRole.UserRole + 2 NUM_ROLE = QtUserRole + 2
def __init__(self, parent: QWidget, isStatus: bool) -> None: def __init__(self, parent: QWidget, isStatus: bool) -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
@@ -614,7 +615,7 @@ class _ReplacePage(NFixedPage):
newItem = QTreeWidgetItem(["<%s>" % aKey, aVal]) newItem = QTreeWidgetItem(["<%s>" % aKey, aVal])
self.listBox.addTopLevelItem(newItem) self.listBox.addTopLevelItem(newItem)
self.listBox.sortByColumn(self.COL_KEY, Qt.AscendingOrder) self.listBox.sortByColumn(self.COL_KEY, Qt.SortOrder.AscendingOrder)
self.listBox.setSortingEnabled(True) self.listBox.setSortingEnabled(True)
# List Controls # List Controls
+3 -3
View File
@@ -26,7 +26,7 @@ from __future__ import annotations
import logging import logging
from PyQt5.QtGui import QFontMetrics from PyQt5.QtGui import QFontMetrics
from PyQt5.QtCore import QSize, Qt, pyqtSlot from PyQt5.QtCore import QSize, pyqtSlot
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QDialog, QDialogButtonBox, QFrame, QHBoxLayout, QLabel, QListWidget, QDialog, QDialogButtonBox, QFrame, QHBoxLayout, QLabel, QListWidget,
QListWidgetItem, QVBoxLayout, QWidget QListWidgetItem, QVBoxLayout, QWidget
@@ -34,7 +34,7 @@ from PyQt5.QtWidgets import (
from novelwriter import CONFIG from novelwriter import CONFIG
from novelwriter.constants import trConst, nwQuotes from novelwriter.constants import trConst, nwQuotes
from novelwriter.types import QtAlignCenter, QtAlignTop from novelwriter.types import QtAlignCenter, QtAlignTop, QtUserRole
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -43,7 +43,7 @@ class GuiQuoteSelect(QDialog):
_selected = "" _selected = ""
D_KEY = Qt.ItemDataRole.UserRole D_KEY = QtUserRole
def __init__(self, parent: QWidget, current: str = '"') -> None: def __init__(self, parent: QWidget, current: str = '"') -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
+2 -2
View File
@@ -157,7 +157,7 @@ class GuiWordList(QDialog):
self.newEntry.setText("") self.newEntry.setText("")
self.listBox.clearSelection() self.listBox.clearSelection()
self._addWord(word) self._addWord(word)
if items := self.listBox.findItems(word, Qt.MatchExactly): if items := self.listBox.findItems(word, Qt.MatchFlag.MatchExactly):
self.listBox.setCurrentItem(items[0]) self.listBox.setCurrentItem(items[0])
self.listBox.scrollToItem(items[0], QAbstractItemView.ScrollHint.PositionAtCenter) self.listBox.scrollToItem(items[0], QAbstractItemView.ScrollHint.PositionAtCenter)
return return
@@ -244,7 +244,7 @@ class GuiWordList(QDialog):
def _addWord(self, word: str) -> None: def _addWord(self, word: str) -> None:
"""Add a single word to the list.""" """Add a single word to the list."""
if word and not self.listBox.findItems(word, Qt.MatchExactly): if word and not self.listBox.findItems(word, Qt.MatchFlag.MatchExactly):
self.listBox.addItem(word) self.listBox.addItem(word)
self._changed = True self._changed = True
return return
+6 -6
View File
@@ -25,11 +25,11 @@ from __future__ import annotations
from math import ceil from math import ceil
from PyQt5.QtCore import QRect
from PyQt5.QtGui import QBrush, QColor, QPaintEvent, QPainter, QPen from PyQt5.QtGui import QBrush, QColor, QPaintEvent, QPainter, QPen
from PyQt5.QtCore import QRect, Qt
from PyQt5.QtWidgets import QProgressBar, QSizePolicy, QWidget from PyQt5.QtWidgets import QProgressBar, QSizePolicy, QWidget
from novelwriter.types import QtAlignCenter from novelwriter.types import QtAlignCenter, QtRoundCap, QtSolidLine, QtTransparent
class NProgressCircle(QProgressBar): class NProgressCircle(QProgressBar):
@@ -50,8 +50,8 @@ class NProgressCircle(QProgressBar):
self._point = point self._point = point
self._dRect = QRect(0, 0, size, size) self._dRect = QRect(0, 0, size, size)
self._cRect = QRect(point, point, size - 2*point, size - 2*point) self._cRect = QRect(point, point, size - 2*point, size - 2*point)
self._dPen = QPen(Qt.transparent) self._dPen = QPen(QtTransparent)
self._dBrush = QBrush(Qt.transparent) self._dBrush = QBrush(QtTransparent)
self.setColours( self.setColours(
track=self.palette().alternateBase().color(), track=self.palette().alternateBase().color(),
bar=self.palette().highlight().color(), bar=self.palette().highlight().color(),
@@ -69,9 +69,9 @@ class NProgressCircle(QProgressBar):
self._dPen = QPen(back) self._dPen = QPen(back)
self._dBrush = QBrush(back) self._dBrush = QBrush(back)
if isinstance(bar, QColor): if isinstance(bar, QColor):
self._cPen = QPen(QBrush(bar), self._point, Qt.SolidLine, Qt.RoundCap) self._cPen = QPen(QBrush(bar), self._point, QtSolidLine, QtRoundCap)
if isinstance(track, QColor): if isinstance(track, QColor):
self._bPen = QPen(QBrush(track), self._point, Qt.SolidLine, Qt.RoundCap) self._bPen = QPen(QBrush(track), self._point, QtSolidLine, QtRoundCap)
if isinstance(text, QColor): if isinstance(text, QColor):
self._tColor = text self._tColor = text
return return
+5 -5
View File
@@ -32,7 +32,7 @@ from PyQt5.QtWidgets import (
QStyleOptionToolButton, QToolBar, QToolButton, QWidget QStyleOptionToolButton, QToolBar, QToolButton, QWidget
) )
from novelwriter.types import QtAlignLeft from novelwriter.types import QtAlignLeft, QtNoBrush, QtNoPen
class NPagedSideBar(QToolBar): class NPagedSideBar(QToolBar):
@@ -56,7 +56,7 @@ class NPagedSideBar(QToolBar):
self._group.buttonClicked.connect(self._buttonClicked) self._group.buttonClicked.connect(self._buttonClicked)
self.setMovable(False) self.setMovable(False)
self.setOrientation(Qt.Vertical) self.setOrientation(Qt.Orientation.Vertical)
stretch = QWidget(self) stretch = QWidget(self)
stretch.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) stretch.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
@@ -146,8 +146,8 @@ class _NPagedToolButton(QToolButton):
paint = QPainter(self) paint = QPainter(self)
paint.setRenderHint(QPainter.Antialiasing, True) paint.setRenderHint(QPainter.Antialiasing, True)
paint.setPen(Qt.NoPen) paint.setPen(QtNoPen)
paint.setBrush(Qt.NoBrush) paint.setBrush(QtNoBrush)
width = self.width() width = self.width()
height = self.height() height = self.height()
@@ -215,7 +215,7 @@ class _NPagedToolLabel(QLabel):
""" """
paint = QPainter(self) paint = QPainter(self)
paint.setRenderHint(QPainter.Antialiasing, True) paint.setRenderHint(QPainter.Antialiasing, True)
paint.setPen(Qt.NoPen) paint.setPen(QtNoPen)
width = self.width() width = self.width()
height = self.height() height = self.height()
+4 -3
View File
@@ -28,6 +28,7 @@ from PyQt5.QtCore import QEvent, QPropertyAnimation, Qt, pyqtProperty
from PyQt5.QtWidgets import QAbstractButton, QSizePolicy, QWidget from PyQt5.QtWidgets import QAbstractButton, QSizePolicy, QWidget
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.types import QtMouseLeft, QtNoPen
class NSwitch(QAbstractButton): class NSwitch(QAbstractButton):
@@ -90,7 +91,7 @@ class NSwitch(QAbstractButton):
"""Drawing the switch itself.""" """Drawing the switch itself."""
painter = QPainter(self) painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QPainter.Antialiasing, True)
painter.setPen(Qt.NoPen) painter.setPen(QtNoPen)
palette = self.palette() palette = self.palette()
if self.isChecked(): if self.isChecked():
@@ -119,7 +120,7 @@ class NSwitch(QAbstractButton):
def mouseReleaseEvent(self, event: QMouseEvent) -> None: def mouseReleaseEvent(self, event: QMouseEvent) -> None:
"""Animate the switch on mouse release.""" """Animate the switch on mouse release."""
super().mouseReleaseEvent(event) super().mouseReleaseEvent(event)
if event.button() == Qt.LeftButton: if event.button() == QtMouseLeft:
anim = QPropertyAnimation(self, b"offset", self) anim = QPropertyAnimation(self, b"offset", self)
anim.setDuration(120) anim.setDuration(120)
anim.setStartValue(self._offset) anim.setStartValue(self._offset)
@@ -129,7 +130,7 @@ class NSwitch(QAbstractButton):
def enterEvent(self, event: QEvent) -> None: def enterEvent(self, event: QEvent) -> None:
"""Change the cursor when hovering the button.""" """Change the cursor when hovering the button."""
self.setCursor(Qt.PointingHandCursor) self.setCursor(Qt.CursorShape.PointingHandCursor)
super().enterEvent(event) super().enterEvent(event)
return return
+8 -9
View File
@@ -64,7 +64,8 @@ from novelwriter.gui.theme import STYLES_MIN_TOOLBUTTON
from novelwriter.text.counting import standardCounter from novelwriter.text.counting import standardCounter
from novelwriter.tools.lipsum import GuiLipsum from novelwriter.tools.lipsum import GuiLipsum
from novelwriter.types import ( from novelwriter.types import (
QtAlignCenterTop, QtAlignJustify, QtAlignLeft, QtAlignLeftTop, QtAlignRight QtAlignCenterTop, QtAlignJustify, QtAlignLeft, QtAlignLeftTop,
QtAlignRight, QtModCtrl, QtMouseLeft, QtModeNone, QtModShift
) )
if TYPE_CHECKING: # pragma: no cover if TYPE_CHECKING: # pragma: no cover
@@ -181,12 +182,12 @@ class GuiDocEditor(QPlainTextEdit):
self.keyContext.activated.connect(self._openContextFromCursor) self.keyContext.activated.connect(self._openContextFromCursor)
self.followTag1 = QShortcut(self) self.followTag1 = QShortcut(self)
self.followTag1.setKey(Qt.Key.Key_Return | Qt.KeyboardModifier.ControlModifier) self.followTag1.setKey(Qt.Key.Key_Return | QtModCtrl)
self.followTag1.setContext(Qt.ShortcutContext.WidgetShortcut) self.followTag1.setContext(Qt.ShortcutContext.WidgetShortcut)
self.followTag1.activated.connect(self._processTag) self.followTag1.activated.connect(self._processTag)
self.followTag2 = QShortcut(self) self.followTag2 = QShortcut(self)
self.followTag2.setKey(Qt.Key.Key_Enter | Qt.KeyboardModifier.ControlModifier) self.followTag2.setKey(Qt.Key.Key_Enter | QtModCtrl)
self.followTag2.setContext(Qt.ShortcutContext.WidgetShortcut) self.followTag2.setContext(Qt.ShortcutContext.WidgetShortcut)
self.followTag2.activated.connect(self._processTag) self.followTag2.activated.connect(self._processTag)
@@ -962,7 +963,7 @@ class GuiDocEditor(QPlainTextEdit):
super().keyPressEvent(event) super().keyPressEvent(event)
nPos = self.cursorRect().topLeft().y() nPos = self.cursorRect().topLeft().y()
kMod = event.modifiers() kMod = event.modifiers()
okMod = kMod in (Qt.KeyboardModifier.NoModifier, Qt.KeyboardModifier.ShiftModifier) okMod = kMod in (QtModeNone, QtModShift)
okKey = event.key() not in self.MOVE_KEYS okKey = event.key() not in self.MOVE_KEYS
if nPos != cPos and okMod and okKey: if nPos != cPos and okMod and okKey:
mPos = CONFIG.autoScrollPos*0.01 * self.viewport().height() mPos = CONFIG.autoScrollPos*0.01 * self.viewport().height()
@@ -991,7 +992,7 @@ class GuiDocEditor(QPlainTextEdit):
pressed, check if we're clicking on a tag, and trigger the pressed, check if we're clicking on a tag, and trigger the
follow tag function. follow tag function.
""" """
if QApplication.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier: if QApplication.keyboardModifiers() == QtModCtrl:
self._processTag(self.cursorForPosition(event.pos())) self._processTag(self.cursorForPosition(event.pos()))
super().mouseReleaseEvent(event) super().mouseReleaseEvent(event)
return return
@@ -2713,9 +2714,7 @@ class GuiDocEditSearch(QFrame):
@pyqtSlot() @pyqtSlot()
def _doSearch(self) -> None: def _doSearch(self) -> None:
"""Call the search action function for the document editor.""" """Call the search action function for the document editor."""
self.docEditor.findNext(goBack=( self.docEditor.findNext(goBack=(QApplication.keyboardModifiers() == QtModShift))
QApplication.keyboardModifiers() == Qt.KeyboardModifier.ShiftModifier)
)
return return
@pyqtSlot() @pyqtSlot()
@@ -3002,7 +3001,7 @@ class GuiDocEditHeader(QWidget):
"""Capture a click on the title and ensure that the item is """Capture a click on the title and ensure that the item is
selected in the project tree. selected in the project tree.
""" """
if event.button() == Qt.MouseButton.LeftButton: if event.button() == QtMouseLeft:
self.docEditor.requestProjectItemSelected.emit(self._docHandle or "", True) self.docEditor.requestProjectItemSelected.emit(self._docHandle or "", True)
return return
+3 -3
View File
@@ -402,16 +402,16 @@ class GuiDocHighlighter(QSyntaxHighlighter):
if style is not None: if style is not None:
styles = style.split(",") styles = style.split(",")
if "bold" in styles: if "bold" in styles:
charFormat.setFontWeight(QFont.Bold) charFormat.setFontWeight(QFont.Weight.Bold)
if "italic" in styles: if "italic" in styles:
charFormat.setFontItalic(True) charFormat.setFontItalic(True)
if "strike" in styles: if "strike" in styles:
charFormat.setFontStrikeOut(True) charFormat.setFontStrikeOut(True)
if "errline" in styles: if "errline" in styles:
charFormat.setUnderlineColor(SHARED.theme.colError) charFormat.setUnderlineColor(SHARED.theme.colError)
charFormat.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline) charFormat.setUnderlineStyle(QTextCharFormat.UnderlineStyle.SpellCheckUnderline)
if "background" in styles and color is not None: if "background" in styles and color is not None:
charFormat.setBackground(QBrush(color, Qt.SolidPattern)) charFormat.setBackground(QBrush(color, Qt.BrushStyle.SolidPattern))
if size is not None: if size is not None:
charFormat.setFontPointSize(int(round(size*CONFIG.textSize))) charFormat.setFontPointSize(int(round(size*CONFIG.textSize)))
+2 -2
View File
@@ -49,7 +49,7 @@ from novelwriter.error import logException
from novelwriter.extensions.eventfilters import WheelEventFilter from novelwriter.extensions.eventfilters import WheelEventFilter
from novelwriter.extensions.modified import NIconToolButton from novelwriter.extensions.modified import NIconToolButton
from novelwriter.gui.theme import STYLES_MIN_TOOLBUTTON from novelwriter.gui.theme import STYLES_MIN_TOOLBUTTON
from novelwriter.types import QtAlignCenterTop, QtAlignJustify from novelwriter.types import QtAlignCenterTop, QtAlignJustify, QtMouseLeft
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -826,7 +826,7 @@ class GuiDocViewHeader(QWidget):
"""Capture a click on the title and ensure that the item is """Capture a click on the title and ensure that the item is
selected in the project tree. selected in the project tree.
""" """
if event.button() == Qt.MouseButton.LeftButton: if event.button() == QtMouseLeft:
self.docViewer.requestProjectItemSelected.emit(self._docHandle, True) self.docViewer.requestProjectItemSelected.emit(self._docHandle, True)
return return
+5 -4
View File
@@ -40,6 +40,7 @@ from novelwriter.core.index import IndexHeading, IndexItem
from novelwriter.enum import nwDocMode, nwItemClass from novelwriter.enum import nwDocMode, nwItemClass
from novelwriter.extensions.modified import NIconToolButton from novelwriter.extensions.modified import NIconToolButton
from novelwriter.gui.theme import STYLES_FLAT_TABS, STYLES_MIN_TOOLBUTTON from novelwriter.gui.theme import STYLES_FLAT_TABS, STYLES_MIN_TOOLBUTTON
from novelwriter.types import QtDecoration, QtUserRole
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -232,7 +233,7 @@ class _ViewPanelBackRefs(QTreeWidget):
C_VIEW = 2 C_VIEW = 2
C_TITLE = 3 C_TITLE = 3
D_HANDLE = Qt.ItemDataRole.UserRole D_HANDLE = QtUserRole
def __init__(self, parent: GuiDocViewerPanel) -> None: def __init__(self, parent: GuiDocViewerPanel) -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
@@ -349,7 +350,7 @@ class _ViewPanelBackRefs(QTreeWidget):
trItem.setToolTip(self.C_DOC, nwItem.itemName) trItem.setToolTip(self.C_DOC, nwItem.itemName)
trItem.setIcon(self.C_EDIT, self._editIcon) trItem.setIcon(self.C_EDIT, self._editIcon)
trItem.setIcon(self.C_VIEW, self._viewIcon) trItem.setIcon(self.C_VIEW, self._viewIcon)
trItem.setData(self.C_TITLE, Qt.ItemDataRole.DecorationRole, hDec) trItem.setData(self.C_TITLE, QtDecoration, hDec)
trItem.setText(self.C_TITLE, hItem.title) trItem.setText(self.C_TITLE, hItem.title)
trItem.setToolTip(self.C_TITLE, hItem.title) trItem.setToolTip(self.C_TITLE, hItem.title)
trItem.setData(self.C_DATA, self.D_HANDLE, tHandle) trItem.setData(self.C_DATA, self.D_HANDLE, tHandle)
@@ -374,7 +375,7 @@ class _ViewPanelKeyWords(QTreeWidget):
C_TITLE = 5 C_TITLE = 5
C_SHORT = 6 C_SHORT = 6
D_TAG = Qt.ItemDataRole.UserRole D_TAG = QtUserRole
def __init__(self, parent: GuiDocViewerPanel, itemClass: nwItemClass) -> None: def __init__(self, parent: GuiDocViewerPanel, itemClass: nwItemClass) -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
@@ -468,7 +469,7 @@ class _ViewPanelKeyWords(QTreeWidget):
trItem.setIcon(self.C_DOC, docIcon) trItem.setIcon(self.C_DOC, docIcon)
trItem.setText(self.C_DOC, nwItem.itemName) trItem.setText(self.C_DOC, nwItem.itemName)
trItem.setToolTip(self.C_DOC, nwItem.itemName) trItem.setToolTip(self.C_DOC, nwItem.itemName)
trItem.setData(self.C_TITLE, Qt.ItemDataRole.DecorationRole, hDec) trItem.setData(self.C_TITLE, QtDecoration, hDec)
trItem.setText(self.C_TITLE, hItem.title) trItem.setText(self.C_TITLE, hItem.title)
trItem.setToolTip(self.C_TITLE, hItem.title) trItem.setToolTip(self.C_TITLE, hItem.title)
trItem.setText(self.C_SHORT, hItem.synopsis) trItem.setText(self.C_SHORT, hItem.synopsis)
+10 -10
View File
@@ -31,8 +31,8 @@ from enum import Enum
from time import time from time import time
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from PyQt5.QtGui import QFocusEvent, QFont, QMouseEvent, QPalette, QResizeEvent
from PyQt5.QtCore import QModelIndex, QPoint, Qt, pyqtSlot, pyqtSignal from PyQt5.QtCore import QModelIndex, QPoint, Qt, pyqtSlot, pyqtSignal
from PyQt5.QtGui import QFocusEvent, QFont, QMouseEvent, QPalette, QResizeEvent
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAbstractItemView, QActionGroup, QFrame, QHBoxLayout, QHeaderView, QAbstractItemView, QActionGroup, QFrame, QHBoxLayout, QHeaderView,
QInputDialog, QMenu, QSizePolicy, QToolTip, QTreeWidget, QTreeWidgetItem, QInputDialog, QMenu, QSizePolicy, QToolTip, QTreeWidget, QTreeWidgetItem,
@@ -47,7 +47,7 @@ from novelwriter.enum import nwDocMode, nwItemClass, nwOutline
from novelwriter.extensions.modified import NIconToolButton from novelwriter.extensions.modified import NIconToolButton
from novelwriter.extensions.novelselector import NovelSelector from novelwriter.extensions.novelselector import NovelSelector
from novelwriter.gui.theme import STYLES_MIN_TOOLBUTTON from novelwriter.gui.theme import STYLES_MIN_TOOLBUTTON
from novelwriter.types import QtAlignRight from novelwriter.types import QtAlignRight, QtDecoration, QtMouseLeft, QtMouseMiddle, QtUserRole
if TYPE_CHECKING: # pragma: no cover if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain from novelwriter.guimain import GuiMain
@@ -364,10 +364,10 @@ class GuiNovelTree(QTreeWidget):
C_EXTRA = 2 C_EXTRA = 2
C_MORE = 3 C_MORE = 3
D_HANDLE = Qt.ItemDataRole.UserRole D_HANDLE = QtUserRole
D_TITLE = Qt.ItemDataRole.UserRole + 1 D_TITLE = QtUserRole + 1
D_KEY = Qt.ItemDataRole.UserRole + 2 D_KEY = QtUserRole + 2
D_EXTRA = Qt.ItemDataRole.UserRole + 3 D_EXTRA = QtUserRole + 3
def __init__(self, novelView: GuiNovelView) -> None: def __init__(self, novelView: GuiNovelView) -> None:
super().__init__(parent=novelView) super().__init__(parent=novelView)
@@ -583,12 +583,12 @@ class GuiNovelTree(QTreeWidget):
""" """
super().mousePressEvent(event) super().mousePressEvent(event)
if event.button() == Qt.MouseButton.LeftButton: if event.button() == QtMouseLeft:
selItem = self.indexAt(event.pos()) selItem = self.indexAt(event.pos())
if not selItem.isValid(): if not selItem.isValid():
self.clearSelection() self.clearSelection()
elif event.button() == Qt.MouseButton.MiddleButton: elif event.button() == QtMouseMiddle:
selItem = self.itemAt(event.pos()) selItem = self.itemAt(event.pos())
if not isinstance(selItem, QTreeWidgetItem): if not isinstance(selItem, QTreeWidgetItem):
return return
@@ -697,11 +697,11 @@ class GuiNovelTree(QTreeWidget):
iLevel = nwHeaders.H_LEVEL.get(idxItem.level, 0) iLevel = nwHeaders.H_LEVEL.get(idxItem.level, 0)
hDec = SHARED.theme.getHeaderDecoration(iLevel) hDec = SHARED.theme.getHeaderDecoration(iLevel)
trItem.setData(self.C_TITLE, Qt.ItemDataRole.DecorationRole, hDec) trItem.setData(self.C_TITLE, QtDecoration, hDec)
trItem.setText(self.C_TITLE, idxItem.title) trItem.setText(self.C_TITLE, idxItem.title)
trItem.setFont(self.C_TITLE, self._hFonts[iLevel]) trItem.setFont(self.C_TITLE, self._hFonts[iLevel])
trItem.setText(self.C_WORDS, f"{idxItem.wordCount:n}") trItem.setText(self.C_WORDS, f"{idxItem.wordCount:n}")
trItem.setData(self.C_MORE, Qt.ItemDataRole.DecorationRole, self._pMore) trItem.setData(self.C_MORE, QtDecoration, self._pMore)
# Custom column # Custom column
mW = int(self._lastColSize * self.viewport().width()) mW = int(self._lastColSize * self.viewport().width())
+7 -5
View File
@@ -48,7 +48,9 @@ from novelwriter.error import logException
from novelwriter.common import checkInt, formatFileFilter, makeFileNameSafe from novelwriter.common import checkInt, formatFileFilter, makeFileNameSafe
from novelwriter.constants import nwHeaders, trConst, nwKeyWords, nwLabels from novelwriter.constants import nwHeaders, trConst, nwKeyWords, nwLabels
from novelwriter.extensions.novelselector import NovelSelector from novelwriter.extensions.novelselector import NovelSelector
from novelwriter.types import QtAlignLeftTop, QtAlignRight, QtAlignRightTop from novelwriter.types import (
QtAlignLeftTop, QtAlignRight, QtAlignRightTop, QtDecoration, QtUserRole
)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -68,7 +70,7 @@ class GuiOutlineView(QWidget):
self.outlineBar = GuiOutlineToolBar(self) self.outlineBar = GuiOutlineToolBar(self)
self.outlineBar.setEnabled(False) self.outlineBar.setEnabled(False)
self.splitOutline = QSplitter(Qt.Vertical) self.splitOutline = QSplitter(Qt.Orientation.Vertical)
self.splitOutline.addWidget(self.outlineTree) self.splitOutline.addWidget(self.outlineTree)
self.splitOutline.addWidget(self.outlineData) self.splitOutline.addWidget(self.outlineData)
self.splitOutline.setOpaqueResize(False) self.splitOutline.setOpaqueResize(False)
@@ -354,8 +356,8 @@ class GuiOutlineTree(QTreeWidget):
nwOutline.SYNOP: False, nwOutline.SYNOP: False,
} }
D_HANDLE = Qt.ItemDataRole.UserRole D_HANDLE = QtUserRole
D_TITLE = Qt.ItemDataRole.UserRole + 1 D_TITLE = QtUserRole + 1
hiddenStateChanged = pyqtSignal() hiddenStateChanged = pyqtSignal()
activeItemChanged = pyqtSignal(str, str) activeItemChanged = pyqtSignal(str, str)
@@ -692,7 +694,7 @@ class GuiOutlineTree(QTreeWidget):
trItem = QTreeWidgetItem() trItem = QTreeWidgetItem()
hDec = SHARED.theme.getHeaderDecoration(iLevel) hDec = SHARED.theme.getHeaderDecoration(iLevel)
trItem.setData(self._colIdx[nwOutline.TITLE], Qt.ItemDataRole.DecorationRole, hDec) trItem.setData(self._colIdx[nwOutline.TITLE], QtDecoration, hDec)
trItem.setText(self._colIdx[nwOutline.TITLE], novIdx.title) trItem.setText(self._colIdx[nwOutline.TITLE], novIdx.title)
trItem.setData(self._colIdx[nwOutline.TITLE], self.D_HANDLE, tHandle) trItem.setData(self._colIdx[nwOutline.TITLE], self.D_HANDLE, tHandle)
trItem.setData(self._colIdx[nwOutline.TITLE], self.D_TITLE, sTitle) trItem.setData(self._colIdx[nwOutline.TITLE], self.D_TITLE, sTitle)
+7 -7
View File
@@ -32,10 +32,10 @@ from enum import Enum
from time import time from time import time
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from PyQt5.QtCore import QPoint, QTimer, Qt, pyqtSignal, pyqtSlot
from PyQt5.QtGui import ( from PyQt5.QtGui import (
QDragEnterEvent, QDragMoveEvent, QDropEvent, QIcon, QMouseEvent, QPalette QDragEnterEvent, QDragMoveEvent, QDropEvent, QIcon, QMouseEvent, QPalette
) )
from PyQt5.QtCore import QPoint, QTimer, Qt, pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAbstractItemView, QAction, QDialog, QFrame, QHBoxLayout, QHeaderView, QAbstractItemView, QAction, QDialog, QFrame, QHBoxLayout, QHeaderView,
QLabel, QMenu, QShortcut, QSizePolicy, QTreeWidget, QTreeWidgetItem, QLabel, QMenu, QShortcut, QSizePolicy, QTreeWidget, QTreeWidgetItem,
@@ -54,7 +54,7 @@ from novelwriter.dialogs.projectsettings import GuiProjectSettings
from novelwriter.enum import nwDocMode, nwItemType, nwItemClass, nwItemLayout from novelwriter.enum import nwDocMode, nwItemType, nwItemClass, nwItemLayout
from novelwriter.extensions.modified import NIconToolButton from novelwriter.extensions.modified import NIconToolButton
from novelwriter.gui.theme import STYLES_MIN_TOOLBUTTON from novelwriter.gui.theme import STYLES_MIN_TOOLBUTTON
from novelwriter.types import QtAlignLeft, QtAlignRight from novelwriter.types import QtAlignLeft, QtAlignRight, QtMouseLeft, QtMouseMiddle, QtUserRole
if TYPE_CHECKING: # pragma: no cover if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain from novelwriter.guimain import GuiMain
@@ -487,8 +487,8 @@ class GuiProjectTree(QTreeWidget):
C_ACTIVE = 2 C_ACTIVE = 2
C_STATUS = 3 C_STATUS = 3
D_HANDLE = Qt.ItemDataRole.UserRole D_HANDLE = QtUserRole
D_WORDS = Qt.ItemDataRole.UserRole + 1 D_WORDS = QtUserRole + 1
itemRefreshed = pyqtSignal(str, NWItem, QIcon) itemRefreshed = pyqtSignal(str, NWItem, QIcon)
@@ -1256,11 +1256,11 @@ class GuiProjectTree(QTreeWidget):
for viewing if the user middle-clicked. for viewing if the user middle-clicked.
""" """
super().mousePressEvent(event) super().mousePressEvent(event)
if event.button() == Qt.MouseButton.LeftButton: if event.button() == QtMouseLeft:
selItem = self.indexAt(event.pos()) selItem = self.indexAt(event.pos())
if not selItem.isValid(): if not selItem.isValid():
self.clearSelection() self.clearSelection()
elif event.button() == Qt.MouseButton.MiddleButton: elif event.button() == QtMouseMiddle:
selItem = self.itemAt(event.pos()) selItem = self.itemAt(event.pos())
if selItem: if selItem:
tHandle = selItem.data(self.C_DATA, self.D_HANDLE) tHandle = selItem.data(self.C_DATA, self.D_HANDLE)
@@ -1268,7 +1268,7 @@ class GuiProjectTree(QTreeWidget):
self.projView.openDocumentRequest.emit(tHandle, nwDocMode.VIEW, "", False) self.projView.openDocumentRequest.emit(tHandle, nwDocMode.VIEW, "", False)
return return
def startDrag(self, dropAction: Qt.DropActions) -> None: def startDrag(self, dropAction: Qt.DropAction) -> None:
"""Capture the drag and drop handling to pop alerts.""" """Capture the drag and drop handling to pop alerts."""
super().startDrag(dropAction) super().startDrag(dropAction)
if self._popAlert: if self._popAlert:
+3 -3
View File
@@ -38,7 +38,7 @@ from novelwriter import CONFIG, SHARED
from novelwriter.common import checkInt, cssCol from novelwriter.common import checkInt, cssCol
from novelwriter.core.coretools import DocSearch from novelwriter.core.coretools import DocSearch
from novelwriter.core.item import NWItem from novelwriter.core.item import NWItem
from novelwriter.types import QtAlignMiddle, QtAlignRight from novelwriter.types import QtAlignMiddle, QtAlignRight, QtUserRole
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -49,8 +49,8 @@ class GuiProjectSearch(QWidget):
C_RESULT = 0 C_RESULT = 0
C_COUNT = 1 C_COUNT = 1
D_HANDLE = Qt.ItemDataRole.UserRole D_HANDLE = QtUserRole
D_RESULT = Qt.ItemDataRole.UserRole + 1 D_RESULT = QtUserRole + 1
selectedItemChanged = pyqtSignal(str) selectedItemChanged = pyqtSignal(str)
openDocumentSelectRequest = pyqtSignal(str, int, int, bool) openDocumentSelectRequest = pyqtSignal(str, int, int, bool)
+9 -8
View File
@@ -148,7 +148,7 @@ class GuiMain(QMainWindow):
self.treePane.setLayout(self.treeBox) self.treePane.setLayout(self.treeBox)
# Splitter : Document Viewer / Document Meta # Splitter : Document Viewer / Document Meta
self.splitView = QSplitter(Qt.Vertical, self) self.splitView = QSplitter(Qt.Orientation.Vertical, self)
self.splitView.addWidget(self.docViewer) self.splitView.addWidget(self.docViewer)
self.splitView.addWidget(self.docViewerPanel) self.splitView.addWidget(self.docViewerPanel)
self.splitView.setHandleWidth(hWd) self.splitView.setHandleWidth(hWd)
@@ -158,7 +158,7 @@ class GuiMain(QMainWindow):
self.splitView.setCollapsible(1, False) self.splitView.setCollapsible(1, False)
# Splitter : Document Editor / Document Viewer # Splitter : Document Editor / Document Viewer
self.splitDocs = QSplitter(Qt.Horizontal, self) self.splitDocs = QSplitter(Qt.Orientation.Horizontal, self)
self.splitDocs.addWidget(self.docEditor) self.splitDocs.addWidget(self.docEditor)
self.splitDocs.addWidget(self.splitView) self.splitDocs.addWidget(self.splitView)
self.splitDocs.setOpaqueResize(False) self.splitDocs.setOpaqueResize(False)
@@ -167,7 +167,7 @@ class GuiMain(QMainWindow):
self.splitDocs.setCollapsible(1, False) self.splitDocs.setCollapsible(1, False)
# Splitter : Project Tree / Document Area # Splitter : Project Tree / Document Area
self.splitMain = QSplitter(Qt.Horizontal) self.splitMain = QSplitter(Qt.Orientation.Horizontal)
self.splitMain.setContentsMargins(0, 0, 0, 0) self.splitMain.setContentsMargins(0, 0, 0, 0)
self.splitMain.addWidget(self.treePane) self.splitMain.addWidget(self.treePane)
self.splitMain.addWidget(self.splitDocs) self.splitMain.addWidget(self.splitDocs)
@@ -205,7 +205,7 @@ class GuiMain(QMainWindow):
self.setMenuBar(self.mainMenu) self.setMenuBar(self.mainMenu)
self.setCentralWidget(self.mainWidget) self.setCentralWidget(self.mainWidget)
self.setStatusBar(self.mainStatus) self.setStatusBar(self.mainStatus)
self.setContextMenuPolicy(Qt.NoContextMenu) # Issue #1147 self.setContextMenuPolicy(Qt.ContextMenuPolicy.NoContextMenu) # Issue #1147
# Connect Signals # Connect Signals
# =============== # ===============
@@ -738,7 +738,7 @@ class GuiMain(QMainWindow):
"""Rebuild the entire index.""" """Rebuild the entire index."""
if SHARED.hasProject: if SHARED.hasProject:
logger.info("Rebuilding index ...") logger.info("Rebuilding index ...")
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))
tStart = time() tStart = time()
self.projView.saveProjectTasks() self.projView.saveProjectTasks()
@@ -899,7 +899,8 @@ class GuiMain(QMainWindow):
CONFIG.setViewPanePos(self.splitView.sizes()) CONFIG.setViewPanePos(self.splitView.sizes())
CONFIG.showViewerPanel = self.docViewerPanel.isVisible() CONFIG.showViewerPanel = self.docViewerPanel.isVisible()
if self.windowState() & Qt.WindowFullScreen != Qt.WindowFullScreen: wFull = Qt.WindowState.WindowFullScreen
if self.windowState() & wFull != wFull:
# Ignore window size if in full screen mode # Ignore window size if in full screen mode
CONFIG.setMainWinSize(self.width(), self.height()) CONFIG.setMainWinSize(self.width(), self.height())
@@ -936,7 +937,7 @@ class GuiMain(QMainWindow):
def toggleFullScreenMode(self) -> None: def toggleFullScreenMode(self) -> None:
"""Toggle full screen mode""" """Toggle full screen mode"""
self.setWindowState(self.windowState() ^ Qt.WindowFullScreen) self.setWindowState(self.windowState() ^ Qt.WindowState.WindowFullScreen)
return return
## ##
@@ -1212,7 +1213,7 @@ class GuiMain(QMainWindow):
if SHARED.hasProject: if SHARED.hasProject:
currTime = time() currTime = time()
editIdle = currTime - self.docEditor.lastActive > CONFIG.userIdleTime editIdle = currTime - self.docEditor.lastActive > CONFIG.userIdleTime
userIdle = QApplication.applicationState() != Qt.ApplicationActive userIdle = QApplication.applicationState() != Qt.ApplicationState.ApplicationActive
self.mainStatus.setUserIdle(editIdle or userIdle) self.mainStatus.setUserIdle(editIdle or userIdle)
SHARED.updateIdleTime(currTime, editIdle or userIdle) SHARED.updateIdleTime(currTime, editIdle or userIdle)
self.mainStatus.updateTime(idleTime=SHARED.projectIdleTime) self.mainStatus.updateTime(idleTime=SHARED.projectIdleTime)
+3 -3
View File
@@ -27,8 +27,8 @@ import logging
from pathlib import Path from pathlib import Path
from PyQt5.QtCore import QTimer, pyqtSlot
from PyQt5.QtGui import QCloseEvent from PyQt5.QtGui import QCloseEvent
from PyQt5.QtCore import QTimer, Qt, pyqtSlot
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAbstractButton, QAbstractItemView, QDialog, QDialogButtonBox, QFileDialog, QAbstractButton, QAbstractItemView, QDialog, QDialogButtonBox, QFileDialog,
QGridLayout, QHBoxLayout, QLabel, QLineEdit, QListWidget, QListWidgetItem, QGridLayout, QHBoxLayout, QLabel, QLineEdit, QListWidget, QListWidgetItem,
@@ -44,7 +44,7 @@ from novelwriter.core.item import NWItem
from novelwriter.enum import nwBuildFmt from novelwriter.enum import nwBuildFmt
from novelwriter.extensions.modified import NIconToolButton from novelwriter.extensions.modified import NIconToolButton
from novelwriter.extensions.simpleprogress import NProgressSimple from novelwriter.extensions.simpleprogress import NProgressSimple
from novelwriter.types import QtAlignCenter from novelwriter.types import QtAlignCenter, QtUserRole
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -56,7 +56,7 @@ class GuiManuscriptBuild(QDialog):
independently of the Manuscript Build Tool. independently of the Manuscript Build Tool.
""" """
D_KEY = Qt.ItemDataRole.UserRole D_KEY = QtUserRole
def __init__(self, parent: QWidget, build: BuildSettings): def __init__(self, parent: QWidget, build: BuildSettings):
super().__init__(parent=parent) super().__init__(parent=parent)
+4 -3
View File
@@ -53,7 +53,8 @@ from novelwriter.gui.theme import STYLES_FLAT_TABS, STYLES_MIN_TOOLBUTTON
from novelwriter.tools.manusbuild import GuiManuscriptBuild from novelwriter.tools.manusbuild import GuiManuscriptBuild
from novelwriter.tools.manussettings import GuiBuildSettings from novelwriter.tools.manussettings import GuiBuildSettings
from novelwriter.types import ( from novelwriter.types import (
QtAlignAbsolute, QtAlignCenter, QtAlignJustify, QtAlignRight, QtAlignTop QtAlignAbsolute, QtAlignCenter, QtAlignJustify, QtAlignRight, QtAlignTop,
QtUserRole
) )
if TYPE_CHECKING: # pragma: no cover if TYPE_CHECKING: # pragma: no cover
@@ -70,7 +71,7 @@ class GuiManuscript(QDialog):
a document directly to disk. a document directly to disk.
""" """
D_KEY = Qt.ItemDataRole.UserRole D_KEY = QtUserRole
def __init__(self, mainGui: GuiMain) -> None: def __init__(self, mainGui: GuiMain) -> None:
super().__init__(parent=mainGui) super().__init__(parent=mainGui)
@@ -661,7 +662,7 @@ class _DetailsWidget(QWidget):
class _OutlineWidget(QWidget): class _OutlineWidget(QWidget):
D_LINE = Qt.ItemDataRole.UserRole D_LINE = QtUserRole
outlineEntryClicked = pyqtSignal(str) outlineEntryClicked = pyqtSignal(str)
+3 -3
View File
@@ -46,7 +46,7 @@ from novelwriter.extensions.modified import NComboBox, NDoubleSpinBox, NIconTool
from novelwriter.extensions.pagedsidebar import NPagedSideBar from novelwriter.extensions.pagedsidebar import NPagedSideBar
from novelwriter.extensions.switch import NSwitch from novelwriter.extensions.switch import NSwitch
from novelwriter.extensions.switchbox import NSwitchBox from novelwriter.extensions.switchbox import NSwitchBox
from novelwriter.types import QtAlignLeft from novelwriter.types import QtAlignLeft, QtUserRole
if TYPE_CHECKING: # pragma: no cover if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain from novelwriter.guimain import GuiMain
@@ -289,8 +289,8 @@ class _FilterTab(NFixedPage):
C_ACTIVE = 1 C_ACTIVE = 1
C_STATUS = 2 C_STATUS = 2
D_HANDLE = Qt.ItemDataRole.UserRole D_HANDLE = QtUserRole
D_FILE = Qt.ItemDataRole.UserRole + 1 D_FILE = QtUserRole + 1
F_NONE = 0 F_NONE = 0
F_FILTERED = 1 F_FILTERED = 1
+3 -3
View File
@@ -26,8 +26,8 @@ from __future__ import annotations
import math import math
import logging import logging
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtGui import QCloseEvent from PyQt5.QtGui import QCloseEvent
from PyQt5.QtCore import Qt, pyqtSlot
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAbstractItemView, QDialog, QDialogButtonBox, QFormLayout, QGridLayout, QAbstractItemView, QDialog, QDialogButtonBox, QFormLayout, QGridLayout,
QHBoxLayout, QLabel, QSpinBox, QStackedWidget, QTreeWidget, QHBoxLayout, QLabel, QSpinBox, QStackedWidget, QTreeWidget,
@@ -41,7 +41,7 @@ from novelwriter.extensions.configlayout import NColourLabel, NFixedPage, NScrol
from novelwriter.extensions.novelselector import NovelSelector from novelwriter.extensions.novelselector import NovelSelector
from novelwriter.extensions.pagedsidebar import NPagedSideBar from novelwriter.extensions.pagedsidebar import NPagedSideBar
from novelwriter.extensions.switch import NSwitch from novelwriter.extensions.switch import NSwitch
from novelwriter.types import QtAlignRight from novelwriter.types import QtAlignRight, QtDecoration
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -485,7 +485,7 @@ class _ContentsPage(NFixedPage):
if tTitle.strip() == "": if tTitle.strip() == "":
tTitle = self.tr("Untitled") tTitle = self.tr("Untitled")
newItem.setData(self.C_TITLE, Qt.DecorationRole, hDec) newItem.setData(self.C_TITLE, QtDecoration, hDec)
newItem.setText(self.C_TITLE, tTitle) newItem.setText(self.C_TITLE, tTitle)
newItem.setText(self.C_WORDS, f"{wCount:n}") newItem.setText(self.C_WORDS, f"{wCount:n}")
newItem.setText(self.C_PAGES, f"{pCount:n}") newItem.setText(self.C_PAGES, f"{pCount:n}")
+8 -7
View File
@@ -42,7 +42,7 @@ from novelwriter.common import formatTime, checkInt, checkIntTuple, minmax
from novelwriter.constants import nwConst from novelwriter.constants import nwConst
from novelwriter.error import formatException from novelwriter.error import formatException
from novelwriter.extensions.switch import NSwitch from novelwriter.extensions.switch import NSwitch
from novelwriter.types import QtAlignLeftMiddle, QtAlignRight, QtAlignRightMiddle from novelwriter.types import QtAlignLeftMiddle, QtAlignRight, QtAlignRightMiddle, QtDecoration
if TYPE_CHECKING: # pragma: no cover if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain from novelwriter.guimain import GuiMain
@@ -122,10 +122,11 @@ class GuiWritingStats(QDialog):
hHeader.setTextAlignment(self.C_IDLE, QtAlignRight) hHeader.setTextAlignment(self.C_IDLE, QtAlignRight)
hHeader.setTextAlignment(self.C_COUNT, QtAlignRight) hHeader.setTextAlignment(self.C_COUNT, QtAlignRight)
sDec = Qt.SortOrder.DescendingOrder
sAsc = Qt.SortOrder.AscendingOrder
sortCol = minmax(pOptions.getInt("GuiWritingStats", "sortCol", 0), 0, 2) sortCol = minmax(pOptions.getInt("GuiWritingStats", "sortCol", 0), 0, 2)
sortOrder = checkIntTuple( sortOrder = checkIntTuple(
pOptions.getInt("GuiWritingStats", "sortOrder", Qt.DescendingOrder), pOptions.getInt("GuiWritingStats", "sortOrder", sDec), (sAsc, sDec), sDec
(Qt.AscendingOrder, Qt.DescendingOrder), Qt.DescendingOrder
) )
self.listBox.sortByColumn(sortCol, sortOrder) # type: ignore self.listBox.sortByColumn(sortCol, sortOrder) # type: ignore
self.listBox.setSortingEnabled(True) self.listBox.setSortingEnabled(True)
@@ -571,6 +572,8 @@ class GuiWritingStats(QDialog):
pcTotal = wcTotal pcTotal = wcTotal
# Populate the list # Populate the list
mTrans = Qt.TransformationMode.FastTransformation
mAspect = Qt.AspectRatioMode.IgnoreAspectRatio
showIdleTime = self.showIdleTime.isChecked() showIdleTime = self.showIdleTime.isChecked()
for _, sStart, sDiff, nWords, _, _, sIdle in self.filterData: for _, sStart, sDiff, nWords, _, _, sIdle in self.filterData:
@@ -589,11 +592,9 @@ class GuiWritingStats(QDialog):
if nWords > 0 and listMax > 0: if nWords > 0 and listMax > 0:
wBar = self.barImage.scaled( wBar = self.barImage.scaled(
int(200*min(nWords, histMax)/listMax), int(200*min(nWords, histMax)/listMax),
self.barHeight, self.barHeight, mAspect, mTrans
Qt.IgnoreAspectRatio,
Qt.FastTransformation
) )
newItem.setData(self.C_BAR, Qt.DecorationRole, wBar) newItem.setData(self.C_BAR, QtDecoration, wBar)
newItem.setTextAlignment(self.C_LENGTH, QtAlignRight) newItem.setTextAlignment(self.C_LENGTH, QtAlignRight)
newItem.setTextAlignment(self.C_IDLE, QtAlignRight) newItem.setTextAlignment(self.C_IDLE, QtAlignRight)
+22
View File
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
from __future__ import annotations from __future__ import annotations
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtGui import QColor
# Qt Alignment Flags # Qt Alignment Flags
@@ -41,3 +42,24 @@ QtAlignRightBase = Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignBaseline
QtAlignRightMiddle = Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter QtAlignRightMiddle = Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter
QtAlignRightTop = Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignTop QtAlignRightTop = Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignTop
QtAlignTop = Qt.AlignmentFlag.AlignTop QtAlignTop = Qt.AlignmentFlag.AlignTop
# Qt Painter Types
QtTransparent = QColor(0, 0, 0, 0)
QtNoBrush = Qt.BrushStyle.NoBrush
QtNoPen = Qt.PenStyle.NoPen
QtRoundCap = Qt.PenCapStyle.RoundCap
QtSolidLine = Qt.PenStyle.SolidLine
# Qt Tree and Table Types
QtDecoration = Qt.ItemDataRole.DecorationRole
QtUserRole = Qt.ItemDataRole.UserRole
# Keyboard and Mouse Buttons
QtModCtrl = Qt.KeyboardModifier.ControlModifier
QtModeNone = Qt.KeyboardModifier.NoModifier
QtModShift = Qt.KeyboardModifier.ShiftModifier
QtMouseLeft = Qt.MouseButton.LeftButton
QtMouseMiddle = Qt.MouseButton.MiddleButton
+6 -5
View File
@@ -27,6 +27,7 @@ from tools import buildTestProject, C
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from novelwriter.dialogs.docmerge import GuiDocMerge from novelwriter.dialogs.docmerge import GuiDocMerge
from novelwriter.types import QtUserRole
@pytest.mark.gui @pytest.mark.gui
@@ -53,11 +54,11 @@ def testDlgMerge_Main(qtbot, nwGUI, projPath, mockRnd):
itemOne = nwMerge.listBox.item(0) itemOne = nwMerge.listBox.item(0)
itemTwo = nwMerge.listBox.item(1) itemTwo = nwMerge.listBox.item(1)
assert itemOne.data(Qt.ItemDataRole.UserRole) == C.hChapterDoc assert itemOne.data(QtUserRole) == C.hChapterDoc
assert itemTwo.data(Qt.ItemDataRole.UserRole) == C.hSceneDoc assert itemTwo.data(QtUserRole) == C.hSceneDoc
assert itemOne.checkState() == Qt.Checked assert itemOne.checkState() == Qt.CheckState.Checked
assert itemTwo.checkState() == Qt.Checked assert itemTwo.checkState() == Qt.CheckState.Checked
data = nwMerge.getData() data = nwMerge.getData()
assert data["sHandle"] == C.hChapterDir assert data["sHandle"] == C.hChapterDir
@@ -66,7 +67,7 @@ def testDlgMerge_Main(qtbot, nwGUI, projPath, mockRnd):
assert data["finalItems"] == [C.hChapterDoc, C.hSceneDoc] assert data["finalItems"] == [C.hChapterDoc, C.hSceneDoc]
# Uncheck second item and toggle trash switch # Uncheck second item and toggle trash switch
itemTwo.setCheckState(Qt.Unchecked) itemTwo.setCheckState(Qt.CheckState.Unchecked)
nwMerge.trashSwitch.setChecked(True) nwMerge.trashSwitch.setChecked(True)
data = nwMerge.getData() data = nwMerge.getData()
+2 -1
View File
@@ -30,6 +30,7 @@ from novelwriter import CONFIG, SHARED
from novelwriter.constants import nwConst, nwUnicode from novelwriter.constants import nwConst, nwUnicode
from novelwriter.dialogs.preferences import GuiPreferences from novelwriter.dialogs.preferences import GuiPreferences
from novelwriter.dialogs.quotes import GuiQuoteSelect from novelwriter.dialogs.quotes import GuiQuoteSelect
from novelwriter.types import QtModeNone
KEY_DELAY = 1 KEY_DELAY = 1
@@ -141,7 +142,7 @@ def testDlgPreferences_Actions(qtbot, monkeypatch, nwGUI):
# Close Using Escape Key # Close Using Escape Key
prefs.show() prefs.show()
with qtbot.waitSignal(prefs.finished) as status: with qtbot.waitSignal(prefs.finished) as status:
event = QKeyEvent(QEvent.Type.KeyPress, Qt.Key.Key_Escape, Qt.KeyboardModifier.NoModifier) event = QKeyEvent(QEvent.Type.KeyPress, Qt.Key.Key_Escape, QtModeNone)
prefs.keyPressEvent(event) prefs.keyPressEvent(event)
assert status.args == [nwConst.DLG_FINISHED] assert status.args == [nwConst.DLG_FINISHED]
+14 -13
View File
@@ -24,14 +24,15 @@ import pytest
from tools import C, buildTestProject from tools import C, buildTestProject
from PyQt5.QtGui import QColor
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import QDialog, QAction, QColorDialog from PyQt5.QtWidgets import QDialog, QAction, QColorDialog
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.enum import nwItemType
from novelwriter.dialogs.editlabel import GuiEditLabel from novelwriter.dialogs.editlabel import GuiEditLabel
from novelwriter.dialogs.projectsettings import GuiProjectSettings from novelwriter.dialogs.projectsettings import GuiProjectSettings
from novelwriter.enum import nwItemType
from novelwriter.types import QtMouseLeft
KEY_DELAY = 1 KEY_DELAY = 1
@@ -188,13 +189,13 @@ def testDlgProjSettings_StatusImport(qtbot, monkeypatch, nwGUI, projPath, mockRn
# Can't delete the first item (it's in use) # Can't delete the first item (it's in use)
status.listBox.clearSelection() status.listBox.clearSelection()
status.listBox.setCurrentItem(status.listBox.topLevelItem(0)) status.listBox.setCurrentItem(status.listBox.topLevelItem(0))
qtbot.mouseClick(status.delButton, Qt.LeftButton) qtbot.mouseClick(status.delButton, QtMouseLeft)
assert status.listBox.topLevelItemCount() == 4 assert status.listBox.topLevelItemCount() == 4
# Can delete the second item # Can delete the second item
status.listBox.clearSelection() status.listBox.clearSelection()
status.listBox.setCurrentItem(status.listBox.topLevelItem(1)) status.listBox.setCurrentItem(status.listBox.topLevelItem(1))
qtbot.mouseClick(status.delButton, Qt.LeftButton) qtbot.mouseClick(status.delButton, QtMouseLeft)
assert status.listBox.topLevelItemCount() == 3 assert status.listBox.topLevelItemCount() == 3
# Add a new item # Add a new item
@@ -270,21 +271,21 @@ def testDlgProjSettings_StatusImport(qtbot, monkeypatch, nwGUI, projPath, mockRn
# Delete unused entry # Delete unused entry
importance.listBox.clearSelection() importance.listBox.clearSelection()
importance.listBox.setCurrentItem(importance.listBox.topLevelItem(1)) importance.listBox.setCurrentItem(importance.listBox.topLevelItem(1))
qtbot.mouseClick(importance.delButton, Qt.LeftButton) qtbot.mouseClick(importance.delButton, QtMouseLeft)
assert importance.listBox.topLevelItemCount() == 3 assert importance.listBox.topLevelItemCount() == 3
# Add a new entry # Add a new entry
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QColorDialog, "getColor", lambda *a: QColor(20, 30, 40)) mp.setattr(QColorDialog, "getColor", lambda *a: QColor(20, 30, 40))
qtbot.mouseClick(importance.addButton, Qt.LeftButton) qtbot.mouseClick(importance.addButton, QtMouseLeft)
importance.listBox.clearSelection() importance.listBox.clearSelection()
importance.listBox.setCurrentItem(importance.listBox.topLevelItem(3)) importance.listBox.setCurrentItem(importance.listBox.topLevelItem(3))
for _ in range(8): for _ in range(8):
qtbot.keyClick(importance.editName, Qt.Key_Backspace, delay=KEY_DELAY) qtbot.keyClick(importance.editName, Qt.Key.Key_Backspace, delay=KEY_DELAY)
for c in "Final": for c in "Final":
qtbot.keyClick(importance.editName, c, delay=KEY_DELAY) qtbot.keyClick(importance.editName, c, delay=KEY_DELAY)
qtbot.mouseClick(importance.colButton, Qt.LeftButton) qtbot.mouseClick(importance.colButton, QtMouseLeft)
qtbot.mouseClick(importance.saveButton, Qt.LeftButton) qtbot.mouseClick(importance.saveButton, QtMouseLeft)
assert importance.listBox.topLevelItemCount() == 4 assert importance.listBox.topLevelItemCount() == 4
assert importance.wasChanged is True assert importance.wasChanged is True
@@ -367,7 +368,7 @@ def testDlgProjSettings_Replace(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
assert replace.listBox.topLevelItemCount() == 2 assert replace.listBox.topLevelItemCount() == 2
# Create a new entry # Create a new entry
qtbot.mouseClick(replace.addButton, Qt.LeftButton) qtbot.mouseClick(replace.addButton, QtMouseLeft)
assert replace.listBox.topLevelItemCount() == 3 assert replace.listBox.topLevelItemCount() == 3
assert replace.listBox.topLevelItem(2).text(0) == "<keyword3>" # type: ignore assert replace.listBox.topLevelItem(2).text(0) == "<keyword3>" # type: ignore
assert replace.listBox.topLevelItem(2).text(1) == "" # type: ignore assert replace.listBox.topLevelItem(2).text(1) == "" # type: ignore
@@ -380,13 +381,13 @@ def testDlgProjSettings_Replace(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
replace.editValue.setText("") replace.editValue.setText("")
for c in "With This Stuff ": for c in "With This Stuff ":
qtbot.keyClick(replace.editValue, c, delay=KEY_DELAY) qtbot.keyClick(replace.editValue, c, delay=KEY_DELAY)
qtbot.mouseClick(replace.saveButton, Qt.LeftButton) qtbot.mouseClick(replace.saveButton, QtMouseLeft)
assert replace.listBox.topLevelItem(2).text(0) == "<This>" # type: ignore assert replace.listBox.topLevelItem(2).text(0) == "<This>" # type: ignore
assert replace.listBox.topLevelItem(2).text(1) == "With This Stuff " # type: ignore assert replace.listBox.topLevelItem(2).text(1) == "With This Stuff " # type: ignore
# Create a new entry again # Create a new entry again
replace.listBox.clearSelection() replace.listBox.clearSelection()
qtbot.mouseClick(replace.addButton, Qt.LeftButton) qtbot.mouseClick(replace.addButton, QtMouseLeft)
assert replace.listBox.topLevelItemCount() == 4 assert replace.listBox.topLevelItemCount() == 4
# The list is sorted, so we must find it # The list is sorted, so we must find it
@@ -399,7 +400,7 @@ def testDlgProjSettings_Replace(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
# Then delete the new item # Then delete the new item
replace.listBox.setCurrentItem(replace.listBox.topLevelItem(newIdx)) replace.listBox.setCurrentItem(replace.listBox.topLevelItem(newIdx))
qtbot.mouseClick(replace.delButton, Qt.LeftButton) qtbot.mouseClick(replace.delButton, QtMouseLeft)
assert replace.listBox.topLevelItemCount() == 3 assert replace.listBox.topLevelItemCount() == 3
# Check Project # Check Project
+10 -10
View File
@@ -37,7 +37,7 @@ from novelwriter.enum import (
) )
from novelwriter.gui.doceditor import GuiDocEditor, GuiDocToolBar from novelwriter.gui.doceditor import GuiDocEditor, GuiDocToolBar
from novelwriter.text.counting import standardCounter from novelwriter.text.counting import standardCounter
from novelwriter.types import QtAlignJustify, QtAlignLeft from novelwriter.types import QtAlignJustify, QtAlignLeft, QtMouseLeft
KEY_DELAY = 1 KEY_DELAY = 1
@@ -95,7 +95,7 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd):
# Select item from header # Select item from header
with qtbot.waitSignal(nwGUI.docEditor.requestProjectItemSelected, timeout=1000) as signal: with qtbot.waitSignal(nwGUI.docEditor.requestProjectItemSelected, timeout=1000) as signal:
qtbot.mouseClick(nwGUI.docEditor.docHeader, Qt.MouseButton.LeftButton) qtbot.mouseClick(nwGUI.docEditor.docHeader, QtMouseLeft)
assert signal.args == [nwGUI.docEditor.docHeader._docHandle, True] assert signal.args == [nwGUI.docEditor.docHeader._docHandle, True]
# Close from header # Close from header
@@ -109,7 +109,7 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd):
# Select item from header # Select item from header
with qtbot.waitSignal(nwGUI.docEditor.requestProjectItemSelected, timeout=1000) as signal: with qtbot.waitSignal(nwGUI.docEditor.requestProjectItemSelected, timeout=1000) as signal:
qtbot.mouseClick(nwGUI.docEditor.docHeader, Qt.MouseButton.LeftButton) qtbot.mouseClick(nwGUI.docEditor.docHeader, QtMouseLeft)
assert signal.args == ["", True] assert signal.args == ["", True]
# qtbot.stop() # qtbot.stop()
@@ -1788,7 +1788,7 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
assert abs(docEditor.getCursorPosition() - 1299) < 3 assert abs(docEditor.getCursorPosition() - 1299) < 3
# Find next by button # Find next by button
qtbot.mouseClick(docSearch.searchButton, Qt.LeftButton, delay=KEY_DELAY) qtbot.mouseClick(docSearch.searchButton, QtMouseLeft, delay=KEY_DELAY)
assert abs(docEditor.getCursorPosition() - 1513) < 3 assert abs(docEditor.getCursorPosition() - 1513) < 3
# Activate loop search # Activate loop search
@@ -1806,14 +1806,14 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
docEditor.setCursorPosition(15) docEditor.setCursorPosition(15)
# Toggle search again with header button # Toggle search again with header button
qtbot.mouseClick(docEditor.docHeader.searchButton, Qt.LeftButton, delay=KEY_DELAY) qtbot.mouseClick(docEditor.docHeader.searchButton, QtMouseLeft, delay=KEY_DELAY)
docSearch.setSearchText("") docSearch.setSearchText("")
assert docSearch.isVisible() is True assert docSearch.isVisible() is True
# Search for non-existing # Search for non-existing
docEditor.setCursorPosition(0) docEditor.setCursorPosition(0)
docSearch.setSearchText("abcdef") docSearch.setSearchText("abcdef")
qtbot.mouseClick(docSearch.searchButton, Qt.LeftButton, delay=KEY_DELAY) qtbot.mouseClick(docSearch.searchButton, QtMouseLeft, delay=KEY_DELAY)
assert docEditor.getCursorPosition() < 3 # No result assert docEditor.getCursorPosition() < 3 # No result
# Enable RegEx search # Enable RegEx search
@@ -1824,19 +1824,19 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
# Set invalid RegEx # Set invalid RegEx
docEditor.setCursorPosition(0) docEditor.setCursorPosition(0)
docSearch.setSearchText(r"\bSus[") docSearch.setSearchText(r"\bSus[")
qtbot.mouseClick(docSearch.searchButton, Qt.LeftButton, delay=KEY_DELAY) qtbot.mouseClick(docSearch.searchButton, QtMouseLeft, delay=KEY_DELAY)
assert docEditor.getCursorPosition() < 3 # No result assert docEditor.getCursorPosition() < 3 # No result
# Set dangerous RegEx (issue #1015) # Set dangerous RegEx (issue #1015)
# If this doesn't get caught, the app will hang # If this doesn't get caught, the app will hang
docEditor.setCursorPosition(0) docEditor.setCursorPosition(0)
docSearch.setSearchText(r".*") docSearch.setSearchText(r".*")
qtbot.mouseClick(docSearch.searchButton, Qt.LeftButton, delay=KEY_DELAY) qtbot.mouseClick(docSearch.searchButton, QtMouseLeft, delay=KEY_DELAY)
assert abs(docEditor.getCursorPosition() - 14) < 3 assert abs(docEditor.getCursorPosition() - 14) < 3
# Set valid RegEx # Set valid RegEx
docSearch.setSearchText(r"\bSus") docSearch.setSearchText(r"\bSus")
qtbot.mouseClick(docSearch.searchButton, Qt.LeftButton, delay=KEY_DELAY) qtbot.mouseClick(docSearch.searchButton, QtMouseLeft, delay=KEY_DELAY)
assert abs(docEditor.getCursorPosition() - 223) < 3 assert abs(docEditor.getCursorPosition() - 223) < 3
# Find next and then prev # Find next and then prev
@@ -1887,7 +1887,7 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
assert abs(docEditor.getCursorPosition() - 223) < 3 assert abs(docEditor.getCursorPosition() - 223) < 3
# Replace "sus" with "foo" via replace button # Replace "sus" with "foo" via replace button
qtbot.mouseClick(docSearch.replaceButton, Qt.LeftButton, delay=KEY_DELAY) qtbot.mouseClick(docSearch.replaceButton, QtMouseLeft, delay=KEY_DELAY)
assert docEditor.getText()[220:228] == "foocipit" assert docEditor.getText()[220:228] == "foocipit"
# Revert last two replaces # Revert last two replaces
+5 -4
View File
@@ -24,14 +24,15 @@ import pytest
from mocked import causeException from mocked import causeException
from PyQt5.QtGui import QMouseEvent, QTextCursor
from PyQt5.QtCore import QEvent, QPoint, Qt, QUrl from PyQt5.QtCore import QEvent, QPoint, Qt, QUrl
from PyQt5.QtGui import QMouseEvent, QTextCursor
from PyQt5.QtWidgets import QAction, QApplication, QMenu from PyQt5.QtWidgets import QAction, QApplication, QMenu
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.enum import nwDocAction from novelwriter.enum import nwDocAction
from novelwriter.core.tohtml import ToHtml from novelwriter.core.tohtml import ToHtml
from novelwriter.gui.docviewer import GuiDocViewer from novelwriter.gui.docviewer import GuiDocViewer
from novelwriter.types import QtMouseLeft, QtModeNone
@pytest.mark.gui @pytest.mark.gui
@@ -59,8 +60,8 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
assert nwGUI.projView.projTree.getSelectedHandle() is None assert nwGUI.projView.projTree.getSelectedHandle() is None
# Re-select via header click # Re-select via header click
button = Qt.MouseButton.LeftButton button = QtMouseLeft
modifier = Qt.KeyboardModifier.NoModifier modifier = QtModeNone
event = QMouseEvent(QEvent.MouseButtonPress, QPoint(), button, button, modifier) event = QMouseEvent(QEvent.MouseButtonPress, QPoint(), button, button, modifier)
docViewer.docHeader.mousePressEvent(event) docViewer.docHeader.mousePressEvent(event)
assert nwGUI.projView.projTree.getSelectedHandle() == "88243afbe5ed8" assert nwGUI.projView.projTree.getSelectedHandle() == "88243afbe5ed8"
@@ -164,7 +165,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
assert docViewer.docHandle == "88243afbe5ed8" assert docViewer.docHandle == "88243afbe5ed8"
qtbot.mouseClick(docViewer.viewport(), Qt.ForwardButton, pos=rect.center(), delay=100) qtbot.mouseClick(docViewer.viewport(), Qt.ForwardButton, pos=rect.center(), delay=100)
assert docViewer.docHandle == "4c4f28287af27" assert docViewer.docHandle == "4c4f28287af27"
qtbot.mouseClick(docViewer.viewport(), Qt.LeftButton, pos=rect.center(), delay=100) qtbot.mouseClick(docViewer.viewport(), QtMouseLeft, pos=rect.center(), delay=100)
assert docViewer.docHandle == "4c4f28287af27" assert docViewer.docHandle == "4c4f28287af27"
# Scroll bar default on empty document # Scroll bar default on empty document
+6 -6
View File
@@ -25,13 +25,13 @@ import pytest
from tools import C, writeFile, buildTestProject from tools import C, writeFile, buildTestProject
from PyQt5.QtGui import QTextCursor, QTextBlock from PyQt5.QtGui import QTextCursor, QTextBlock
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.enum import nwDocAction, nwDocInsert
from novelwriter.constants import nwKeyWords, nwUnicode from novelwriter.constants import nwKeyWords, nwUnicode
from novelwriter.enum import nwDocAction, nwDocInsert
from novelwriter.gui.doceditor import GuiDocEditor from novelwriter.gui.doceditor import GuiDocEditor
from novelwriter.types import QtMouseLeft
@pytest.mark.gui @pytest.mark.gui
@@ -359,7 +359,7 @@ def testGuiMenu_ContextMenus(qtbot, nwGUI, prjLipsum):
rect = nwGUI.docEditor.cursorRect() rect = nwGUI.docEditor.cursorRect()
nwGUI.docEditor._openContextMenu(rect.bottomRight()) nwGUI.docEditor._openContextMenu(rect.bottomRight())
qtbot.mouseClick(nwGUI.docEditor, Qt.LeftButton, pos=rect.topLeft()) qtbot.mouseClick(nwGUI.docEditor, QtMouseLeft, pos=rect.topLeft())
nwGUI.docEditor._makePosSelection(QTextCursor.WordUnderCursor, rect.center()) nwGUI.docEditor._makePosSelection(QTextCursor.WordUnderCursor, rect.center())
cursor = nwGUI.docEditor.textCursor() cursor = nwGUI.docEditor.textCursor()
@@ -386,7 +386,7 @@ def testGuiMenu_ContextMenus(qtbot, nwGUI, prjLipsum):
rect = nwGUI.docViewer.cursorRect() rect = nwGUI.docViewer.cursorRect()
nwGUI.docViewer._openContextMenu(rect.bottomRight()) nwGUI.docViewer._openContextMenu(rect.bottomRight())
qtbot.mouseClick(nwGUI.docViewer, Qt.LeftButton, pos=rect.topLeft()) qtbot.mouseClick(nwGUI.docViewer, QtMouseLeft, pos=rect.topLeft())
nwGUI.docViewer._makePosSelection(QTextCursor.WordUnderCursor, rect.center()) nwGUI.docViewer._makePosSelection(QTextCursor.WordUnderCursor, rect.center())
cursor = nwGUI.docViewer.textCursor() cursor = nwGUI.docViewer.textCursor()
@@ -410,12 +410,12 @@ def testGuiMenu_ContextMenus(qtbot, nwGUI, prjLipsum):
assert nwGUI.docViewer.docHeader.backButton.isEnabled() assert nwGUI.docViewer.docHeader.backButton.isEnabled()
assert not nwGUI.docViewer.docHeader.forwardButton.isEnabled() assert not nwGUI.docViewer.docHeader.forwardButton.isEnabled()
qtbot.mouseClick(nwGUI.docViewer.docHeader.backButton, Qt.LeftButton) qtbot.mouseClick(nwGUI.docViewer.docHeader.backButton, QtMouseLeft)
assert nwGUI.docViewer.docHandle == "4c4f28287af27" assert nwGUI.docViewer.docHandle == "4c4f28287af27"
assert not nwGUI.docViewer.docHeader.backButton.isEnabled() assert not nwGUI.docViewer.docHeader.backButton.isEnabled()
assert nwGUI.docViewer.docHeader.forwardButton.isEnabled() assert nwGUI.docViewer.docHeader.forwardButton.isEnabled()
qtbot.mouseClick(nwGUI.docViewer.docHeader.forwardButton, Qt.LeftButton) qtbot.mouseClick(nwGUI.docViewer.docHeader.forwardButton, QtMouseLeft)
assert nwGUI.docViewer.docHandle == "04468803b92e1" assert nwGUI.docViewer.docHandle == "04468803b92e1"
assert nwGUI.docViewer.docHeader.backButton.isEnabled() assert nwGUI.docViewer.docHeader.backButton.isEnabled()
assert not nwGUI.docViewer.docHeader.forwardButton.isEnabled() assert not nwGUI.docViewer.docHeader.forwardButton.isEnabled()
+4 -3
View File
@@ -26,14 +26,15 @@ from pathlib import Path
from tools import C, buildTestProject from tools import C, buildTestProject
from PyQt5.QtGui import QFocusEvent
from PyQt5.QtCore import QPoint, Qt, QEvent from PyQt5.QtCore import QPoint, Qt, QEvent
from PyQt5.QtGui import QFocusEvent
from PyQt5.QtWidgets import QInputDialog, QToolTip from PyQt5.QtWidgets import QInputDialog, QToolTip
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.dialogs.editlabel import GuiEditLabel
from novelwriter.enum import nwWidget, nwItemType from novelwriter.enum import nwWidget, nwItemType
from novelwriter.gui.noveltree import GuiNovelTree, NovelTreeColumn from novelwriter.gui.noveltree import GuiNovelTree, NovelTreeColumn
from novelwriter.dialogs.editlabel import GuiEditLabel from novelwriter.types import QtMouseLeft
@pytest.mark.gui @pytest.mark.gui
@@ -112,7 +113,7 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
# Clear selection with mouse # Clear selection with mouse
vPort = novelTree.viewport() vPort = novelTree.viewport()
qtbot.mouseClick(vPort, Qt.LeftButton, pos=vPort.rect().center(), delay=10) qtbot.mouseClick(vPort, QtMouseLeft, pos=vPort.rect().center(), delay=10)
assert not scItem.isSelected() assert not scItem.isSelected()
# Double-click item # Double-click item
+14 -13
View File
@@ -23,23 +23,24 @@ from __future__ import annotations
import pytest import pytest
from pathlib import Path from pathlib import Path
from novelwriter.core.project import NWProject
from tools import C, buildTestProject
from mocked import causeOSError from mocked import causeOSError
from tools import C, buildTestProject
from PyQt5.QtGui import QDragEnterEvent, QDragMoveEvent, QDropEvent, QMouseEvent
from PyQt5.QtCore import QEvent, QMimeData, QPoint, QTimer, Qt from PyQt5.QtCore import QEvent, QMimeData, QPoint, QTimer, Qt
from PyQt5.QtGui import QDragEnterEvent, QDragMoveEvent, QDropEvent, QMouseEvent
from PyQt5.QtWidgets import QMessageBox, QMenu, QTreeWidget, QTreeWidgetItem, QDialog from PyQt5.QtWidgets import QMessageBox, QMenu, QTreeWidget, QTreeWidgetItem, QDialog
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.enum import nwItemLayout, nwItemType, nwItemClass, nwWidget
from novelwriter.guimain import GuiMain
from novelwriter.core.item import NWItem from novelwriter.core.item import NWItem
from novelwriter.gui.projtree import GuiProjectTree, GuiProjectView, _TreeContextMenu from novelwriter.core.project import NWProject
from novelwriter.dialogs.docmerge import GuiDocMerge from novelwriter.dialogs.docmerge import GuiDocMerge
from novelwriter.dialogs.docsplit import GuiDocSplit from novelwriter.dialogs.docsplit import GuiDocSplit
from novelwriter.dialogs.editlabel import GuiEditLabel from novelwriter.dialogs.editlabel import GuiEditLabel
from novelwriter.enum import nwItemLayout, nwItemType, nwItemClass, nwWidget
from novelwriter.gui.projtree import GuiProjectTree, GuiProjectView, _TreeContextMenu
from novelwriter.guimain import GuiMain
from novelwriter.types import QtMouseLeft, QtMouseMiddle, QtModeNone
@pytest.mark.gui @pytest.mark.gui
@@ -821,8 +822,8 @@ def testGuiProjTree_AutoScroll(qtbot, monkeypatch, nwGUI: GuiMain, projPath, moc
action = Qt.DropAction.MoveAction action = Qt.DropAction.MoveAction
mime = QMimeData() mime = QMimeData()
mouse = Qt.MouseButton.LeftButton mouse = QtMouseLeft
modifier = Qt.KeyboardModifier.NoModifier modifier = QtModeNone
# Scroll Down # Scroll Down
h = projTree.height() h = projTree.height()
@@ -880,8 +881,8 @@ def testGuiProjTree_DragAndDrop(qtbot, monkeypatch, caplog, nwGUI: GuiMain, proj
nPos = projTree.visualItemRect(projTree._getTreeItem(C.hNovelRoot)).bottomLeft() nPos = projTree.visualItemRect(projTree._getTreeItem(C.hNovelRoot)).bottomLeft()
action = Qt.DropAction.MoveAction action = Qt.DropAction.MoveAction
mime = QMimeData() mime = QMimeData()
mouse = Qt.MouseButton.LeftButton mouse = QtMouseLeft
modifier = Qt.KeyboardModifier.NoModifier modifier = QtModeNone
projTree.saveTreeOrder() projTree.saveTreeOrder()
treeOrder = SHARED.project.tree._order treeOrder = SHARED.project.tree._order
@@ -1082,8 +1083,8 @@ def testGuiProjTree_Other(qtbot, monkeypatch, nwGUI: GuiMain, projPath, mockRnd)
eType = QEvent.Type.MouseButtonPress eType = QEvent.Type.MouseButtonPress
pos = projTree.visualItemRect(projTree._getTreeItem(C.hChapterDoc)).center() pos = projTree.visualItemRect(projTree._getTreeItem(C.hChapterDoc)).center()
button = Qt.MouseButton.MiddleButton button = QtMouseMiddle
modifier = Qt.KeyboardModifier.NoModifier modifier = QtModeNone
# Trigger the viewer # Trigger the viewer
event = QMouseEvent(eType, pos, button, button, modifier) event = QMouseEvent(eType, pos, button, button, modifier)
@@ -1092,7 +1093,7 @@ def testGuiProjTree_Other(qtbot, monkeypatch, nwGUI: GuiMain, projPath, mockRnd)
# Trigger the left click clear # Trigger the left click clear
pos = QPoint(5000, 5000) pos = QPoint(5000, 5000)
button = Qt.MouseButton.LeftButton button = QtMouseLeft
event = QMouseEvent(eType, pos, button, button, modifier) event = QMouseEvent(eType, pos, button, button, modifier)
projTree.setSelectedHandle(C.hChapterDoc) projTree.setSelectedHandle(C.hChapterDoc)
projTree.mousePressEvent(event) projTree.mousePressEvent(event)
+7 -6
View File
@@ -26,13 +26,14 @@ from pathlib import Path
from datetime import datetime from datetime import datetime
from pytestqt.qtbot import QtBot from pytestqt.qtbot import QtBot
from PyQt5.QtCore import QPoint, Qt from PyQt5.QtCore import QPoint
from PyQt5.QtWidgets import QAction, QFileDialog, QMenu from PyQt5.QtWidgets import QAction, QFileDialog, QMenu
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.enum import nwItemClass from novelwriter.enum import nwItemClass
from novelwriter.constants import nwFiles from novelwriter.constants import nwFiles
from novelwriter.tools.welcome import GuiWelcome from novelwriter.tools.welcome import GuiWelcome
from novelwriter.types import QtMouseLeft
@pytest.mark.gui @pytest.mark.gui
@@ -100,19 +101,19 @@ def testToolWelcome_Open(qtbot: QtBot, monkeypatch, nwGUI, fncPath):
# Single click item # Single click item
assert tabOpen.selectedPath.text() == "Path: /stuff/project_two" assert tabOpen.selectedPath.text() == "Path: /stuff/project_two"
qtbot.mouseClick(vPort, Qt.MouseButton.LeftButton, pos=posTwo, delay=10) qtbot.mouseClick(vPort, QtMouseLeft, pos=posTwo, delay=10)
assert tabOpen.selectedPath.text() == "Path: /stuff/project_one" assert tabOpen.selectedPath.text() == "Path: /stuff/project_one"
# Double click item # Double click item
qtbot.mouseClick(vPort, Qt.MouseButton.LeftButton, pos=posTwo, delay=10) qtbot.mouseClick(vPort, QtMouseLeft, pos=posTwo, delay=10)
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(welcome, "close", lambda *a: None) mp.setattr(welcome, "close", lambda *a: None)
with qtbot.waitSignal(welcome.openProjectRequest, timeout=5000) as signal: with qtbot.waitSignal(welcome.openProjectRequest, timeout=5000) as signal:
qtbot.mouseDClick(vPort, Qt.MouseButton.LeftButton, pos=posTwo, delay=10) qtbot.mouseDClick(vPort, QtMouseLeft, pos=posTwo, delay=10)
assert signal.args and signal.args[0] == Path("/stuff/project_one") assert signal.args and signal.args[0] == Path("/stuff/project_one")
# Press open button # Press open button
qtbot.mouseClick(vPort, Qt.MouseButton.LeftButton, pos=posTwo, delay=10) qtbot.mouseClick(vPort, QtMouseLeft, pos=posTwo, delay=10)
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(welcome, "close", lambda *a: None) mp.setattr(welcome, "close", lambda *a: None)
with qtbot.waitSignal(welcome.openProjectRequest, timeout=5000) as signal: with qtbot.waitSignal(welcome.openProjectRequest, timeout=5000) as signal:
@@ -128,7 +129,7 @@ def testToolWelcome_Open(qtbot: QtBot, monkeypatch, nwGUI, fncPath):
return obj return obj
return None return None
qtbot.mouseClick(vPort, Qt.MouseButton.LeftButton, pos=posOne, delay=10) qtbot.mouseClick(vPort, QtMouseLeft, pos=posOne, delay=10)
ctxMenu = getMenuForPos(posOne) ctxMenu = getMenuForPos(posOne)
assert isinstance(ctxMenu, QMenu) assert isinstance(ctxMenu, QMenu)
assert ctxMenu.actions()[0].text() == "Open Project" assert ctxMenu.actions()[0].text() == "Open Project"
+12 -12
View File
@@ -25,15 +25,15 @@ import pytest
from pathlib import Path from pathlib import Path
from tools import buildTestProject
from mocked import causeOSError from mocked import causeOSError
from tools import buildTestProject
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QAction, QFileDialog from PyQt5.QtWidgets import QAction, QFileDialog
from novelwriter import SHARED from novelwriter import SHARED
from novelwriter.constants import nwFiles from novelwriter.constants import nwFiles
from novelwriter.tools.writingstats import GuiWritingStats from novelwriter.tools.writingstats import GuiWritingStats
from novelwriter.types import QtMouseLeft
@pytest.mark.gui @pytest.mark.gui
@@ -97,11 +97,11 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, projPath, tstPaths):
monkeypatch.setattr(QFileDialog, "getSaveFileName", lambda *a, **k: ("", "")) monkeypatch.setattr(QFileDialog, "getSaveFileName", lambda *a, **k: ("", ""))
assert not sessLog._saveData(sessLog.FMT_CSV) assert not sessLog._saveData(sessLog.FMT_CSV)
assert not sessLog._saveData(sessLog.FMT_JSON) assert not sessLog._saveData(sessLog.FMT_JSON)
assert not sessLog._saveData(None) assert not sessLog._saveData(None) # type: ignore
# Make the save succeed # Make the save succeed
monkeypatch.setattr(QFileDialog, "getSaveFileName", lambda ss, tt, pp, options: (pp, "")) monkeypatch.setattr(QFileDialog, "getSaveFileName", lambda ss, tt, pp, options: (pp, ""))
sessLog.listBox.sortByColumn(sessLog.C_TIME, 0) sessLog.listBox.sortByColumn(sessLog.C_TIME, 0) # type: ignore
assert sessLog.novelWords.text() == "{:n}".format(600) assert sessLog.novelWords.text() == "{:n}".format(600)
assert sessLog.notesWords.text() == "{:n}".format(275) assert sessLog.notesWords.text() == "{:n}".format(275)
@@ -156,7 +156,7 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, projPath, tstPaths):
# ============ # ============
# No Novel Files # No Novel Files
qtbot.mouseClick(sessLog.incNovel, Qt.LeftButton) qtbot.mouseClick(sessLog.incNovel, QtMouseLeft)
assert sessLog._saveData(sessLog.FMT_JSON) assert sessLog._saveData(sessLog.FMT_JSON)
jsonStats = tstPaths.tmpDir / "sessionStats.json" jsonStats = tstPaths.tmpDir / "sessionStats.json"
@@ -201,8 +201,8 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, projPath, tstPaths):
] ]
# No Note Files # No Note Files
qtbot.mouseClick(sessLog.incNovel, Qt.LeftButton) qtbot.mouseClick(sessLog.incNovel, QtMouseLeft)
qtbot.mouseClick(sessLog.incNotes, Qt.LeftButton) qtbot.mouseClick(sessLog.incNotes, QtMouseLeft)
assert sessLog._saveData(sessLog.FMT_JSON) assert sessLog._saveData(sessLog.FMT_JSON)
jsonStats = tstPaths.tmpDir / "sessionStats.json" jsonStats = tstPaths.tmpDir / "sessionStats.json"
@@ -247,8 +247,8 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, projPath, tstPaths):
] ]
# No Negative Entries # No Negative Entries
qtbot.mouseClick(sessLog.incNotes, Qt.LeftButton) qtbot.mouseClick(sessLog.incNotes, QtMouseLeft)
qtbot.mouseClick(sessLog.hideNegative, Qt.LeftButton) qtbot.mouseClick(sessLog.hideNegative, QtMouseLeft)
assert sessLog._saveData(sessLog.FMT_JSON) assert sessLog._saveData(sessLog.FMT_JSON)
# qtbot.stop() # qtbot.stop()
@@ -279,8 +279,8 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, projPath, tstPaths):
] ]
# Un-hide Zero Entries # Un-hide Zero Entries
qtbot.mouseClick(sessLog.hideNegative, Qt.LeftButton) qtbot.mouseClick(sessLog.hideNegative, QtMouseLeft)
qtbot.mouseClick(sessLog.hideZeros, Qt.LeftButton) qtbot.mouseClick(sessLog.hideZeros, QtMouseLeft)
assert sessLog._saveData(sessLog.FMT_JSON) assert sessLog._saveData(sessLog.FMT_JSON)
jsonStats = tstPaths.tmpDir / "sessionStats.json" jsonStats = tstPaths.tmpDir / "sessionStats.json"
@@ -333,7 +333,7 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, projPath, tstPaths):
] ]
# Group by Day # Group by Day
qtbot.mouseClick(sessLog.groupByDay, Qt.LeftButton) qtbot.mouseClick(sessLog.groupByDay, QtMouseLeft)
assert sessLog._saveData(sessLog.FMT_JSON) assert sessLog._saveData(sessLog.FMT_JSON)
jsonStats = tstPaths.tmpDir / "sessionStats.json" jsonStats = tstPaths.tmpDir / "sessionStats.json"