Clean up a lot more namespace flags

This commit is contained in:
Veronica Berglyd Olsen
2024-04-03 20:25:54 +02:00
parent 46c5f1c10d
commit 20c5993e2d
38 changed files with 184 additions and 142 deletions
+3 -2
View File
@@ -35,6 +35,7 @@ from PyQt5.QtCore import QRectF
from novelwriter import CONFIG from novelwriter import CONFIG
from novelwriter.common import minmax, simplified from novelwriter.common import minmax, simplified
from novelwriter.types import QtPaintAnitAlias, QtTransparent
if TYPE_CHECKING: # pragma: no cover if TYPE_CHECKING: # pragma: no cover
from typing import TypeGuard # Requires Python 3.10 from typing import TypeGuard # Requires Python 3.10
@@ -248,10 +249,10 @@ class NWStatus:
def _createIcon(self, red: int, green: int, blue: int) -> QIcon: def _createIcon(self, red: int, green: int, blue: int) -> QIcon:
"""Generate an icon for a status label.""" """Generate an icon for a status label."""
pixmap = QPixmap(self._iPX, self._iPX) pixmap = QPixmap(self._iPX, self._iPX)
pixmap.fill(QColor(0, 0, 0, 0)) pixmap.fill(QtTransparent)
painter = QPainter(pixmap) painter = QPainter(pixmap)
painter.setRenderHint(QPainter.Antialiasing) painter.setRenderHint(QtPaintAnitAlias)
painter.fillPath(self._iconPath, QColor(red, green, blue)) painter.fillPath(self._iconPath, QColor(red, green, blue))
painter.end() painter.end()
+2 -2
View File
@@ -35,7 +35,7 @@ from novelwriter import CONFIG, SHARED
from novelwriter.common import readTextFile from novelwriter.common import readTextFile
from novelwriter.extensions.configlayout import NColourLabel from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.versioninfo import VersionInfoWidget from novelwriter.extensions.versioninfo import VersionInfoWidget
from novelwriter.types import QtAlignRightTop from novelwriter.types import QtAlignRightTop, QtDialogClose
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -84,7 +84,7 @@ class GuiAbout(QDialog):
self.txtCredits.setViewportMargins(0, hA, hA, 0) self.txtCredits.setViewportMargins(0, hA, hA, 0)
# Buttons # Buttons
self.btnBox = QDialogButtonBox(QDialogButtonBox.Close, self) self.btnBox = QDialogButtonBox(QtDialogClose, self)
self.btnBox.rejected.connect(self.close) self.btnBox.rejected.connect(self.close)
# Assemble # Assemble
+3 -3
View File
@@ -36,7 +36,7 @@ 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 from novelwriter.types import QtDialogCancel, QtDialogOk, QtDialogReset, QtUserRole
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -85,11 +85,11 @@ class GuiDocMerge(QDialog):
self.optBox.setColumnStretch(2, 1) self.optBox.setColumnStretch(2, 1)
# Buttons # Buttons
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.buttonBox = QDialogButtonBox(QtDialogOk | QtDialogCancel)
self.buttonBox.accepted.connect(self.accept) self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject) self.buttonBox.rejected.connect(self.reject)
self.resetButton = self.buttonBox.addButton(QDialogButtonBox.Reset) self.resetButton = self.buttonBox.addButton(QtDialogReset)
self.resetButton.clicked.connect(self._resetList) self.resetButton.clicked.connect(self._resetList)
# Assemble # Assemble
+2 -2
View File
@@ -36,7 +36,7 @@ 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 from novelwriter.types import QtDialogCancel, QtDialogOk, QtUserRole
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -115,7 +115,7 @@ class GuiDocSplit(QDialog):
self.optBox.setColumnStretch(3, 1) self.optBox.setColumnStretch(3, 1)
# Buttons # Buttons
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.buttonBox = QDialogButtonBox(QtDialogOk | QtDialogCancel)
self.buttonBox.accepted.connect(self.accept) self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject) self.buttonBox.rejected.connect(self.reject)
+3 -2
View File
@@ -31,6 +31,7 @@ from PyQt5.QtWidgets import (
) )
from novelwriter import CONFIG from novelwriter import CONFIG
from novelwriter.types import QtDialogCancel, QtDialogOk
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -55,7 +56,7 @@ class GuiEditLabel(QDialog):
self.labelValue.selectAll() self.labelValue.selectAll()
# Buttons # Buttons
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.buttonBox = QDialogButtonBox(QtDialogOk | QtDialogCancel)
self.buttonBox.accepted.connect(self.accept) self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject) self.buttonBox.rejected.connect(self.reject)
@@ -90,7 +91,7 @@ class GuiEditLabel(QDialog):
cls = GuiEditLabel(parent, text=text) cls = GuiEditLabel(parent, text=text)
cls.exec() cls.exec()
label = cls.itemLabel label = cls.itemLabel
accepted = cls.result() == QDialog.Accepted accepted = cls.result() == QDialog.DialogCode.Accepted
cls.deleteLater() cls.deleteLater()
return label, accepted return label, accepted
+8 -9
View File
@@ -41,7 +41,10 @@ from novelwriter.extensions.configlayout import NColourLabel, NScrollableForm
from novelwriter.extensions.modified import NComboBox, NDoubleSpinBox, NIconToolButton, NSpinBox from novelwriter.extensions.modified import NComboBox, NDoubleSpinBox, NIconToolButton, NSpinBox
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 QtAlignCenter from novelwriter.types import (
QtAlignCenter, QtDialogApply, QtDialogClose, QtDialogSave, QtRoleAccept,
QtRoleApply, QtRoleReject
)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -84,11 +87,7 @@ class GuiPreferences(QDialog):
self.mainForm.setHelpTextStyle(SHARED.theme.helpText) self.mainForm.setHelpTextStyle(SHARED.theme.helpText)
# Buttons # Buttons
self.buttonBox = QDialogButtonBox( self.buttonBox = QDialogButtonBox(QtDialogApply | QtDialogSave | QtDialogClose)
QDialogButtonBox.StandardButton.Apply
| QDialogButtonBox.StandardButton.Save
| QDialogButtonBox.StandardButton.Close
)
self.buttonBox.clicked.connect(self._dialogButtonClicked) self.buttonBox.clicked.connect(self._dialogButtonClicked)
# Assemble # Assemble
@@ -762,12 +761,12 @@ class GuiPreferences(QDialog):
def _dialogButtonClicked(self, button: QAbstractButton) -> None: def _dialogButtonClicked(self, button: QAbstractButton) -> None:
"""Handle button clicks from the dialog button box.""" """Handle button clicks from the dialog button box."""
role = self.buttonBox.buttonRole(button) role = self.buttonBox.buttonRole(button)
if role == QDialogButtonBox.ButtonRole.ApplyRole: if role == QtRoleApply:
self._saveValues() self._saveValues()
elif role == QDialogButtonBox.ButtonRole.AcceptRole: elif role == QtRoleAccept:
self._saveValues() self._saveValues()
self.close() self.close()
elif role == QDialogButtonBox.ButtonRole.RejectRole: elif role == QtRoleReject:
self.close() self.close()
return return
+2 -4
View File
@@ -40,7 +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 from novelwriter.types import QtDialogCancel, QtDialogSave, QtUserRole
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -84,9 +84,7 @@ class GuiProjectSettings(QDialog):
self.sidebar.buttonClicked.connect(self._sidebarClicked) self.sidebar.buttonClicked.connect(self._sidebarClicked)
# Buttons # Buttons
self.buttonBox = QDialogButtonBox( self.buttonBox = QDialogButtonBox(QtDialogSave | QtDialogCancel)
QDialogButtonBox.StandardButton.Save | QDialogButtonBox.StandardButton.Cancel
)
self.buttonBox.accepted.connect(self._doSave) self.buttonBox.accepted.connect(self._doSave)
self.buttonBox.rejected.connect(self.close) self.buttonBox.rejected.connect(self.close)
+2 -2
View File
@@ -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, QtUserRole from novelwriter.types import QtAlignCenter, QtAlignTop, QtDialogCancel, QtDialogOk, QtUserRole
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -90,7 +90,7 @@ class GuiQuoteSelect(QDialog):
self.listBox.setMinimumHeight(CONFIG.pxInt(150)) self.listBox.setMinimumHeight(CONFIG.pxInt(150))
# Buttons # Buttons
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.buttonBox = QDialogButtonBox(QtDialogOk | QtDialogCancel)
self.buttonBox.accepted.connect(self.accept) self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject) self.buttonBox.rejected.connect(self.reject)
+2 -1
View File
@@ -40,6 +40,7 @@ from novelwriter.common import formatFileFilter
from novelwriter.core.spellcheck import UserDictionary from novelwriter.core.spellcheck import UserDictionary
from novelwriter.extensions.configlayout import NColourLabel from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.modified import NIconToolButton from novelwriter.extensions.modified import NIconToolButton
from novelwriter.types import QtDialogClose, QtDialogSave
if TYPE_CHECKING: # pragma: no cover if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain from novelwriter.guimain import GuiMain
@@ -110,7 +111,7 @@ class GuiWordList(QDialog):
self.editBox.addWidget(self.delButton, 0) self.editBox.addWidget(self.delButton, 0)
# Buttons # Buttons
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Save | QDialogButtonBox.Close) self.buttonBox = QDialogButtonBox(QtDialogSave | QtDialogClose)
self.buttonBox.accepted.connect(self._doSave) self.buttonBox.accepted.connect(self._doSave)
self.buttonBox.rejected.connect(self.close) self.buttonBox.rejected.connect(self.close)
+4 -2
View File
@@ -74,7 +74,9 @@ class NWErrorMessage(QDialog):
# Widgets # Widgets
self.msgIcon = QLabel() self.msgIcon = QLabel()
self.msgIcon.setPixmap( self.msgIcon.setPixmap(
QApplication.style().standardIcon(QStyle.SP_MessageBoxCritical).pixmap(64, 64) QApplication.style().standardIcon(
QStyle.StandardPixmap.SP_MessageBoxCritical
).pixmap(64, 64)
) )
self.msgHead = QLabel() self.msgHead = QLabel()
self.msgHead.setOpenExternalLinks(True) self.msgHead.setOpenExternalLinks(True)
@@ -88,7 +90,7 @@ class NWErrorMessage(QDialog):
self.msgBody.setFont(font) self.msgBody.setFont(font)
self.msgBody.setReadOnly(True) self.msgBody.setReadOnly(True)
self.btnBox = QDialogButtonBox(QDialogButtonBox.Close) self.btnBox = QDialogButtonBox(QDialogButtonBox.StandardButton.Close)
self.btnBox.rejected.connect(self._doClose) self.btnBox.rejected.connect(self._doClose)
# Assemble # Assemble
+4 -2
View File
@@ -29,7 +29,9 @@ 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.QtWidgets import QProgressBar, QSizePolicy, QWidget from PyQt5.QtWidgets import QProgressBar, QSizePolicy, QWidget
from novelwriter.types import QtAlignCenter, QtRoundCap, QtSolidLine, QtTransparent from novelwriter.types import (
QtPaintAnitAlias, QtAlignCenter, QtRoundCap, QtSolidLine, QtTransparent
)
class NProgressCircle(QProgressBar): class NProgressCircle(QProgressBar):
@@ -87,7 +89,7 @@ class NProgressCircle(QProgressBar):
progress = 100.0*self.value()/self.maximum() progress = 100.0*self.value()/self.maximum()
angle = ceil(16*3.6*progress) angle = ceil(16*3.6*progress)
painter = QPainter(self) painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QtPaintAnitAlias, True)
painter.setPen(self._dPen) painter.setPen(self._dPen)
painter.setBrush(self._dBrush) painter.setBrush(self._dBrush)
painter.drawEllipse(self._dRect) painter.drawEllipse(self._dRect)
+1 -1
View File
@@ -258,7 +258,7 @@ class NColourLabel(QLabel):
font.setWeight(QFont.Weight.Bold if bold else QFont.Weight.Normal) font.setWeight(QFont.Weight.Bold if bold else QFont.Weight.Normal)
if color: if color:
colour = self.palette() colour = self.palette()
colour.setColor(QPalette.WindowText, color) colour.setColor(QPalette.ColorRole.WindowText, color)
self.setPalette(colour) self.setPalette(colour)
self.setFont(font) self.setFont(font)
+6 -6
View File
@@ -32,7 +32,7 @@ from PyQt5.QtWidgets import (
QStyleOptionToolButton, QToolBar, QToolButton, QWidget QStyleOptionToolButton, QToolBar, QToolButton, QWidget
) )
from novelwriter.types import QtAlignLeft, QtNoBrush, QtNoPen from novelwriter.types import QtPaintAnitAlias, QtAlignLeft, QtMouseOver, QtNoBrush, QtNoPen
class NPagedSideBar(QToolBar): class NPagedSideBar(QToolBar):
@@ -125,7 +125,7 @@ class _NPagedToolButton(QToolButton):
fH = self.fontMetrics().height() fH = self.fontMetrics().height()
self._bH = round(fH * 1.7) self._bH = round(fH * 1.7)
self._tM = (self._bH - fH)//2 self._tM = (self._bH - fH)//2
self._lM = 3*self.style().pixelMetric(QStyle.PM_ButtonMargin)//2 self._lM = 3*self.style().pixelMetric(QStyle.PixelMetric.PM_ButtonMargin)//2
self._cR = self._lM//2 self._cR = self._lM//2
self._aH = 2*fH//7 self._aH = 2*fH//7
self.setFixedHeight(self._bH) self.setFixedHeight(self._bH)
@@ -145,7 +145,7 @@ class _NPagedToolButton(QToolButton):
opt.initFrom(self) opt.initFrom(self)
paint = QPainter(self) paint = QPainter(self)
paint.setRenderHint(QPainter.Antialiasing, True) paint.setRenderHint(QtPaintAnitAlias, True)
paint.setPen(QtNoPen) paint.setPen(QtNoPen)
paint.setBrush(QtNoBrush) paint.setBrush(QtNoBrush)
@@ -153,7 +153,7 @@ class _NPagedToolButton(QToolButton):
height = self.height() height = self.height()
palette = self.palette() palette = self.palette()
if opt.state & QStyle.State_MouseOver == QStyle.State_MouseOver: if opt.state & QtMouseOver == QtMouseOver:
backCol = palette.base() backCol = palette.base()
paint.setBrush(backCol) paint.setBrush(backCol)
paint.setOpacity(0.75) paint.setOpacity(0.75)
@@ -202,7 +202,7 @@ class _NPagedToolLabel(QLabel):
fH = self.fontMetrics().height() fH = self.fontMetrics().height()
self._bH = round(fH * 1.7) self._bH = round(fH * 1.7)
self._tM = (self._bH - fH)//2 self._tM = (self._bH - fH)//2
self._lM = self.style().pixelMetric(QStyle.PM_ButtonMargin)//2 self._lM = self.style().pixelMetric(QStyle.PixelMetric.PM_ButtonMargin)//2
self.setFixedHeight(self._bH) self.setFixedHeight(self._bH)
self._textCol = textColor or self.palette().text().color() self._textCol = textColor or self.palette().text().color()
@@ -214,7 +214,7 @@ class _NPagedToolLabel(QLabel):
label that matches the button style. label that matches the button style.
""" """
paint = QPainter(self) paint = QPainter(self)
paint.setRenderHint(QPainter.Antialiasing, True) paint.setRenderHint(QtPaintAnitAlias, True)
paint.setPen(QtNoPen) paint.setPen(QtNoPen)
width = self.width() width = self.width()
+3 -1
View File
@@ -28,6 +28,8 @@ from math import ceil
from PyQt5.QtGui import QPaintEvent, QPainter from PyQt5.QtGui import QPaintEvent, QPainter
from PyQt5.QtWidgets import QProgressBar, QWidget from PyQt5.QtWidgets import QProgressBar, QWidget
from novelwriter.types import QtPaintAnitAlias
class NProgressSimple(QProgressBar): class NProgressSimple(QProgressBar):
"""Extension: Simple Progress Widget """Extension: Simple Progress Widget
@@ -44,7 +46,7 @@ class NProgressSimple(QProgressBar):
if (value := self.value()) > 0: if (value := self.value()) > 0:
progress = ceil(self.width()*float(value)/self.maximum()) progress = ceil(self.width()*float(value)/self.maximum())
painter = QPainter(self) painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QtPaintAnitAlias, True)
painter.setPen(self.palette().highlight().color()) painter.setPen(self.palette().highlight().color())
painter.setBrush(self.palette().highlight()) painter.setBrush(self.palette().highlight())
painter.drawRect(0, 0, progress, self.height()) painter.drawRect(0, 0, progress, self.height())
+3 -1
View File
@@ -30,6 +30,8 @@ from typing import Literal
from PyQt5.QtGui import QColor, QPaintEvent, QPainter from PyQt5.QtGui import QColor, QPaintEvent, QPainter
from PyQt5.QtWidgets import QAbstractButton, QWidget from PyQt5.QtWidgets import QAbstractButton, QWidget
from novelwriter.types import QtPaintAnitAlias
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -67,7 +69,7 @@ class StatusLED(QAbstractButton):
def paintEvent(self, event: QPaintEvent) -> None: def paintEvent(self, event: QPaintEvent) -> None:
"""Draw the LED.""" """Draw the LED."""
painter = QPainter(self) painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QtPaintAnitAlias, True)
painter.setPen(self.palette().dark().color()) painter.setPen(self.palette().dark().color())
painter.setBrush(self._theCol) painter.setBrush(self._theCol)
painter.setOpacity(1.0) painter.setOpacity(1.0)
+2 -2
View File
@@ -28,7 +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 from novelwriter.types import QtPaintAnitAlias, QtMouseLeft, QtNoPen
class NSwitch(QAbstractButton): class NSwitch(QAbstractButton):
@@ -90,7 +90,7 @@ class NSwitch(QAbstractButton):
def paintEvent(self, event: QPaintEvent) -> None: def paintEvent(self, event: QPaintEvent) -> None:
"""Drawing the switch itself.""" """Drawing the switch itself."""
painter = QPainter(self) painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QtPaintAnitAlias, True)
painter.setPen(QtNoPen) painter.setPen(QtNoPen)
palette = self.palette() palette = self.palette()
+2 -2
View File
@@ -125,7 +125,7 @@ class GuiSideBar(QWidget):
def updateTheme(self) -> None: def updateTheme(self) -> None:
"""Initialise GUI elements that depend on specific settings.""" """Initialise GUI elements that depend on specific settings."""
qPalette = self.palette() qPalette = self.palette()
qPalette.setBrush(QPalette.Window, qPalette.base()) qPalette.setBrush(QPalette.ColorRole.Window, qPalette.base())
self.setPalette(qPalette) self.setPalette(qPalette)
buttonStyle = SHARED.theme.getStyleSheet(STYLES_BIG_TOOLBUTTON) buttonStyle = SHARED.theme.getStyleSheet(STYLES_BIG_TOOLBUTTON)
@@ -157,7 +157,7 @@ class _PopRightMenu(QMenu):
def event(self, event: QEvent) -> bool: def event(self, event: QEvent) -> bool:
"""Overload the show event and move the menu popup location.""" """Overload the show event and move the menu popup location."""
if event.type() == QEvent.Show: if event.type() == QEvent.Type.Show:
if isinstance(parent := self.parent(), QWidget): if isinstance(parent := self.parent(), QWidget):
offset = QPoint(parent.width(), parent.height() - self.height()) offset = QPoint(parent.width(), parent.height() - self.height())
self.move(parent.mapToGlobal(offset)) self.move(parent.mapToGlobal(offset))
+2 -1
View File
@@ -39,6 +39,7 @@ from novelwriter import CONFIG, SHARED
from novelwriter.common import formatFileFilter, openExternalPath, formatInt, getFileSize from novelwriter.common import formatFileFilter, openExternalPath, formatInt, getFileSize
from novelwriter.error import formatException from novelwriter.error import formatException
from novelwriter.extensions.modified import NIconToolButton from novelwriter.extensions.modified import NIconToolButton
from novelwriter.types import QtDialogClose
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -107,7 +108,7 @@ class GuiDictionaries(QDialog):
self.infoBox.setFrameStyle(QFrame.Shape.NoFrame) self.infoBox.setFrameStyle(QFrame.Shape.NoFrame)
# Buttons # Buttons
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Close) self.buttonBox = QDialogButtonBox(QtDialogClose)
self.buttonBox.rejected.connect(self._doClose) self.buttonBox.rejected.connect(self._doClose)
# Assemble # Assemble
+3 -3
View File
@@ -35,7 +35,7 @@ from PyQt5.QtWidgets import (
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.common import readTextFile from novelwriter.common import readTextFile
from novelwriter.extensions.switch import NSwitch from novelwriter.extensions.switch import NSwitch
from novelwriter.types import QtAlignLeft, QtAlignRight from novelwriter.types import QtAlignLeft, QtAlignRight, QtRoleAction, QtDialogClose
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -96,10 +96,10 @@ class GuiLipsum(QDialog):
self.buttonBox = QDialogButtonBox() self.buttonBox = QDialogButtonBox()
self.buttonBox.rejected.connect(self.close) self.buttonBox.rejected.connect(self.close)
self.btnClose = self.buttonBox.addButton(QDialogButtonBox.Close) self.btnClose = self.buttonBox.addButton(QtDialogClose)
self.btnClose.setAutoDefault(False) self.btnClose.setAutoDefault(False)
self.btnInsert = self.buttonBox.addButton(self.tr("Insert"), QDialogButtonBox.ActionRole) self.btnInsert = self.buttonBox.addButton(self.tr("Insert"), QtRoleAction)
self.btnInsert.clicked.connect(self._doInsert) self.btnInsert.clicked.connect(self._doInsert)
self.btnInsert.setAutoDefault(False) self.btnInsert.setAutoDefault(False)
+8 -6
View File
@@ -44,7 +44,9 @@ 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, QtUserRole from novelwriter.types import (
QtAlignCenter, QtDialogClose, QtRoleAction, QtRoleReject, QtUserRole
)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -184,9 +186,9 @@ class GuiManuscriptBuild(QDialog):
self.btnBuild = QPushButton(SHARED.theme.getIcon("export"), self.tr("&Build")) self.btnBuild = QPushButton(SHARED.theme.getIcon("export"), self.tr("&Build"))
self.btnBuild.setIconSize(bSz) self.btnBuild.setIconSize(bSz)
self.dlgButtons = QDialogButtonBox(QDialogButtonBox.StandardButton.Close) self.dlgButtons = QDialogButtonBox(QtDialogClose)
self.dlgButtons.addButton(self.btnOpen, QDialogButtonBox.ButtonRole.ActionRole) self.dlgButtons.addButton(self.btnOpen, QtRoleAction)
self.dlgButtons.addButton(self.btnBuild, QDialogButtonBox.ButtonRole.ActionRole) self.dlgButtons.addButton(self.btnBuild, QtRoleAction)
# Assemble GUI # Assemble GUI
# ============ # ============
@@ -261,12 +263,12 @@ class GuiManuscriptBuild(QDialog):
def _dialogButtonClicked(self, button: QAbstractButton): def _dialogButtonClicked(self, button: QAbstractButton):
"""Handle button clicks from the dialog button box.""" """Handle button clicks from the dialog button box."""
role = self.dlgButtons.buttonRole(button) role = self.dlgButtons.buttonRole(button)
if role == QDialogButtonBox.ActionRole: if role == QtRoleAction:
if button == self.btnBuild: if button == self.btnBuild:
self._runBuild() self._runBuild()
elif button == self.btnOpen: elif button == self.btnOpen:
self._openOutputFolder() self._openOutputFolder()
elif role == QDialogButtonBox.RejectRole: elif role == QtRoleReject:
self.close() self.close()
return return
+5 -5
View File
@@ -104,7 +104,7 @@ class GuiManuscript(QDialog):
# ============== # ==============
qPalette = self.palette() qPalette = self.palette()
qPalette.setBrush(QPalette.Window, qPalette.base()) qPalette.setBrush(QPalette.ColorRole.Window, qPalette.base())
self.setPalette(qPalette) self.setPalette(qPalette)
buttonStyle = SHARED.theme.getStyleSheet(STYLES_MIN_TOOLBUTTON) buttonStyle = SHARED.theme.getStyleSheet(STYLES_MIN_TOOLBUTTON)
@@ -751,8 +751,8 @@ class _PreviewWidget(QTextBrowser):
# Document Setup # Document Setup
dPalette = self.palette() dPalette = self.palette()
dPalette.setColor(QPalette.Base, QColor(255, 255, 255)) dPalette.setColor(QPalette.ColorRole.Base, QColor(255, 255, 255))
dPalette.setColor(QPalette.Text, QColor(0, 0, 0)) dPalette.setColor(QPalette.ColorRole.Text, QColor(0, 0, 0))
self.setPalette(dPalette) self.setPalette(dPalette)
self.setMinimumWidth(40*SHARED.theme.textNWidth) self.setMinimumWidth(40*SHARED.theme.textNWidth)
@@ -769,8 +769,8 @@ class _PreviewWidget(QTextBrowser):
# Document Age # Document Age
aPalette = self.palette() aPalette = self.palette()
aPalette.setColor(QPalette.Background, aPalette.toolTipBase().color()) aPalette.setColor(QPalette.ColorRole.Window, aPalette.toolTipBase().color())
aPalette.setColor(QPalette.Foreground, aPalette.toolTipText().color()) aPalette.setColor(QPalette.ColorRole.WindowText, aPalette.toolTipText().color())
aFont = self.font() aFont = self.font()
aFont.setPointSizeF(0.9*SHARED.theme.fontPointSize) aFont.setPointSizeF(0.9*SHARED.theme.fontPointSize)
+8 -9
View File
@@ -46,7 +46,10 @@ 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, QtUserRole from novelwriter.types import (
QtAlignLeft, QtDialogApply, QtDialogClose, QtDialogSave, QtRoleAccept,
QtRoleApply, QtRoleReject, QtUserRole
)
if TYPE_CHECKING: # pragma: no cover if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain from novelwriter.guimain import GuiMain
@@ -131,11 +134,7 @@ class GuiBuildSettings(QDialog):
self.toolStack.addWidget(self.optTabOutput) self.toolStack.addWidget(self.optTabOutput)
# Buttons # Buttons
self.buttonBox = QDialogButtonBox( self.buttonBox = QDialogButtonBox(QtDialogApply | QtDialogSave | QtDialogClose)
QDialogButtonBox.StandardButton.Apply
| QDialogButtonBox.StandardButton.Save
| QDialogButtonBox.StandardButton.Close
)
self.buttonBox.clicked.connect(self._dialogButtonClicked) self.buttonBox.clicked.connect(self._dialogButtonClicked)
# Assemble # Assemble
@@ -226,12 +225,12 @@ class GuiBuildSettings(QDialog):
def _dialogButtonClicked(self, button: QAbstractButton) -> None: def _dialogButtonClicked(self, button: QAbstractButton) -> None:
"""Handle button clicks from the dialog button box.""" """Handle button clicks from the dialog button box."""
role = self.buttonBox.buttonRole(button) role = self.buttonBox.buttonRole(button)
if role == QDialogButtonBox.ApplyRole: if role == QtRoleApply:
self._emitBuildData() self._emitBuildData()
elif role == QDialogButtonBox.AcceptRole: elif role == QtRoleAccept:
self._emitBuildData() self._emitBuildData()
self.close() self.close()
elif role == QDialogButtonBox.RejectRole: elif role == QtRoleReject:
self.close() self.close()
return return
+2 -2
View File
@@ -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, QtDecoration from novelwriter.types import QtAlignRight, QtDecoration, QtDialogClose
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -95,7 +95,7 @@ class GuiNovelDetails(QDialog):
self.mainStack.addWidget(self.contentsPage) self.mainStack.addWidget(self.contentsPage)
# Buttons # Buttons
self.buttonBox = QDialogButtonBox(QDialogButtonBox.StandardButton.Close) self.buttonBox = QDialogButtonBox(QtDialogClose)
self.buttonBox.rejected.connect(self.close) self.buttonBox.rejected.connect(self.close)
# Assemble # Assemble
+5 -5
View File
@@ -36,8 +36,8 @@ from PyQt5.QtGui import QCloseEvent, QColor, QFont, QPaintEvent, QPainter, QPen
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAction, QApplication, QDialog, QFileDialog, QFormLayout, QHBoxLayout, QAction, QApplication, QDialog, QFileDialog, QFormLayout, QHBoxLayout,
QLabel, QLineEdit, QListView, QMenu, QPushButton, QScrollArea, QShortcut, QLabel, QLineEdit, QListView, QMenu, QPushButton, QScrollArea, QShortcut,
QStackedWidget, QStyle, QStyleOptionViewItem, QStyledItemDelegate, QStackedWidget, QStyleOptionViewItem, QStyledItemDelegate, QVBoxLayout,
QVBoxLayout, QWidget QWidget
) )
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
@@ -49,7 +49,7 @@ from novelwriter.extensions.configlayout import NWrappedWidgetBox
from novelwriter.extensions.modified import NIconToolButton, NSpinBox from novelwriter.extensions.modified import NIconToolButton, NSpinBox
from novelwriter.extensions.switch import NSwitch from novelwriter.extensions.switch import NSwitch
from novelwriter.extensions.versioninfo import VersionInfoWidget from novelwriter.extensions.versioninfo import VersionInfoWidget
from novelwriter.types import QtAlignLeft, QtAlignRightTop from novelwriter.types import QtAlignLeft, QtAlignRightTop, QtSelected
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -431,7 +431,7 @@ class _ProjectListItem(QStyledItemDelegate):
ix, iy, x, y1, y2 = self._pPx ix, iy, x, y1, y2 = self._pPx
painter.save() painter.save()
if opt.state & QStyle.StateFlag.State_Selected == QStyle.StateFlag.State_Selected: if opt.state & QtSelected == QtSelected:
painter.setOpacity(0.25) painter.setOpacity(0.25)
painter.fillRect(rect, QApplication.palette().highlight()) painter.fillRect(rect, QApplication.palette().highlight())
painter.setOpacity(1.0) painter.setOpacity(1.0)
@@ -813,7 +813,7 @@ class _PopLeftDirectionMenu(QMenu):
def event(self, event: QEvent) -> bool: def event(self, event: QEvent) -> bool:
"""Overload the show event and move the menu popup location.""" """Overload the show event and move the menu popup location."""
if event.type() == QEvent.Show: if event.type() == QEvent.Type.Show:
if isinstance(parent := self.parent(), QWidget): if isinstance(parent := self.parent(), QWidget):
offset = QPoint(parent.width() - self.width(), parent.height()) offset = QPoint(parent.width() - self.width(), parent.height())
self.move(parent.mapToGlobal(offset)) self.move(parent.mapToGlobal(offset))
+7 -4
View File
@@ -42,7 +42,10 @@ 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, QtDecoration from novelwriter.types import (
QtAlignLeftMiddle, QtAlignRight, QtAlignRightMiddle, QtDecoration,
QtDialogClose, QtRoleAction
)
if TYPE_CHECKING: # pragma: no cover if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain from novelwriter.guimain import GuiMain
@@ -262,13 +265,13 @@ class GuiWritingStats(QDialog):
self.optsBox.addWidget(self.histMax, 0) self.optsBox.addWidget(self.histMax, 0)
# Buttons # Buttons
self.buttonBox = QDialogButtonBox() self.buttonBox = QDialogButtonBox(self)
self.buttonBox.rejected.connect(self._doClose) self.buttonBox.rejected.connect(self._doClose)
self.btnClose = self.buttonBox.addButton(QDialogButtonBox.Close) self.btnClose = self.buttonBox.addButton(QtDialogClose)
self.btnClose.setAutoDefault(False) self.btnClose.setAutoDefault(False)
self.btnSave = self.buttonBox.addButton(self.tr("Save As"), QDialogButtonBox.ActionRole) self.btnSave = self.buttonBox.addButton(self.tr("Save As"), QtRoleAction)
self.btnSave.setAutoDefault(False) self.btnSave.setAutoDefault(False)
self.saveMenu = QMenu(self) self.saveMenu = QMenu(self)
+19 -1
View File
@@ -24,7 +24,8 @@ 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 from PyQt5.QtGui import QColor, QPainter
from PyQt5.QtWidgets import QDialogButtonBox, QStyle
# Qt Alignment Flags # Qt Alignment Flags
@@ -50,6 +51,9 @@ QtNoBrush = Qt.BrushStyle.NoBrush
QtNoPen = Qt.PenStyle.NoPen QtNoPen = Qt.PenStyle.NoPen
QtRoundCap = Qt.PenCapStyle.RoundCap QtRoundCap = Qt.PenCapStyle.RoundCap
QtSolidLine = Qt.PenStyle.SolidLine QtSolidLine = Qt.PenStyle.SolidLine
QtPaintAnitAlias = QPainter.RenderHint.Antialiasing
QtMouseOver = QStyle.StateFlag.State_MouseOver
QtSelected = QStyle.StateFlag.State_Selected
# Qt Tree and Table Types # Qt Tree and Table Types
@@ -63,3 +67,17 @@ QtModeNone = Qt.KeyboardModifier.NoModifier
QtModShift = Qt.KeyboardModifier.ShiftModifier QtModShift = Qt.KeyboardModifier.ShiftModifier
QtMouseLeft = Qt.MouseButton.LeftButton QtMouseLeft = Qt.MouseButton.LeftButton
QtMouseMiddle = Qt.MouseButton.MiddleButton QtMouseMiddle = Qt.MouseButton.MiddleButton
# Dialog Button Box Types
QtDialogApply = QDialogButtonBox.StandardButton.Apply
QtDialogCancel = QDialogButtonBox.StandardButton.Cancel
QtDialogClose = QDialogButtonBox.StandardButton.Close
QtDialogOk = QDialogButtonBox.StandardButton.Ok
QtDialogReset = QDialogButtonBox.StandardButton.Reset
QtDialogSave = QDialogButtonBox.StandardButton.Save
QtRoleAccept = QDialogButtonBox.ButtonRole.AcceptRole
QtRoleAction = QDialogButtonBox.ButtonRole.ActionRole
QtRoleApply = QDialogButtonBox.ButtonRole.ApplyRole
QtRoleReject = QDialogButtonBox.ButtonRole.RejectRole
+3 -3
View File
@@ -47,7 +47,7 @@ def testDlgOther_QuoteSelect(qtbot, monkeypatch, nwGUI):
assert nwQuot.previewLabel.text() == lastItem assert nwQuot.previewLabel.text() == lastItem
nwQuot.accept() nwQuot.accept()
assert nwQuot.result() == QDialog.Accepted assert nwQuot.result() == QDialog.DialogCode.Accepted
assert nwQuot.selectedQuote == lastItem assert nwQuot.selectedQuote == lastItem
nwQuot.close() nwQuot.close()
@@ -71,13 +71,13 @@ def testDlgOther_EditLabel(qtbot, monkeypatch):
monkeypatch.setattr(GuiEditLabel, "exec", lambda *a: None) monkeypatch.setattr(GuiEditLabel, "exec", lambda *a: None)
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(GuiEditLabel, "result", lambda *a: QDialog.Accepted) mp.setattr(GuiEditLabel, "result", lambda *a: QDialog.DialogCode.Accepted)
newLabel, dlgOk = GuiEditLabel.getLabel(None, text="Hello World") # type: ignore newLabel, dlgOk = GuiEditLabel.getLabel(None, text="Hello World") # type: ignore
assert dlgOk is True assert dlgOk is True
assert newLabel == "Hello World" assert newLabel == "Hello World"
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(GuiEditLabel, "result", lambda *a: QDialog.Rejected) mp.setattr(GuiEditLabel, "result", lambda *a: QDialog.DialogCode.Rejected)
newLabel, dlgOk = GuiEditLabel.getLabel(None, text="Hello World") # type: ignore newLabel, dlgOk = GuiEditLabel.getLabel(None, text="Hello World") # type: ignore
assert dlgOk is False assert dlgOk is False
assert newLabel == "Hello World" assert newLabel == "Hello World"
+6 -6
View File
@@ -24,13 +24,13 @@ import pytest
from PyQt5.QtGui import QFontDatabase, QKeyEvent from PyQt5.QtGui import QFontDatabase, QKeyEvent
from PyQt5.QtCore import QEvent, Qt from PyQt5.QtCore import QEvent, Qt
from PyQt5.QtWidgets import QAction, QDialogButtonBox, QFileDialog, QFontDialog from PyQt5.QtWidgets import QAction, QFileDialog, QFontDialog
from novelwriter import CONFIG, SHARED 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 from novelwriter.types import QtDialogApply, QtDialogClose, QtDialogSave, QtModeNone
KEY_DELAY = 1 KEY_DELAY = 1
@@ -122,21 +122,21 @@ def testDlgPreferences_Actions(qtbot, monkeypatch, nwGUI):
# Check Apply Button # Check Apply Button
prefs.show() prefs.show()
with qtbot.waitSignal(prefs.newPreferencesReady) as signal: with qtbot.waitSignal(prefs.newPreferencesReady) as signal:
prefs.buttonBox.button(QDialogButtonBox.StandardButton.Apply).click() prefs.buttonBox.button(QtDialogApply).click()
assert signal.args == [False, False, False, False] assert signal.args == [False, False, False, False]
# Check Save Button # Check Save Button
prefs.show() prefs.show()
with qtbot.waitSignal(prefs.newPreferencesReady) as signal: with qtbot.waitSignal(prefs.newPreferencesReady) as signal:
with qtbot.waitSignal(prefs.finished) as status: with qtbot.waitSignal(prefs.finished) as status:
prefs.buttonBox.button(QDialogButtonBox.StandardButton.Save).click() prefs.buttonBox.button(QtDialogSave).click()
assert signal.args == [False, False, False, False] assert signal.args == [False, False, False, False]
assert status.args == [nwConst.DLG_FINISHED] assert status.args == [nwConst.DLG_FINISHED]
# Check Close Button # Check Close Button
prefs.show() prefs.show()
with qtbot.waitSignal(prefs.finished) as status: with qtbot.waitSignal(prefs.finished) as status:
prefs.buttonBox.button(QDialogButtonBox.StandardButton.Close).click() prefs.buttonBox.button(QtDialogClose).click()
assert status.args == [nwConst.DLG_FINISHED] assert status.args == [nwConst.DLG_FINISHED]
# Close Using Escape Key # Close Using Escape Key
@@ -333,7 +333,7 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QFontDatabase, "families", lambda *a: ["TestFont"]) mp.setattr(QFontDatabase, "families", lambda *a: ["TestFont"])
with qtbot.waitSignal(prefs.newPreferencesReady) as signal: with qtbot.waitSignal(prefs.newPreferencesReady) as signal:
prefs.buttonBox.button(QDialogButtonBox.StandardButton.Apply).click() prefs.buttonBox.button(QtDialogApply).click()
assert signal.args == [True, True, True, True] assert signal.args == [True, True, True, True]
# Check Settings # Check Settings
@@ -44,7 +44,7 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI):
""" """
# Block the GUI blocking thread # Block the GUI blocking thread
monkeypatch.setattr(GuiProjectSettings, "exec", lambda *a: None) monkeypatch.setattr(GuiProjectSettings, "exec", lambda *a: None)
monkeypatch.setattr(GuiProjectSettings, "result", lambda *a: QDialog.Accepted) monkeypatch.setattr(GuiProjectSettings, "result", lambda *a: QDialog.DialogCode.Accepted)
# Check that we cannot open when there is no project # Check that we cannot open when there is no project
nwGUI.mainMenu.aProjectSettings.activate(QAction.Trigger) nwGUI.mainMenu.aProjectSettings.activate(QAction.Trigger)
+1 -1
View File
@@ -39,7 +39,7 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, fncPath, projPath):
buildTestProject(nwGUI, projPath) buildTestProject(nwGUI, projPath)
monkeypatch.setattr(GuiWordList, "exec", lambda *a: None) monkeypatch.setattr(GuiWordList, "exec", lambda *a: None)
monkeypatch.setattr(GuiWordList, "result", lambda *a: QDialog.Accepted) monkeypatch.setattr(GuiWordList, "result", lambda *a: QDialog.DialogCode.Accepted)
monkeypatch.setattr(GuiWordList, "accept", lambda *a: None) monkeypatch.setattr(GuiWordList, "accept", lambda *a: None)
# Open project # Open project
+2 -1
View File
@@ -27,6 +27,7 @@ from PyQt5.QtCore import QEvent, QObject, QPoint, Qt
from PyQt5.QtWidgets import QWidget from PyQt5.QtWidgets import QWidget
from novelwriter.extensions.eventfilters import WheelEventFilter from novelwriter.extensions.eventfilters import WheelEventFilter
from novelwriter.types import QtModShift
class MockWidget(QWidget): class MockWidget(QWidget):
@@ -50,7 +51,7 @@ def testExtEventFilters_WheelEventFilter():
assert widget.count == 0 assert widget.count == 0
# Sending a key event does nothing # Sending a key event does nothing
event = QKeyEvent(QEvent.KeyPress, 1, Qt.ShiftModifier) event = QKeyEvent(QEvent.Type.KeyPress, 1, QtModShift)
eFilter.eventFilter(obj, event) eFilter.eventFilter(obj, event)
assert widget.count == 0 assert widget.count == 0
+1 -1
View File
@@ -62,7 +62,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
# Re-select via header click # Re-select via header click
button = QtMouseLeft button = QtMouseLeft
modifier = QtModeNone modifier = QtModeNone
event = QMouseEvent(QEvent.MouseButtonPress, QPoint(), button, button, modifier) event = QMouseEvent(QEvent.Type.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"
+1 -1
View File
@@ -225,7 +225,7 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
scItem = novelTree.topLevelItem(2) scItem = novelTree.topLevelItem(2)
scItem.setSelected(True) scItem.setSelected(True)
assert scItem.isSelected() assert scItem.isSelected()
novelTree.focusOutEvent(QFocusEvent(QEvent.None_, Qt.MouseFocusReason)) novelTree.focusOutEvent(QFocusEvent(QEvent.Type.None_, Qt.MouseFocusReason))
assert not scItem.isSelected() assert not scItem.isSelected()
# Close # Close
+4 -4
View File
@@ -541,7 +541,7 @@ def testGuiProjTree_MergeDocuments(qtbot, monkeypatch, nwGUI, projPath, mockRnd,
monkeypatch.setattr(GuiDocMerge, "__init__", lambda *a: None) monkeypatch.setattr(GuiDocMerge, "__init__", lambda *a: None)
monkeypatch.setattr(GuiDocMerge, "exec", lambda *a: None) monkeypatch.setattr(GuiDocMerge, "exec", lambda *a: None)
monkeypatch.setattr(GuiDocMerge, "result", lambda *a: QDialog.Accepted) monkeypatch.setattr(GuiDocMerge, "result", lambda *a: QDialog.DialogCode.Accepted)
monkeypatch.setattr(GuiDocMerge, "getData", lambda *a: mergeData) monkeypatch.setattr(GuiDocMerge, "getData", lambda *a: mergeData)
buildTestProject(nwGUI, projPath) buildTestProject(nwGUI, projPath)
@@ -597,7 +597,7 @@ def testGuiProjTree_MergeDocuments(qtbot, monkeypatch, nwGUI, projPath, mockRnd,
# User cancels merge # User cancels merge
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(GuiDocMerge, "result", lambda *a: QDialog.Rejected) mp.setattr(GuiDocMerge, "result", lambda *a: QDialog.DialogCode.Rejected)
assert projTree._mergeDocuments(hChapter1, True) is False assert projTree._mergeDocuments(hChapter1, True) is False
# The merge goes through # The merge goes through
@@ -642,7 +642,7 @@ def testGuiProjTree_SplitDocument(qtbot, monkeypatch, nwGUI, projPath, mockRnd,
monkeypatch.setattr(GuiDocSplit, "__init__", lambda *a: None) monkeypatch.setattr(GuiDocSplit, "__init__", lambda *a: None)
monkeypatch.setattr(GuiDocSplit, "exec", lambda *a: None) monkeypatch.setattr(GuiDocSplit, "exec", lambda *a: None)
monkeypatch.setattr(GuiDocSplit, "result", lambda *a: QDialog.Accepted) monkeypatch.setattr(GuiDocSplit, "result", lambda *a: QDialog.DialogCode.Accepted)
monkeypatch.setattr(GuiDocSplit, "getData", lambda *a: (splitData, splitText)) monkeypatch.setattr(GuiDocSplit, "getData", lambda *a: (splitData, splitText))
# Create a project # Create a project
@@ -736,7 +736,7 @@ def testGuiProjTree_SplitDocument(qtbot, monkeypatch, nwGUI, projPath, mockRnd,
# Cancelled by user # Cancelled by user
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(GuiDocSplit, "result", lambda *a: QDialog.Rejected) mp.setattr(GuiDocSplit, "result", lambda *a: QDialog.DialogCode.Rejected)
assert projTree._splitDocument(hSplitDoc) is False assert projTree._splitDocument(hSplitDoc) is False
# qtbot.stop() # qtbot.stop()
+33 -25
View File
@@ -106,22 +106,22 @@ def testGuiTheme_Main(qtbot, nwGUI, tstPaths):
assert mainTheme._parseColour(parser, "Palette", "colour6").getRgb() == (0, 127, 255, 255) assert mainTheme._parseColour(parser, "Palette", "colour6").getRgb() == (0, 127, 255, 255)
# The palette should load with the parsed values # The palette should load with the parsed values
mainTheme._setPalette(parser, "Palette", "colour1", QPalette.Window) mainTheme._setPalette(parser, "Palette", "colour1", QPalette.ColorRole.Window)
assert mainTheme._guiPalette.color(QPalette.Window).getRgb() == (100, 150, 200, 255) assert mainTheme._guiPalette.color(QPalette.ColorRole.Window).getRgb() == (100, 150, 200, 255)
mainTheme._setPalette(parser, "Palette", "colour2", QPalette.Window) mainTheme._setPalette(parser, "Palette", "colour2", QPalette.ColorRole.Window)
assert mainTheme._guiPalette.color(QPalette.Window).getRgb() == (100, 150, 200, 250) assert mainTheme._guiPalette.color(QPalette.ColorRole.Window).getRgb() == (100, 150, 200, 250)
mainTheme._setPalette(parser, "Palette", "colour3", QPalette.Window) mainTheme._setPalette(parser, "Palette", "colour3", QPalette.ColorRole.Window)
assert mainTheme._guiPalette.color(QPalette.Window).getRgb() == (100, 150, 200, 250) assert mainTheme._guiPalette.color(QPalette.ColorRole.Window).getRgb() == (100, 150, 200, 250)
mainTheme._setPalette(parser, "Palette", "colour4", QPalette.Window) mainTheme._setPalette(parser, "Palette", "colour4", QPalette.ColorRole.Window)
assert mainTheme._guiPalette.color(QPalette.Window).getRgb() == (250, 250, 0, 255) assert mainTheme._guiPalette.color(QPalette.ColorRole.Window).getRgb() == (250, 250, 0, 255)
mainTheme._setPalette(parser, "Palette", "colour5", QPalette.Window) mainTheme._setPalette(parser, "Palette", "colour5", QPalette.ColorRole.Window)
assert mainTheme._guiPalette.color(QPalette.Window).getRgb() == (0, 0, 0, 0) assert mainTheme._guiPalette.color(QPalette.ColorRole.Window).getRgb() == (0, 0, 0, 0)
mainTheme._setPalette(parser, "Palette", "colour6", QPalette.Window) mainTheme._setPalette(parser, "Palette", "colour6", QPalette.ColorRole.Window)
assert mainTheme._guiPalette.color(QPalette.Window).getRgb() == (0, 127, 255, 255) assert mainTheme._guiPalette.color(QPalette.ColorRole.Window).getRgb() == (0, 127, 255, 255)
# Non-existing value should return default colour # Non-existing value should return default colour
mainTheme._setPalette(parser, "Palette", "stuff", QPalette.Window) mainTheme._setPalette(parser, "Palette", "stuff", QPalette.ColorRole.Window)
assert mainTheme._guiPalette.color(QPalette.Window).getRgb() == (0, 0, 0, 255) assert mainTheme._guiPalette.color(QPalette.ColorRole.Window).getRgb() == (0, 0, 0, 255)
# qtbot.stop() # qtbot.stop()
@@ -168,15 +168,15 @@ def testGuiTheme_Theme(qtbot, monkeypatch, nwGUI):
# ================== # ==================
# Set a mock colour for the window background # Set a mock colour for the window background
mainTheme._guiPalette.color(QPalette.Window).setRgb(0, 0, 0, 0) mainTheme._guiPalette.color(QPalette.ColorRole.Window).setRgb(0, 0, 0, 0)
# Load the default theme # Load the default theme
CONFIG.guiTheme = "default" CONFIG.guiTheme = "default"
assert mainTheme.loadTheme() is True assert mainTheme.loadTheme() is True
# This should load a standard palette # This should load a standard palette
wCol = QApplication.style().standardPalette().color(QPalette.Window).getRgb() wCol = QApplication.style().standardPalette().color(QPalette.ColorRole.Window).getRgb()
assert mainTheme._guiPalette.color(QPalette.Window).getRgb() == wCol assert mainTheme._guiPalette.color(QPalette.ColorRole.Window).getRgb() == wCol
# Load Default Light Theme # Load Default Light Theme
# ======================== # ========================
@@ -185,10 +185,14 @@ def testGuiTheme_Theme(qtbot, monkeypatch, nwGUI):
assert mainTheme.loadTheme() is True assert mainTheme.loadTheme() is True
# Check a few values # Check a few values
assert mainTheme._guiPalette.color(QPalette.Window).getRgb() == (239, 239, 239, 255) assert mainTheme._guiPalette.color(
assert mainTheme._guiPalette.color(QPalette.WindowText).getRgb() == (0, 0, 0, 255) QPalette.ColorRole.Window).getRgb() == (239, 239, 239, 255)
assert mainTheme._guiPalette.color(QPalette.Base).getRgb() == (255, 255, 255, 255) assert mainTheme._guiPalette.color(
assert mainTheme._guiPalette.color(QPalette.AlternateBase).getRgb() == (239, 239, 239, 255) QPalette.ColorRole.WindowText).getRgb() == (0, 0, 0, 255)
assert mainTheme._guiPalette.color(
QPalette.ColorRole.Base).getRgb() == (255, 255, 255, 255)
assert mainTheme._guiPalette.color(
QPalette.ColorRole.AlternateBase).getRgb() == (239, 239, 239, 255)
# Load Default Dark Theme # Load Default Dark Theme
# ======================= # =======================
@@ -197,10 +201,14 @@ def testGuiTheme_Theme(qtbot, monkeypatch, nwGUI):
assert mainTheme.loadTheme() is True assert mainTheme.loadTheme() is True
# Check a few values # Check a few values
assert mainTheme._guiPalette.color(QPalette.Window).getRgb() == (54, 54, 54, 255) assert mainTheme._guiPalette.color(
assert mainTheme._guiPalette.color(QPalette.WindowText).getRgb() == (204, 204, 204, 255) QPalette.ColorRole.Window).getRgb() == (54, 54, 54, 255)
assert mainTheme._guiPalette.color(QPalette.Base).getRgb() == (62, 62, 62, 255) assert mainTheme._guiPalette.color(
assert mainTheme._guiPalette.color(QPalette.AlternateBase).getRgb() == (78, 78, 78, 255) QPalette.ColorRole.WindowText).getRgb() == (204, 204, 204, 255)
assert mainTheme._guiPalette.color(
QPalette.ColorRole.Base).getRgb() == (62, 62, 62, 255)
assert mainTheme._guiPalette.color(
QPalette.ColorRole.AlternateBase).getRgb() == (78, 78, 78, 255)
# qtbot.stop() # qtbot.stop()
+7 -6
View File
@@ -27,15 +27,16 @@ from pytestqt.qtbot import QtBot
from tools import buildTestProject from tools import buildTestProject
from PyQt5.QtGui import QDesktopServices
from PyQt5.QtCore import QUrl from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QDialogButtonBox, QFileDialog, QListWidgetItem, QMessageBox from PyQt5.QtGui import QDesktopServices
from PyQt5.QtWidgets import QFileDialog, QListWidgetItem, QMessageBox
from novelwriter.constants import nwLabels
from novelwriter.core.buildsettings import BuildSettings
from novelwriter.enum import nwBuildFmt from novelwriter.enum import nwBuildFmt
from novelwriter.guimain import GuiMain from novelwriter.guimain import GuiMain
from novelwriter.constants import nwLabels
from novelwriter.tools.manusbuild import GuiManuscriptBuild from novelwriter.tools.manusbuild import GuiManuscriptBuild
from novelwriter.core.buildsettings import BuildSettings from novelwriter.types import QtDialogClose
@pytest.mark.gui @pytest.mark.gui
@@ -94,7 +95,7 @@ def testManuscriptBuild_Main(
assert (fncPath / "TestBuild").with_suffix(nwLabels.BUILD_EXT[fmt]).exists() assert (fncPath / "TestBuild").with_suffix(nwLabels.BUILD_EXT[fmt]).exists()
lastFmt = fmt lastFmt = fmt
manus._dialogButtonClicked(manus.dlgButtons.button(QDialogButtonBox.Close)) manus._dialogButtonClicked(manus.dlgButtons.button(QtDialogClose))
manus.deleteLater() manus.deleteLater()
assert build.lastBuildName == "TestBuild" assert build.lastBuildName == "TestBuild"
@@ -149,7 +150,7 @@ def testManuscriptBuild_Main(
assert lastUrl.startswith("file://") assert lastUrl.startswith("file://")
# Finish # Finish
manus._dialogButtonClicked(manus.dlgButtons.button(QDialogButtonBox.Close)) manus._dialogButtonClicked(manus.dlgButtons.button(QtDialogClose))
# qtbot.stop() # qtbot.stop()
# END Test testManuscriptBuild_Main # END Test testManuscriptBuild_Main
+4 -4
View File
@@ -31,7 +31,7 @@ from tools import C, buildTestProject
from PyQt5.QtCore import pyqtSlot from PyQt5.QtCore import pyqtSlot
from PyQt5.QtPrintSupport import QPrintPreviewDialog from PyQt5.QtPrintSupport import QPrintPreviewDialog
from PyQt5.QtWidgets import QAction, QDialogButtonBox, QListWidgetItem from PyQt5.QtWidgets import QAction, QListWidgetItem
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.constants import nwHeadFmt from novelwriter.constants import nwHeadFmt
@@ -40,7 +40,7 @@ from novelwriter.guimain import GuiMain
from novelwriter.tools.manusbuild import GuiManuscriptBuild from novelwriter.tools.manusbuild import GuiManuscriptBuild
from novelwriter.tools.manuscript import GuiManuscript from novelwriter.tools.manuscript import GuiManuscript
from novelwriter.tools.manussettings import GuiBuildSettings from novelwriter.tools.manussettings import GuiBuildSettings
from novelwriter.types import QtAlignAbsolute, QtAlignJustify from novelwriter.types import QtAlignAbsolute, QtAlignJustify, QtDialogApply, QtDialogSave
@pytest.mark.gui @pytest.mark.gui
@@ -118,7 +118,7 @@ def testManuscript_Builds(qtbot: QtBot, nwGUI: GuiMain, projPath: Path):
with qtbot.waitSignal(bSettings.newSettingsReady, timeout=5000): with qtbot.waitSignal(bSettings.newSettingsReady, timeout=5000):
bSettings.newSettingsReady.connect(_testNewSettingsReady) bSettings.newSettingsReady.connect(_testNewSettingsReady)
bSettings.buttonBox.button(QDialogButtonBox.Save).click() bSettings.buttonBox.button(QtDialogSave).click()
assert isinstance(build, BuildSettings) assert isinstance(build, BuildSettings)
assert build.name == "Test Build" assert build.name == "Test Build"
@@ -135,7 +135,7 @@ def testManuscript_Builds(qtbot: QtBot, nwGUI: GuiMain, projPath: Path):
with qtbot.waitSignal(bSettings.newSettingsReady, timeout=5000): with qtbot.waitSignal(bSettings.newSettingsReady, timeout=5000):
bSettings.newSettingsReady.connect(_testNewSettingsReady) bSettings.newSettingsReady.connect(_testNewSettingsReady)
bSettings.buttonBox.button(QDialogButtonBox.Apply).click() # Should leave the dialog open bSettings.buttonBox.button(QtDialogApply).click() # Should leave the dialog open
assert isinstance(build, BuildSettings) assert isinstance(build, BuildSettings)
assert build.name == "Test Build" assert build.name == "Test Build"
+10 -9
View File
@@ -29,7 +29,7 @@ from tools import C, buildTestProject
from PyQt5.QtGui import QFont from PyQt5.QtGui import QFont
from PyQt5.QtCore import pyqtSlot from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QDialogButtonBox, QFontDialog from PyQt5.QtWidgets import QFontDialog
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.guimain import GuiMain from novelwriter.guimain import GuiMain
@@ -38,6 +38,7 @@ from novelwriter.core.buildsettings import BuildSettings, FilterMode
from novelwriter.tools.manussettings import ( from novelwriter.tools.manussettings import (
GuiBuildSettings, _OutputTab, _FormatTab, _ContentTab, _HeadingsTab, _FilterTab GuiBuildSettings, _OutputTab, _FormatTab, _ContentTab, _HeadingsTab, _FilterTab
) )
from novelwriter.types import QtDialogApply, QtDialogClose, QtDialogSave
@pytest.mark.gui @pytest.mark.gui
@@ -80,7 +81,7 @@ def testBuildSettings_Init(qtbot: QtBot, nwGUI: GuiMain, projPath: Path, mockRnd
# Capture Apply button # Capture Apply button
with qtbot.waitSignal(bSettings.newSettingsReady, timeout=5000): with qtbot.waitSignal(bSettings.newSettingsReady, timeout=5000):
bSettings.newSettingsReady.connect(_testNewSettingsReady) bSettings.newSettingsReady.connect(_testNewSettingsReady)
bSettings._dialogButtonClicked(bSettings.buttonBox.button(QDialogButtonBox.Apply)) bSettings._dialogButtonClicked(bSettings.buttonBox.button(QtDialogApply))
assert triggered assert triggered
@@ -89,7 +90,7 @@ def testBuildSettings_Init(qtbot: QtBot, nwGUI: GuiMain, projPath: Path, mockRnd
with qtbot.waitSignal(bSettings.newSettingsReady, timeout=5000): with qtbot.waitSignal(bSettings.newSettingsReady, timeout=5000):
bSettings.newSettingsReady.connect(_testNewSettingsReady) bSettings.newSettingsReady.connect(_testNewSettingsReady)
bSettings._dialogButtonClicked(bSettings.buttonBox.button(QDialogButtonBox.Save)) bSettings._dialogButtonClicked(bSettings.buttonBox.button(QtDialogSave))
assert triggered assert triggered
@@ -106,7 +107,7 @@ def testBuildSettings_Init(qtbot: QtBot, nwGUI: GuiMain, projPath: Path, mockRnd
assert triggered assert triggered
# Finish # Finish
bSettings._dialogButtonClicked(bSettings.buttonBox.button(QDialogButtonBox.Close)) bSettings._dialogButtonClicked(bSettings.buttonBox.button(QtDialogClose))
# qtbot.stop() # qtbot.stop()
# END Test testBuildSettings_Init # END Test testBuildSettings_Init
@@ -312,7 +313,7 @@ def testBuildSettings_Filter(qtbot: QtBot, nwGUI: GuiMain, projPath: Path, mockR
] ]
# Finish # Finish
bSettings._dialogButtonClicked(bSettings.buttonBox.button(QDialogButtonBox.Close)) bSettings._dialogButtonClicked(bSettings.buttonBox.button(QtDialogClose))
# qtbot.stop() # qtbot.stop()
# END Test testBuildSettings_Filter # END Test testBuildSettings_Filter
@@ -484,7 +485,7 @@ def testBuildSettings_Headings(qtbot: QtBot, nwGUI: GuiMain):
assert build.getBool("headings.hideSection") is True assert build.getBool("headings.hideSection") is True
# Finish # Finish
bSettings._dialogButtonClicked(bSettings.buttonBox.button(QDialogButtonBox.Close)) bSettings._dialogButtonClicked(bSettings.buttonBox.button(QtDialogClose))
# qtbot.stop() # qtbot.stop()
# END Test testBuildSettings_Headings # END Test testBuildSettings_Headings
@@ -546,7 +547,7 @@ def testBuildSettings_Content(qtbot: QtBot, nwGUI: GuiMain):
assert build.getBool("text.addNoteHeadings") is True assert build.getBool("text.addNoteHeadings") is True
# Finish # Finish
bSettings._dialogButtonClicked(bSettings.buttonBox.button(QDialogButtonBox.Close)) bSettings._dialogButtonClicked(bSettings.buttonBox.button(QtDialogClose))
# qtbot.stop() # qtbot.stop()
# END Test testBuildSettings_Content # END Test testBuildSettings_Content
@@ -648,7 +649,7 @@ def testBuildSettings_Format(monkeypatch, qtbot: QtBot, nwGUI: GuiMain):
assert fmtTab.textSize.value() == 10 assert fmtTab.textSize.value() == 10
# Finish # Finish
bSettings._dialogButtonClicked(bSettings.buttonBox.button(QDialogButtonBox.Close)) bSettings._dialogButtonClicked(bSettings.buttonBox.button(QtDialogClose))
# qtbot.stop() # qtbot.stop()
# END Test testBuildSettings_Format # END Test testBuildSettings_Format
@@ -707,7 +708,7 @@ def testBuildSettings_Output(qtbot: QtBot, nwGUI: GuiMain):
assert outTab.odtPageHeader.text() == nwHeadFmt.ODT_AUTO assert outTab.odtPageHeader.text() == nwHeadFmt.ODT_AUTO
# Finish # Finish
bSettings._dialogButtonClicked(bSettings.buttonBox.button(QDialogButtonBox.Close)) bSettings._dialogButtonClicked(bSettings.buttonBox.button(QtDialogClose))
# qtbot.stop() # qtbot.stop()
# END Test testBuildSettings_Output # END Test testBuildSettings_Output