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.common import minmax, simplified
from novelwriter.types import QtPaintAnitAlias, QtTransparent
if TYPE_CHECKING: # pragma: no cover
from typing import TypeGuard # Requires Python 3.10
@@ -248,10 +249,10 @@ class NWStatus:
def _createIcon(self, red: int, green: int, blue: int) -> QIcon:
"""Generate an icon for a status label."""
pixmap = QPixmap(self._iPX, self._iPX)
pixmap.fill(QColor(0, 0, 0, 0))
pixmap.fill(QtTransparent)
painter = QPainter(pixmap)
painter.setRenderHint(QPainter.Antialiasing)
painter.setRenderHint(QtPaintAnitAlias)
painter.fillPath(self._iconPath, QColor(red, green, blue))
painter.end()
+2 -2
View File
@@ -35,7 +35,7 @@ from novelwriter import CONFIG, SHARED
from novelwriter.common import readTextFile
from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.versioninfo import VersionInfoWidget
from novelwriter.types import QtAlignRightTop
from novelwriter.types import QtAlignRightTop, QtDialogClose
logger = logging.getLogger(__name__)
@@ -84,7 +84,7 @@ class GuiAbout(QDialog):
self.txtCredits.setViewportMargins(0, hA, hA, 0)
# Buttons
self.btnBox = QDialogButtonBox(QDialogButtonBox.Close, self)
self.btnBox = QDialogButtonBox(QtDialogClose, self)
self.btnBox.rejected.connect(self.close)
# Assemble
+3 -3
View File
@@ -36,7 +36,7 @@ from PyQt5.QtWidgets import (
from novelwriter import CONFIG, SHARED
from novelwriter.extensions.switch import NSwitch
from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.types import QtUserRole
from novelwriter.types import QtDialogCancel, QtDialogOk, QtDialogReset, QtUserRole
logger = logging.getLogger(__name__)
@@ -85,11 +85,11 @@ class GuiDocMerge(QDialog):
self.optBox.setColumnStretch(2, 1)
# Buttons
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.buttonBox = QDialogButtonBox(QtDialogOk | QtDialogCancel)
self.buttonBox.accepted.connect(self.accept)
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)
# Assemble
+2 -2
View File
@@ -36,7 +36,7 @@ from PyQt5.QtWidgets import (
from novelwriter import CONFIG, SHARED
from novelwriter.extensions.switch import NSwitch
from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.types import QtUserRole
from novelwriter.types import QtDialogCancel, QtDialogOk, QtUserRole
logger = logging.getLogger(__name__)
@@ -115,7 +115,7 @@ class GuiDocSplit(QDialog):
self.optBox.setColumnStretch(3, 1)
# Buttons
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.buttonBox = QDialogButtonBox(QtDialogOk | QtDialogCancel)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
+3 -2
View File
@@ -31,6 +31,7 @@ from PyQt5.QtWidgets import (
)
from novelwriter import CONFIG
from novelwriter.types import QtDialogCancel, QtDialogOk
logger = logging.getLogger(__name__)
@@ -55,7 +56,7 @@ class GuiEditLabel(QDialog):
self.labelValue.selectAll()
# Buttons
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.buttonBox = QDialogButtonBox(QtDialogOk | QtDialogCancel)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
@@ -90,7 +91,7 @@ class GuiEditLabel(QDialog):
cls = GuiEditLabel(parent, text=text)
cls.exec()
label = cls.itemLabel
accepted = cls.result() == QDialog.Accepted
accepted = cls.result() == QDialog.DialogCode.Accepted
cls.deleteLater()
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.pagedsidebar import NPagedSideBar
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__)
@@ -84,11 +87,7 @@ class GuiPreferences(QDialog):
self.mainForm.setHelpTextStyle(SHARED.theme.helpText)
# Buttons
self.buttonBox = QDialogButtonBox(
QDialogButtonBox.StandardButton.Apply
| QDialogButtonBox.StandardButton.Save
| QDialogButtonBox.StandardButton.Close
)
self.buttonBox = QDialogButtonBox(QtDialogApply | QtDialogSave | QtDialogClose)
self.buttonBox.clicked.connect(self._dialogButtonClicked)
# Assemble
@@ -762,12 +761,12 @@ class GuiPreferences(QDialog):
def _dialogButtonClicked(self, button: QAbstractButton) -> None:
"""Handle button clicks from the dialog button box."""
role = self.buttonBox.buttonRole(button)
if role == QDialogButtonBox.ButtonRole.ApplyRole:
if role == QtRoleApply:
self._saveValues()
elif role == QDialogButtonBox.ButtonRole.AcceptRole:
elif role == QtRoleAccept:
self._saveValues()
self.close()
elif role == QDialogButtonBox.ButtonRole.RejectRole:
elif role == QtRoleReject:
self.close()
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.pagedsidebar import NPagedSideBar
from novelwriter.extensions.switch import NSwitch
from novelwriter.types import QtUserRole
from novelwriter.types import QtDialogCancel, QtDialogSave, QtUserRole
logger = logging.getLogger(__name__)
@@ -84,9 +84,7 @@ class GuiProjectSettings(QDialog):
self.sidebar.buttonClicked.connect(self._sidebarClicked)
# Buttons
self.buttonBox = QDialogButtonBox(
QDialogButtonBox.StandardButton.Save | QDialogButtonBox.StandardButton.Cancel
)
self.buttonBox = QDialogButtonBox(QtDialogSave | QtDialogCancel)
self.buttonBox.accepted.connect(self._doSave)
self.buttonBox.rejected.connect(self.close)
+2 -2
View File
@@ -34,7 +34,7 @@ from PyQt5.QtWidgets import (
from novelwriter import CONFIG
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__)
@@ -90,7 +90,7 @@ class GuiQuoteSelect(QDialog):
self.listBox.setMinimumHeight(CONFIG.pxInt(150))
# Buttons
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.buttonBox = QDialogButtonBox(QtDialogOk | QtDialogCancel)
self.buttonBox.accepted.connect(self.accept)
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.extensions.configlayout import NColourLabel
from novelwriter.extensions.modified import NIconToolButton
from novelwriter.types import QtDialogClose, QtDialogSave
if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain
@@ -110,7 +111,7 @@ class GuiWordList(QDialog):
self.editBox.addWidget(self.delButton, 0)
# Buttons
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Save | QDialogButtonBox.Close)
self.buttonBox = QDialogButtonBox(QtDialogSave | QtDialogClose)
self.buttonBox.accepted.connect(self._doSave)
self.buttonBox.rejected.connect(self.close)
+4 -2
View File
@@ -74,7 +74,9 @@ class NWErrorMessage(QDialog):
# Widgets
self.msgIcon = QLabel()
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.setOpenExternalLinks(True)
@@ -88,7 +90,7 @@ class NWErrorMessage(QDialog):
self.msgBody.setFont(font)
self.msgBody.setReadOnly(True)
self.btnBox = QDialogButtonBox(QDialogButtonBox.Close)
self.btnBox = QDialogButtonBox(QDialogButtonBox.StandardButton.Close)
self.btnBox.rejected.connect(self._doClose)
# 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.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):
@@ -87,7 +89,7 @@ class NProgressCircle(QProgressBar):
progress = 100.0*self.value()/self.maximum()
angle = ceil(16*3.6*progress)
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setRenderHint(QtPaintAnitAlias, True)
painter.setPen(self._dPen)
painter.setBrush(self._dBrush)
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)
if color:
colour = self.palette()
colour.setColor(QPalette.WindowText, color)
colour.setColor(QPalette.ColorRole.WindowText, color)
self.setPalette(colour)
self.setFont(font)
+6 -6
View File
@@ -32,7 +32,7 @@ from PyQt5.QtWidgets import (
QStyleOptionToolButton, QToolBar, QToolButton, QWidget
)
from novelwriter.types import QtAlignLeft, QtNoBrush, QtNoPen
from novelwriter.types import QtPaintAnitAlias, QtAlignLeft, QtMouseOver, QtNoBrush, QtNoPen
class NPagedSideBar(QToolBar):
@@ -125,7 +125,7 @@ class _NPagedToolButton(QToolButton):
fH = self.fontMetrics().height()
self._bH = round(fH * 1.7)
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._aH = 2*fH//7
self.setFixedHeight(self._bH)
@@ -145,7 +145,7 @@ class _NPagedToolButton(QToolButton):
opt.initFrom(self)
paint = QPainter(self)
paint.setRenderHint(QPainter.Antialiasing, True)
paint.setRenderHint(QtPaintAnitAlias, True)
paint.setPen(QtNoPen)
paint.setBrush(QtNoBrush)
@@ -153,7 +153,7 @@ class _NPagedToolButton(QToolButton):
height = self.height()
palette = self.palette()
if opt.state & QStyle.State_MouseOver == QStyle.State_MouseOver:
if opt.state & QtMouseOver == QtMouseOver:
backCol = palette.base()
paint.setBrush(backCol)
paint.setOpacity(0.75)
@@ -202,7 +202,7 @@ class _NPagedToolLabel(QLabel):
fH = self.fontMetrics().height()
self._bH = round(fH * 1.7)
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._textCol = textColor or self.palette().text().color()
@@ -214,7 +214,7 @@ class _NPagedToolLabel(QLabel):
label that matches the button style.
"""
paint = QPainter(self)
paint.setRenderHint(QPainter.Antialiasing, True)
paint.setRenderHint(QtPaintAnitAlias, True)
paint.setPen(QtNoPen)
width = self.width()
+3 -1
View File
@@ -28,6 +28,8 @@ from math import ceil
from PyQt5.QtGui import QPaintEvent, QPainter
from PyQt5.QtWidgets import QProgressBar, QWidget
from novelwriter.types import QtPaintAnitAlias
class NProgressSimple(QProgressBar):
"""Extension: Simple Progress Widget
@@ -44,7 +46,7 @@ class NProgressSimple(QProgressBar):
if (value := self.value()) > 0:
progress = ceil(self.width()*float(value)/self.maximum())
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setRenderHint(QtPaintAnitAlias, True)
painter.setPen(self.palette().highlight().color())
painter.setBrush(self.palette().highlight())
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.QtWidgets import QAbstractButton, QWidget
from novelwriter.types import QtPaintAnitAlias
logger = logging.getLogger(__name__)
@@ -67,7 +69,7 @@ class StatusLED(QAbstractButton):
def paintEvent(self, event: QPaintEvent) -> None:
"""Draw the LED."""
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setRenderHint(QtPaintAnitAlias, True)
painter.setPen(self.palette().dark().color())
painter.setBrush(self._theCol)
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 novelwriter import CONFIG, SHARED
from novelwriter.types import QtMouseLeft, QtNoPen
from novelwriter.types import QtPaintAnitAlias, QtMouseLeft, QtNoPen
class NSwitch(QAbstractButton):
@@ -90,7 +90,7 @@ class NSwitch(QAbstractButton):
def paintEvent(self, event: QPaintEvent) -> None:
"""Drawing the switch itself."""
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setRenderHint(QtPaintAnitAlias, True)
painter.setPen(QtNoPen)
palette = self.palette()
+2 -2
View File
@@ -125,7 +125,7 @@ class GuiSideBar(QWidget):
def updateTheme(self) -> None:
"""Initialise GUI elements that depend on specific settings."""
qPalette = self.palette()
qPalette.setBrush(QPalette.Window, qPalette.base())
qPalette.setBrush(QPalette.ColorRole.Window, qPalette.base())
self.setPalette(qPalette)
buttonStyle = SHARED.theme.getStyleSheet(STYLES_BIG_TOOLBUTTON)
@@ -157,7 +157,7 @@ class _PopRightMenu(QMenu):
def event(self, event: QEvent) -> bool:
"""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):
offset = QPoint(parent.width(), parent.height() - self.height())
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.error import formatException
from novelwriter.extensions.modified import NIconToolButton
from novelwriter.types import QtDialogClose
logger = logging.getLogger(__name__)
@@ -107,7 +108,7 @@ class GuiDictionaries(QDialog):
self.infoBox.setFrameStyle(QFrame.Shape.NoFrame)
# Buttons
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Close)
self.buttonBox = QDialogButtonBox(QtDialogClose)
self.buttonBox.rejected.connect(self._doClose)
# Assemble
+3 -3
View File
@@ -35,7 +35,7 @@ from PyQt5.QtWidgets import (
from novelwriter import CONFIG, SHARED
from novelwriter.common import readTextFile
from novelwriter.extensions.switch import NSwitch
from novelwriter.types import QtAlignLeft, QtAlignRight
from novelwriter.types import QtAlignLeft, QtAlignRight, QtRoleAction, QtDialogClose
logger = logging.getLogger(__name__)
@@ -96,10 +96,10 @@ class GuiLipsum(QDialog):
self.buttonBox = QDialogButtonBox()
self.buttonBox.rejected.connect(self.close)
self.btnClose = self.buttonBox.addButton(QDialogButtonBox.Close)
self.btnClose = self.buttonBox.addButton(QtDialogClose)
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.setAutoDefault(False)
+8 -6
View File
@@ -44,7 +44,9 @@ from novelwriter.core.item import NWItem
from novelwriter.enum import nwBuildFmt
from novelwriter.extensions.modified import NIconToolButton
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__)
@@ -184,9 +186,9 @@ class GuiManuscriptBuild(QDialog):
self.btnBuild = QPushButton(SHARED.theme.getIcon("export"), self.tr("&Build"))
self.btnBuild.setIconSize(bSz)
self.dlgButtons = QDialogButtonBox(QDialogButtonBox.StandardButton.Close)
self.dlgButtons.addButton(self.btnOpen, QDialogButtonBox.ButtonRole.ActionRole)
self.dlgButtons.addButton(self.btnBuild, QDialogButtonBox.ButtonRole.ActionRole)
self.dlgButtons = QDialogButtonBox(QtDialogClose)
self.dlgButtons.addButton(self.btnOpen, QtRoleAction)
self.dlgButtons.addButton(self.btnBuild, QtRoleAction)
# Assemble GUI
# ============
@@ -261,12 +263,12 @@ class GuiManuscriptBuild(QDialog):
def _dialogButtonClicked(self, button: QAbstractButton):
"""Handle button clicks from the dialog button box."""
role = self.dlgButtons.buttonRole(button)
if role == QDialogButtonBox.ActionRole:
if role == QtRoleAction:
if button == self.btnBuild:
self._runBuild()
elif button == self.btnOpen:
self._openOutputFolder()
elif role == QDialogButtonBox.RejectRole:
elif role == QtRoleReject:
self.close()
return
+5 -5
View File
@@ -104,7 +104,7 @@ class GuiManuscript(QDialog):
# ==============
qPalette = self.palette()
qPalette.setBrush(QPalette.Window, qPalette.base())
qPalette.setBrush(QPalette.ColorRole.Window, qPalette.base())
self.setPalette(qPalette)
buttonStyle = SHARED.theme.getStyleSheet(STYLES_MIN_TOOLBUTTON)
@@ -751,8 +751,8 @@ class _PreviewWidget(QTextBrowser):
# Document Setup
dPalette = self.palette()
dPalette.setColor(QPalette.Base, QColor(255, 255, 255))
dPalette.setColor(QPalette.Text, QColor(0, 0, 0))
dPalette.setColor(QPalette.ColorRole.Base, QColor(255, 255, 255))
dPalette.setColor(QPalette.ColorRole.Text, QColor(0, 0, 0))
self.setPalette(dPalette)
self.setMinimumWidth(40*SHARED.theme.textNWidth)
@@ -769,8 +769,8 @@ class _PreviewWidget(QTextBrowser):
# Document Age
aPalette = self.palette()
aPalette.setColor(QPalette.Background, aPalette.toolTipBase().color())
aPalette.setColor(QPalette.Foreground, aPalette.toolTipText().color())
aPalette.setColor(QPalette.ColorRole.Window, aPalette.toolTipBase().color())
aPalette.setColor(QPalette.ColorRole.WindowText, aPalette.toolTipText().color())
aFont = self.font()
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.switch import NSwitch
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
from novelwriter.guimain import GuiMain
@@ -131,11 +134,7 @@ class GuiBuildSettings(QDialog):
self.toolStack.addWidget(self.optTabOutput)
# Buttons
self.buttonBox = QDialogButtonBox(
QDialogButtonBox.StandardButton.Apply
| QDialogButtonBox.StandardButton.Save
| QDialogButtonBox.StandardButton.Close
)
self.buttonBox = QDialogButtonBox(QtDialogApply | QtDialogSave | QtDialogClose)
self.buttonBox.clicked.connect(self._dialogButtonClicked)
# Assemble
@@ -226,12 +225,12 @@ class GuiBuildSettings(QDialog):
def _dialogButtonClicked(self, button: QAbstractButton) -> None:
"""Handle button clicks from the dialog button box."""
role = self.buttonBox.buttonRole(button)
if role == QDialogButtonBox.ApplyRole:
if role == QtRoleApply:
self._emitBuildData()
elif role == QDialogButtonBox.AcceptRole:
elif role == QtRoleAccept:
self._emitBuildData()
self.close()
elif role == QDialogButtonBox.RejectRole:
elif role == QtRoleReject:
self.close()
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.pagedsidebar import NPagedSideBar
from novelwriter.extensions.switch import NSwitch
from novelwriter.types import QtAlignRight, QtDecoration
from novelwriter.types import QtAlignRight, QtDecoration, QtDialogClose
logger = logging.getLogger(__name__)
@@ -95,7 +95,7 @@ class GuiNovelDetails(QDialog):
self.mainStack.addWidget(self.contentsPage)
# Buttons
self.buttonBox = QDialogButtonBox(QDialogButtonBox.StandardButton.Close)
self.buttonBox = QDialogButtonBox(QtDialogClose)
self.buttonBox.rejected.connect(self.close)
# Assemble
+5 -5
View File
@@ -36,8 +36,8 @@ from PyQt5.QtGui import QCloseEvent, QColor, QFont, QPaintEvent, QPainter, QPen
from PyQt5.QtWidgets import (
QAction, QApplication, QDialog, QFileDialog, QFormLayout, QHBoxLayout,
QLabel, QLineEdit, QListView, QMenu, QPushButton, QScrollArea, QShortcut,
QStackedWidget, QStyle, QStyleOptionViewItem, QStyledItemDelegate,
QVBoxLayout, QWidget
QStackedWidget, QStyleOptionViewItem, QStyledItemDelegate, QVBoxLayout,
QWidget
)
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.switch import NSwitch
from novelwriter.extensions.versioninfo import VersionInfoWidget
from novelwriter.types import QtAlignLeft, QtAlignRightTop
from novelwriter.types import QtAlignLeft, QtAlignRightTop, QtSelected
logger = logging.getLogger(__name__)
@@ -431,7 +431,7 @@ class _ProjectListItem(QStyledItemDelegate):
ix, iy, x, y1, y2 = self._pPx
painter.save()
if opt.state & QStyle.StateFlag.State_Selected == QStyle.StateFlag.State_Selected:
if opt.state & QtSelected == QtSelected:
painter.setOpacity(0.25)
painter.fillRect(rect, QApplication.palette().highlight())
painter.setOpacity(1.0)
@@ -813,7 +813,7 @@ class _PopLeftDirectionMenu(QMenu):
def event(self, event: QEvent) -> bool:
"""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):
offset = QPoint(parent.width() - self.width(), parent.height())
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.error import formatException
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
from novelwriter.guimain import GuiMain
@@ -262,13 +265,13 @@ class GuiWritingStats(QDialog):
self.optsBox.addWidget(self.histMax, 0)
# Buttons
self.buttonBox = QDialogButtonBox()
self.buttonBox = QDialogButtonBox(self)
self.buttonBox.rejected.connect(self._doClose)
self.btnClose = self.buttonBox.addButton(QDialogButtonBox.Close)
self.btnClose = self.buttonBox.addButton(QtDialogClose)
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.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 PyQt5.QtCore import Qt
from PyQt5.QtGui import QColor
from PyQt5.QtGui import QColor, QPainter
from PyQt5.QtWidgets import QDialogButtonBox, QStyle
# Qt Alignment Flags
@@ -50,6 +51,9 @@ QtNoBrush = Qt.BrushStyle.NoBrush
QtNoPen = Qt.PenStyle.NoPen
QtRoundCap = Qt.PenCapStyle.RoundCap
QtSolidLine = Qt.PenStyle.SolidLine
QtPaintAnitAlias = QPainter.RenderHint.Antialiasing
QtMouseOver = QStyle.StateFlag.State_MouseOver
QtSelected = QStyle.StateFlag.State_Selected
# Qt Tree and Table Types
@@ -63,3 +67,17 @@ QtModeNone = Qt.KeyboardModifier.NoModifier
QtModShift = Qt.KeyboardModifier.ShiftModifier
QtMouseLeft = Qt.MouseButton.LeftButton
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