Clean up Qt enums (#2025)

This commit is contained in:
Veronica Berglyd Olsen
2024-09-18 22:18:15 +02:00
committed by GitHub
30 changed files with 335 additions and 318 deletions
+5 -5
View File
@@ -27,7 +27,6 @@ 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.QtGui import QColor, QFont, QPalette from PyQt5.QtGui import QColor, QFont, QPalette
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAbstractButton, QFrame, QHBoxLayout, QLabel, QLayout, QScrollArea, QAbstractButton, QFrame, QHBoxLayout, QLabel, QLayout, QScrollArea,
@@ -35,6 +34,7 @@ from PyQt5.QtWidgets import (
) )
from novelwriter import CONFIG from novelwriter import CONFIG
from novelwriter.types import QtScrollAsNeeded
DEFAULT_SCALE = 0.9 DEFAULT_SCALE = 0.9
@@ -76,8 +76,8 @@ class NScrollablePage(QScrollArea):
self._widget = QWidget(self) self._widget = QWidget(self)
self.setWidget(self._widget) self.setWidget(self._widget)
self.setWidgetResizable(True) self.setWidgetResizable(True)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setHorizontalScrollBarPolicy(QtScrollAsNeeded)
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setVerticalScrollBarPolicy(QtScrollAsNeeded)
self.setFrameShadow(QFrame.Shadow.Sunken) self.setFrameShadow(QFrame.Shadow.Sunken)
self.setFrameShape(QFrame.Shape.StyledPanel) self.setFrameShape(QFrame.Shape.StyledPanel)
return return
@@ -113,8 +113,8 @@ class NScrollableForm(QScrollArea):
self.setWidget(self._widget) self.setWidget(self._widget)
self.setWidgetResizable(True) self.setWidgetResizable(True)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setHorizontalScrollBarPolicy(QtScrollAsNeeded)
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setVerticalScrollBarPolicy(QtScrollAsNeeded)
self.setFrameShadow(QFrame.Shadow.Sunken) self.setFrameShadow(QFrame.Shadow.Sunken)
self.setFrameShape(QFrame.Shape.StyledPanel) self.setFrameShape(QFrame.Shape.StyledPanel)
+7 -7
View File
@@ -66,7 +66,7 @@ from novelwriter.tools.lipsum import GuiLipsum
from novelwriter.types import ( from novelwriter.types import (
QtAlignCenterTop, QtAlignJustify, QtAlignLeft, QtAlignLeftTop, QtAlignCenterTop, QtAlignJustify, QtAlignLeft, QtAlignLeftTop,
QtAlignRight, QtKeepAnchor, QtModCtrl, QtModNone, QtModShift, QtMouseLeft, QtAlignRight, QtKeepAnchor, QtModCtrl, QtModNone, QtModShift, QtMouseLeft,
QtMoveAnchor, QtMoveLeft, QtMoveRight QtMoveAnchor, QtMoveLeft, QtMoveRight, QtScrollAlwaysOff, QtScrollAsNeeded
) )
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -177,12 +177,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 | QtModCtrl) self.followTag1.setKey("Ctrl+Return")
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 | QtModCtrl) self.followTag2.setKey("Ctrl+Enter")
self.followTag2.setContext(Qt.ShortcutContext.WidgetShortcut) self.followTag2.setContext(Qt.ShortcutContext.WidgetShortcut)
self.followTag2.activated.connect(self._processTag) self.followTag2.activated.connect(self._processTag)
@@ -354,14 +354,14 @@ class GuiDocEditor(QPlainTextEdit):
# Scrolling # Scrolling
self.setCenterOnScroll(CONFIG.scrollPastEnd) self.setCenterOnScroll(CONFIG.scrollPastEnd)
if CONFIG.hideVScroll: if CONFIG.hideVScroll:
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(QtScrollAlwaysOff)
else: else:
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setVerticalScrollBarPolicy(QtScrollAsNeeded)
if CONFIG.hideHScroll: if CONFIG.hideHScroll:
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(QtScrollAlwaysOff)
else: else:
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setHorizontalScrollBarPolicy(QtScrollAsNeeded)
# Refresh the tab stops # Refresh the tab stops
self.setTabStopDistance(CONFIG.getTabWidth()) self.setTabStopDistance(CONFIG.getTabWidth())
+8 -5
View File
@@ -46,7 +46,10 @@ from novelwriter.extensions.configlayout import NColourLabel
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, QtKeepAnchor, QtMouseLeft, QtMoveAnchor from novelwriter.types import (
QtAlignCenterTop, QtKeepAnchor, QtMouseLeft, QtMoveAnchor,
QtScrollAlwaysOff, QtScrollAsNeeded
)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -177,14 +180,14 @@ class GuiDocViewer(QTextBrowser):
# Scroll bars # Scroll bars
if CONFIG.hideVScroll: if CONFIG.hideVScroll:
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(QtScrollAlwaysOff)
else: else:
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setVerticalScrollBarPolicy(QtScrollAsNeeded)
if CONFIG.hideHScroll: if CONFIG.hideHScroll:
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(QtScrollAlwaysOff)
else: else:
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setHorizontalScrollBarPolicy(QtScrollAsNeeded)
# Refresh the tab stops # Refresh the tab stops
self.setTabStopDistance(CONFIG.getTabWidth()) self.setTabStopDistance(CONFIG.getTabWidth())
+4 -4
View File
@@ -184,7 +184,7 @@ class GuiMainMenu(QMenuBar):
# Project > Exit # Project > Exit
self.aExitNW = self.projMenu.addAction(self.tr("Exit")) self.aExitNW = self.projMenu.addAction(self.tr("Exit"))
self.aExitNW.setShortcut("Ctrl+Q") self.aExitNW.setShortcut("Ctrl+Q")
self.aExitNW.setMenuRole(QAction.QuitRole) self.aExitNW.setMenuRole(QAction.MenuRole.QuitRole)
self.aExitNW.triggered.connect(lambda: self.mainGui.closeMain()) self.aExitNW.triggered.connect(lambda: self.mainGui.closeMain())
return return
@@ -941,7 +941,7 @@ class GuiMainMenu(QMenuBar):
# Tools > Preferences # Tools > Preferences
self.aPreferences = self.toolsMenu.addAction(self.tr("Preferences")) self.aPreferences = self.toolsMenu.addAction(self.tr("Preferences"))
self.aPreferences.setShortcut("Ctrl+,") self.aPreferences.setShortcut("Ctrl+,")
self.aPreferences.setMenuRole(QAction.PreferencesRole) self.aPreferences.setMenuRole(QAction.MenuRole.PreferencesRole)
self.aPreferences.triggered.connect(self.mainGui.showPreferencesDialog) self.aPreferences.triggered.connect(self.mainGui.showPreferencesDialog)
return return
@@ -953,12 +953,12 @@ class GuiMainMenu(QMenuBar):
# Help > About # Help > About
self.aAboutNW = self.helpMenu.addAction(self.tr("About novelWriter")) self.aAboutNW = self.helpMenu.addAction(self.tr("About novelWriter"))
self.aAboutNW.setMenuRole(QAction.AboutRole) self.aAboutNW.setMenuRole(QAction.MenuRole.AboutRole)
self.aAboutNW.triggered.connect(self.mainGui.showAboutNWDialog) self.aAboutNW.triggered.connect(self.mainGui.showAboutNWDialog)
# Help > About Qt5 # Help > About Qt5
self.aAboutQt = self.helpMenu.addAction(self.tr("About Qt5")) self.aAboutQt = self.helpMenu.addAction(self.tr("About Qt5"))
self.aAboutQt.setMenuRole(QAction.AboutQtRole) self.aAboutQt.setMenuRole(QAction.MenuRole.AboutQtRole)
self.aAboutQt.triggered.connect(self.mainGui.showAboutQtDialog) self.aAboutQt.triggered.connect(self.mainGui.showAboutQtDialog)
# Help > Separator # Help > Separator
+6 -6
View File
@@ -47,8 +47,8 @@ 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 ( from novelwriter.types import (
QtAlignRight, QtDecoration, QtMouseLeft, QtMouseMiddle, QtSizeExpanding, QtAlignRight, QtDecoration, QtMouseLeft, QtMouseMiddle, QtScrollAlwaysOff,
QtUserRole QtScrollAsNeeded, QtSizeExpanding, QtUserRole
) )
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -433,14 +433,14 @@ class GuiNovelTree(QTreeWidget):
"""Set or update tree widget settings.""" """Set or update tree widget settings."""
# Scroll bars # Scroll bars
if CONFIG.hideVScroll: if CONFIG.hideVScroll:
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(QtScrollAlwaysOff)
else: else:
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setVerticalScrollBarPolicy(QtScrollAsNeeded)
if CONFIG.hideHScroll: if CONFIG.hideHScroll:
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(QtScrollAlwaysOff)
else: else:
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setHorizontalScrollBarPolicy(QtScrollAsNeeded)
return return
+11 -11
View File
@@ -49,7 +49,7 @@ from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.novelselector import NovelSelector from novelwriter.extensions.novelselector import NovelSelector
from novelwriter.types import ( from novelwriter.types import (
QtAlignLeftTop, QtAlignRight, QtAlignRightTop, QtDecoration, QtAlignLeftTop, QtAlignRight, QtAlignRightTop, QtDecoration,
QtSizeExpanding, QtUserRole QtScrollAlwaysOff, QtScrollAsNeeded, QtSizeExpanding, QtUserRole
) )
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -433,13 +433,13 @@ class GuiOutlineTree(QTreeWidget):
def initSettings(self) -> None: def initSettings(self) -> None:
"""Set or update outline settings.""" """Set or update outline settings."""
if CONFIG.hideVScroll: if CONFIG.hideVScroll:
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(QtScrollAlwaysOff)
else: else:
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setVerticalScrollBarPolicy(QtScrollAsNeeded)
if CONFIG.hideHScroll: if CONFIG.hideHScroll:
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(QtScrollAlwaysOff)
else: else:
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setHorizontalScrollBarPolicy(QtScrollAsNeeded)
return return
def clearContent(self) -> None: def clearContent(self) -> None:
@@ -976,8 +976,8 @@ class GuiOutlineDetails(QScrollArea):
self.outerWidget.setLayout(self.outerBox) self.outerWidget.setLayout(self.outerBox)
self.setWidget(self.outerWidget) self.setWidget(self.outerWidget)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setHorizontalScrollBarPolicy(QtScrollAsNeeded)
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setVerticalScrollBarPolicy(QtScrollAsNeeded)
self.setWidgetResizable(True) self.setWidgetResizable(True)
self.setFrameStyle(QFrame.Shape.NoFrame) self.setFrameStyle(QFrame.Shape.NoFrame)
@@ -990,13 +990,13 @@ class GuiOutlineDetails(QScrollArea):
def initSettings(self) -> None: def initSettings(self) -> None:
"""Set or update outline settings.""" """Set or update outline settings."""
if CONFIG.hideVScroll: if CONFIG.hideVScroll:
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(QtScrollAlwaysOff)
else: else:
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setVerticalScrollBarPolicy(QtScrollAsNeeded)
if CONFIG.hideHScroll: if CONFIG.hideHScroll:
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(QtScrollAlwaysOff)
else: else:
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setHorizontalScrollBarPolicy(QtScrollAsNeeded)
self.updateClasses() self.updateClasses()
return return
+6 -6
View File
@@ -51,8 +51,8 @@ from novelwriter.enum import nwDocMode, nwItemClass, nwItemLayout, nwItemType
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 ( from novelwriter.types import (
QtAlignLeft, QtAlignRight, QtMouseLeft, QtMouseMiddle, QtSizeExpanding, QtAlignLeft, QtAlignRight, QtMouseLeft, QtMouseMiddle, QtScrollAlwaysOff,
QtUserRole QtScrollAsNeeded, QtSizeExpanding, QtUserRole
) )
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -578,13 +578,13 @@ class GuiProjectTree(QTreeWidget):
"""Set or update tree widget settings.""" """Set or update tree widget settings."""
# Scroll bars # Scroll bars
if CONFIG.hideVScroll: if CONFIG.hideVScroll:
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(QtScrollAlwaysOff)
else: else:
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setVerticalScrollBarPolicy(QtScrollAsNeeded)
if CONFIG.hideHScroll: if CONFIG.hideHScroll:
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(QtScrollAlwaysOff)
else: else:
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setHorizontalScrollBarPolicy(QtScrollAsNeeded)
return return
## ##
+3 -3
View File
@@ -293,15 +293,15 @@ class GuiMain(QMainWindow):
self._connectMenuActions() self._connectMenuActions()
self.keyReturn = QShortcut(self) self.keyReturn = QShortcut(self)
self.keyReturn.setKey(Qt.Key.Key_Return) self.keyReturn.setKey("Return")
self.keyReturn.activated.connect(self._keyPressReturn) self.keyReturn.activated.connect(self._keyPressReturn)
self.keyEnter = QShortcut(self) self.keyEnter = QShortcut(self)
self.keyEnter.setKey(Qt.Key.Key_Enter) self.keyEnter.setKey("Enter")
self.keyEnter.activated.connect(self._keyPressReturn) self.keyEnter.activated.connect(self._keyPressReturn)
self.keyEscape = QShortcut(self) self.keyEscape = QShortcut(self)
self.keyEscape.setKey(Qt.Key.Key_Escape) self.keyEscape.setKey("Esc")
self.keyEscape.activated.connect(self._keyPressEscape) self.keyEscape.activated.connect(self._keyPressEscape)
# Initialise Main GUI # Initialise Main GUI
+2 -2
View File
@@ -441,9 +441,9 @@ class _GuiAlert(QMessageBox):
Yes/No buttons or just an Ok button. Yes/No buttons or just an Ok button.
""" """
if isYesNo: if isYesNo:
self.setStandardButtons(QMessageBox.Yes | QMessageBox.No) self.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
else: else:
self.setStandardButtons(QMessageBox.Ok) self.setStandardButtons(QMessageBox.StandardButton.Ok)
pSz = 2*self._theme.baseIconHeight pSz = 2*self._theme.baseIconHeight
if level == self.INFO: if level == self.INFO:
self.setIconPixmap(self._theme.getPixmap("alert_info", (pSz, pSz))) self.setIconPixmap(self._theme.getPixmap("alert_info", (pSz, pSz)))
+4 -4
View File
@@ -49,7 +49,7 @@ from novelwriter.extensions.configlayout import NWrappedWidgetBox
from novelwriter.extensions.modified import NDialog, NIconToolButton, NSpinBox from novelwriter.extensions.modified import NDialog, 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, QtSelected from novelwriter.types import QtAlignLeft, QtAlignRightTop, QtScrollAsNeeded, QtSelected
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -297,7 +297,7 @@ class _OpenProjectPage(QWidget):
self.selectedPath.addAction(self.aMissing, QLineEdit.ActionPosition.TrailingPosition) self.selectedPath.addAction(self.aMissing, QLineEdit.ActionPosition.TrailingPosition)
self.keyDelete = QShortcut(self) self.keyDelete = QShortcut(self)
self.keyDelete.setKey(Qt.Key.Key_Delete) self.keyDelete.setKey("Del")
self.keyDelete.activated.connect(self._deleteSelectedItem) self.keyDelete.activated.connect(self._deleteSelectedItem)
# Assemble # Assemble
@@ -501,8 +501,8 @@ class _NewProjectPage(QWidget):
self.scrollArea = QScrollArea(self) self.scrollArea = QScrollArea(self)
self.scrollArea.setWidget(self.projectForm) self.scrollArea.setWidget(self.projectForm)
self.scrollArea.setWidgetResizable(True) self.scrollArea.setWidgetResizable(True)
self.scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.scrollArea.setHorizontalScrollBarPolicy(QtScrollAsNeeded)
self.scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.scrollArea.setVerticalScrollBarPolicy(QtScrollAsNeeded)
self.enterForm = self.projectForm.enterForm self.enterForm = self.projectForm.enterForm
+6 -1
View File
@@ -110,6 +110,11 @@ QtSizeIgnored = QSizePolicy.Policy.Ignored
QtSizeMinimum = QSizePolicy.Policy.Minimum QtSizeMinimum = QSizePolicy.Policy.Minimum
QtSizeMinimumExpanding = QSizePolicy.Policy.MinimumExpanding QtSizeMinimumExpanding = QSizePolicy.Policy.MinimumExpanding
# Scroll Bar Policy
QtScrollAlwaysOff = Qt.ScrollBarPolicy.ScrollBarAlwaysOff
QtScrollAsNeeded = Qt.ScrollBarPolicy.ScrollBarAsNeeded
# Other # Other
QRegExUnicode = QRegularExpression.PatternOption.UseUnicodePropertiesOption QRegExUnicode = QRegularExpression.PatternOption.UseUnicodePropertiesOption
@@ -128,7 +133,7 @@ FONT_WEIGHTS: dict[int, int] = {
QFont.Weight.Black: 900, QFont.Weight.Black: 900,
} }
FONT_STYLE: dict[int, str] = { FONT_STYLE: dict[QFont.Style, str] = {
QFont.Style.StyleNormal: "normal", QFont.Style.StyleNormal: "normal",
QFont.Style.StyleItalic: "italic", QFont.Style.StyleItalic: "italic",
QFont.Style.StyleOblique: "oblique", QFont.Style.StyleOblique: "oblique",
+2 -2
View File
@@ -144,7 +144,7 @@ def projPath(fncPath):
def mockGUI(qtbot, monkeypatch): def mockGUI(qtbot, monkeypatch):
"""Create a mock instance of novelWriter's main GUI class.""" """Create a mock instance of novelWriter's main GUI class."""
monkeypatch.setattr(QMessageBox, "exec", lambda *a: None) monkeypatch.setattr(QMessageBox, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.Yes)
gui = MockGuiMain() gui = MockGuiMain()
theme = MockTheme() theme = MockTheme()
monkeypatch.setattr(SHARED, "_gui", gui) monkeypatch.setattr(SHARED, "_gui", gui)
@@ -156,7 +156,7 @@ def mockGUI(qtbot, monkeypatch):
def nwGUI(qtbot, monkeypatch, functionFixture): def nwGUI(qtbot, monkeypatch, functionFixture):
"""Create an instance of the novelWriter GUI.""" """Create an instance of the novelWriter GUI."""
monkeypatch.setattr(QMessageBox, "exec", lambda *a: None) monkeypatch.setattr(QMessageBox, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.Yes)
nwGUI = main(["--testmode", f"--config={_TMP_CONF}", f"--data={_TMP_CONF}"]) nwGUI = main(["--testmode", f"--config={_TMP_CONF}", f"--data={_TMP_CONF}"])
qtbot.addWidget(nwGUI) qtbot.addWidget(nwGUI)
+1 -1
View File
@@ -126,7 +126,7 @@ def testBaseSharedData_Projects(monkeypatch, caplog, fncPath):
def testBaseSharedData_Alerts(qtbot, monkeypatch, caplog): def testBaseSharedData_Alerts(qtbot, monkeypatch, caplog):
"""Test SharedData class alert helper functions.""" """Test SharedData class alert helper functions."""
monkeypatch.setattr(QMessageBox, "exec", lambda *a: None) monkeypatch.setattr(QMessageBox, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.Yes)
shared = SharedData() shared = SharedData()
+2 -2
View File
@@ -271,14 +271,14 @@ def testCoreProject_Open(monkeypatch, caplog, mockGUI, fncPath, mockRnd):
# Won't convert legacy file # Won't convert legacy file
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(ProjectXMLReader, "state", property(lambda *a: XMLReadState.WAS_LEGACY)) mp.setattr(ProjectXMLReader, "state", property(lambda *a: XMLReadState.WAS_LEGACY))
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No) mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
assert project.openProject(fncPath, clearLock=True) is False assert project.openProject(fncPath, clearLock=True) is False
assert "The file format of your project is about to be" in SHARED.lastAlert assert "The file format of your project is about to be" in SHARED.lastAlert
# Won't open project from newer version # Won't open project from newer version
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(ProjectXMLReader, "hexVersion", property(lambda *a: 0x99999999)) mp.setattr(ProjectXMLReader, "hexVersion", property(lambda *a: 0x99999999))
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No) mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
assert project.openProject(fncPath, clearLock=True) is False assert project.openProject(fncPath, clearLock=True) is False
assert "This project was saved by a newer version" in SHARED.lastAlert assert "This project was saved by a newer version" in SHARED.lastAlert
+1 -1
View File
@@ -58,4 +58,4 @@ def testDlgAbout_QtDialog(monkeypatch, nwGUI):
# Open About # Open About
# All it can do is check against a crash # All it can do is check against a crash
nwGUI.showAboutQtDialog() nwGUI.showAboutQtDialog()
nwGUI.mainMenu.aAboutQt.activate(QAction.Trigger) nwGUI.mainMenu.aAboutQt.activate(QAction.ActionEvent.Trigger)
@@ -46,7 +46,7 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI):
monkeypatch.setattr(GuiProjectSettings, "result", lambda *a: QtAccepted) monkeypatch.setattr(GuiProjectSettings, "result", lambda *a: QtAccepted)
# 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.ActionEvent.Trigger)
assert SHARED.findTopLevelWidget(GuiProjectSettings) is None assert SHARED.findTopLevelWidget(GuiProjectSettings) is None
# Pretend we have a project # Pretend we have a project
@@ -54,7 +54,7 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI):
SHARED.project.data.setSpellLang("en") SHARED.project.data.setSpellLang("en")
# Get the dialog object # Get the dialog object
nwGUI.mainMenu.aProjectSettings.activate(QAction.Trigger) nwGUI.mainMenu.aProjectSettings.activate(QAction.ActionEvent.Trigger)
qtbot.waitUntil( qtbot.waitUntil(
lambda: SHARED.findTopLevelWidget(GuiProjectSettings) is not None, timeout=1000 lambda: SHARED.findTopLevelWidget(GuiProjectSettings) is not None, timeout=1000
) )
+1 -1
View File
@@ -47,7 +47,7 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, fncPath, projPath):
nwGUI.openProject(projPath) nwGUI.openProject(projPath)
# Load the dialog # Load the dialog
nwGUI.mainMenu.aEditWordList.activate(QAction.Trigger) nwGUI.mainMenu.aEditWordList.activate(QAction.ActionEvent.Trigger)
qtbot.waitUntil(lambda: SHARED.findTopLevelWidget(GuiWordList) is not None, timeout=1000) qtbot.waitUntil(lambda: SHARED.findTopLevelWidget(GuiWordList) is not None, timeout=1000)
wList = SHARED.findTopLevelWidget(GuiWordList) wList = SHARED.findTopLevelWidget(GuiWordList)
+6 -2
View File
@@ -27,7 +27,7 @@ from PyQt5.QtGui import QKeyEvent, QWheelEvent
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 from novelwriter.types import QtModNone, QtModShift
class MockWidget(QWidget): class MockWidget(QWidget):
@@ -57,7 +57,11 @@ def testExtEventFilters_WheelEventFilter():
# Sending a mouse wheel event forwards it # Sending a mouse wheel event forwards it
pos = QPoint(0, 0) pos = QPoint(0, 0)
event = QWheelEvent(pos, pos, pos, pos, Qt.NoButton, Qt.NoModifier, Qt.NoScrollPhase, False) event = QWheelEvent(
pos, pos, pos, pos,
Qt.MouseButton.NoButton, QtModNone,
Qt.ScrollPhase.NoScrollPhase, False,
)
eFilter.eventFilter(obj, event) eFilter.eventFilter(obj, event)
assert widget.count == 1 assert widget.count == 1
+60 -60
View File
@@ -34,7 +34,7 @@ from novelwriter.gui.doceditor import GuiDocEditor
from novelwriter.text.counting import standardCounter from novelwriter.text.counting import standardCounter
from novelwriter.types import ( from novelwriter.types import (
QtAlignJustify, QtAlignLeft, QtKeepAnchor, QtModCtrl, QtMouseLeft, QtAlignJustify, QtAlignLeft, QtKeepAnchor, QtModCtrl, QtMouseLeft,
QtMoveRight QtMoveAnchor, QtMoveRight, QtScrollAlwaysOff, QtScrollAsNeeded
) )
from tests.mocked import causeOSError from tests.mocked import causeOSError
@@ -73,8 +73,8 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd):
# Check Defaults # Check Defaults
qDoc = docEditor.document() qDoc = docEditor.document()
assert qDoc.defaultTextOption().alignment() == QtAlignLeft assert qDoc.defaultTextOption().alignment() == QtAlignLeft
assert docEditor.verticalScrollBarPolicy() == Qt.ScrollBarAsNeeded assert docEditor.verticalScrollBarPolicy() == QtScrollAsNeeded
assert docEditor.horizontalScrollBarPolicy() == Qt.ScrollBarAsNeeded assert docEditor.horizontalScrollBarPolicy() == QtScrollAsNeeded
assert docEditor._typPadChar == nwUnicode.U_NBSP assert docEditor._typPadChar == nwUnicode.U_NBSP
assert docEditor.docHeader.itemTitle.text() == ( assert docEditor.docHeader.itemTitle.text() == (
"Novel \u203a New Chapter \u203a New Scene" "Novel \u203a New Chapter \u203a New Scene"
@@ -98,8 +98,8 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd):
assert qDoc.defaultTextOption().alignment() == QtAlignJustify assert qDoc.defaultTextOption().alignment() == QtAlignJustify
assert qDoc.defaultTextOption().flags() & QTextOption.ShowTabsAndSpaces assert qDoc.defaultTextOption().flags() & QTextOption.ShowTabsAndSpaces
assert qDoc.defaultTextOption().flags() & QTextOption.ShowLineAndParagraphSeparators assert qDoc.defaultTextOption().flags() & QTextOption.ShowLineAndParagraphSeparators
assert docEditor.verticalScrollBarPolicy() == Qt.ScrollBarAlwaysOff assert docEditor.verticalScrollBarPolicy() == QtScrollAlwaysOff
assert docEditor.horizontalScrollBarPolicy() == Qt.ScrollBarAlwaysOff assert docEditor.horizontalScrollBarPolicy() == QtScrollAlwaysOff
assert docEditor._typPadChar == nwUnicode.U_THNBSP assert docEditor._typPadChar == nwUnicode.U_THNBSP
assert docEditor.docHeader.itemTitle.text() == "New Scene" assert docEditor.docHeader.itemTitle.text() == "New Scene"
@@ -989,8 +989,8 @@ def testGuiEditor_TextManipulation(qtbot, nwGUI, projPath, ipsumText, mockRnd):
# Past Paragraph # Past Paragraph
docEditor.replaceText(text) docEditor.replaceText(text)
cursor = docEditor.textCursor() cursor = docEditor.textCursor()
cursor.setPosition(13, QTextCursor.MoveAnchor) cursor.setPosition(13, QtMoveAnchor)
cursor.setPosition(1000, QTextCursor.KeepAnchor) cursor.setPosition(1000, QtKeepAnchor)
docEditor.setTextCursor(cursor) docEditor.setTextCursor(cursor)
docEditor._wrapSelection("=") docEditor._wrapSelection("=")
@@ -1021,8 +1021,8 @@ def testGuiEditor_TextManipulation(qtbot, nwGUI, projPath, ipsumText, mockRnd):
# Past Paragraph # Past Paragraph
docEditor.replaceText(text) docEditor.replaceText(text)
cursor = docEditor.textCursor() cursor = docEditor.textCursor()
cursor.setPosition(13, QTextCursor.MoveAnchor) cursor.setPosition(13, QtMoveAnchor)
cursor.setPosition(1000, QTextCursor.KeepAnchor) cursor.setPosition(1000, QtKeepAnchor)
docEditor.setTextCursor(cursor) docEditor.setTextCursor(cursor)
docEditor._toggleFormat(1, "=") docEditor._toggleFormat(1, "=")
@@ -1130,8 +1130,8 @@ def testGuiEditor_TextManipulation(qtbot, nwGUI, projPath, ipsumText, mockRnd):
text = "### A Scene\n\n%s\n\n%s" % (parOne, parTwo) text = "### A Scene\n\n%s\n\n%s" % (parOne, parTwo)
docEditor.replaceText(text) docEditor.replaceText(text)
cursor = docEditor.textCursor() cursor = docEditor.textCursor()
cursor.setPosition(16, QTextCursor.MoveAnchor) cursor.setPosition(16, QtMoveAnchor)
cursor.setPosition(680, QTextCursor.KeepAnchor) cursor.setPosition(680, QtKeepAnchor)
docEditor.setTextCursor(cursor) docEditor.setTextCursor(cursor)
docEditor._removeInParLineBreaks() docEditor._removeInParLineBreaks()
@@ -1153,16 +1153,16 @@ def testGuiEditor_TextManipulation(qtbot, nwGUI, projPath, ipsumText, mockRnd):
assert docEditor.getText() == text assert docEditor.getText() == text
# Select All # Select All
qtbot.keyClick(docEditor, Qt.Key_A, modifier=Qt.ControlModifier, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_A, modifier=QtModCtrl, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Delete, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Delete, delay=KEY_DELAY)
assert docEditor.getText() == "" assert docEditor.getText() == ""
# Undo # Undo
qtbot.keyClick(docEditor, Qt.Key_Z, modifier=Qt.ControlModifier, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Z, modifier=QtModCtrl, delay=KEY_DELAY)
assert docEditor.getText() == text assert docEditor.getText() == text
# Redo # Redo
qtbot.keyClick(docEditor, Qt.Key_Y, modifier=Qt.ControlModifier, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Y, modifier=QtModCtrl, delay=KEY_DELAY)
assert docEditor.getText() == "" assert docEditor.getText() == ""
# qtbot.stop() # qtbot.stop()
@@ -1679,8 +1679,8 @@ def testGuiEditor_Completer(qtbot, nwGUI, projPath, mockRnd):
nwGUI.docEditor.setFocus() nwGUI.docEditor.setFocus()
for c in "### Scene One": for c in "### Scene One":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
# Type Keyword @ # Type Keyword @
qtbot.keyClick(docEditor, "@", delay=KEY_DELAY) qtbot.keyClick(docEditor, "@", delay=KEY_DELAY)
@@ -1695,7 +1695,7 @@ def testGuiEditor_Completer(qtbot, nwGUI, projPath, mockRnd):
assert len(completer.actions()) == 0 assert len(completer.actions()) == 0
# Delete character and go select @char # Delete character and go select @char
qtbot.keyClick(docEditor, Qt.Key_Backspace, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Backspace, delay=KEY_DELAY)
assert len(completer.actions()) == 2 assert len(completer.actions()) == 2
completer.actions()[0].trigger() completer.actions()[0].trigger()
assert docEditor.getText() == ( assert docEditor.getText() == (
@@ -1712,13 +1712,13 @@ def testGuiEditor_Completer(qtbot, nwGUI, projPath, mockRnd):
assert [a.text() for a in completer.actions()] == [] assert [a.text() for a in completer.actions()] == []
# Deleting it and typing "a", should leave "Jane" # Deleting it and typing "a", should leave "Jane"
qtbot.keyClick(docEditor, Qt.Key_Backspace, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Backspace, delay=KEY_DELAY)
qtbot.keyClick(docEditor, "a", delay=KEY_DELAY) qtbot.keyClick(docEditor, "a", delay=KEY_DELAY)
assert [a.text() for a in completer.actions()] == ["Jane"] assert [a.text() for a in completer.actions()] == ["Jane"]
# Selecting "Jane" should insert it # Selecting "Jane" should insert it
completer.actions()[0].trigger() completer.actions()[0].trigger()
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
assert docEditor.getText() == ( assert docEditor.getText() == (
"### Scene One\n\n" "### Scene One\n\n"
"@char: Jane\n" "@char: Jane\n"
@@ -1727,21 +1727,21 @@ def testGuiEditor_Completer(qtbot, nwGUI, projPath, mockRnd):
# Start a new line with a nonsense keyword, which should be handled # Start a new line with a nonsense keyword, which should be handled
for c in "@: ": for c in "@: ":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Backspace, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Backspace, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Backspace, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Backspace, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Backspace, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Backspace, delay=KEY_DELAY)
# Send keypresses to the completer object # Send keypresses to the completer object
qtbot.keyClick(docEditor, "@", delay=KEY_DELAY) qtbot.keyClick(docEditor, "@", delay=KEY_DELAY)
assert len(completer.actions()) == len(nwKeyWords.VALID_KEYS) assert len(completer.actions()) == len(nwKeyWords.VALID_KEYS)
qtbot.keyClick(completer, "f", delay=KEY_DELAY) qtbot.keyClick(completer, "f", delay=KEY_DELAY)
qtbot.keyClick(completer, Qt.Key_Down, delay=KEY_DELAY) qtbot.keyClick(completer, Qt.Key.Key_Down, delay=KEY_DELAY)
qtbot.keyClick(completer, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(completer, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(completer, " ", delay=KEY_DELAY) qtbot.keyClick(completer, " ", delay=KEY_DELAY)
qtbot.keyClick(completer, "h", delay=KEY_DELAY) qtbot.keyClick(completer, "h", delay=KEY_DELAY)
qtbot.keyClick(completer, Qt.Key_Down, delay=KEY_DELAY) qtbot.keyClick(completer, Qt.Key.Key_Down, delay=KEY_DELAY)
qtbot.keyClick(completer, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(completer, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(completer, Qt.Key_Escape, delay=KEY_DELAY) qtbot.keyClick(completer, Qt.Key.Key_Escape, delay=KEY_DELAY)
assert docEditor.getText() == ( assert docEditor.getText() == (
"### Scene One\n\n" "### Scene One\n\n"
"@char: Jane\n" "@char: Jane\n"
@@ -1881,13 +1881,13 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
assert cursor.selectedText() == "est" assert cursor.selectedText() == "est"
# Activate search # Activate search
nwGUI.mainMenu.aFind.activate(QAction.Trigger) nwGUI.mainMenu.aFind.activate(QAction.ActionEvent.Trigger)
assert docSearch.isVisible() assert docSearch.isVisible()
assert docSearch.searchText == "est" assert docSearch.searchText == "est"
# Find next by enter key # Find next by enter key
monkeypatch.setattr(docSearch.searchBox, "hasFocus", lambda: True) monkeypatch.setattr(docSearch.searchBox, "hasFocus", lambda: True)
qtbot.keyClick(docSearch.searchBox, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docSearch.searchBox, Qt.Key.Key_Return, delay=KEY_DELAY)
assert abs(docEditor.getCursorPosition() - 1299) < 3 assert abs(docEditor.getCursorPosition() - 1299) < 3
# Find next by button # Find next by button
@@ -1895,16 +1895,16 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
assert abs(docEditor.getCursorPosition() - 1513) < 3 assert abs(docEditor.getCursorPosition() - 1513) < 3
# Activate loop search # Activate loop search
docSearch.toggleLoop.activate(QAction.Trigger) docSearch.toggleLoop.activate(QAction.ActionEvent.Trigger)
assert docSearch.toggleLoop.isChecked() assert docSearch.toggleLoop.isChecked()
assert CONFIG.searchLoop is True assert CONFIG.searchLoop is True
# Find next by menu Search > Find Next # Find next by menu Search > Find Next
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.ActionEvent.Trigger)
assert abs(docEditor.getCursorPosition() - 647) < 3 assert abs(docEditor.getCursorPosition() - 647) < 3
# Close search # Close search
docSearch.cancelSearch.activate(QAction.Trigger) docSearch.cancelSearch.activate(QAction.ActionEvent.Trigger)
assert docSearch.isVisible() is False assert docSearch.isVisible() is False
docEditor.setCursorPosition(15) docEditor.setCursorPosition(15)
@@ -1920,7 +1920,7 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
assert docEditor.getCursorPosition() < 3 # No result assert docEditor.getCursorPosition() < 3 # No result
# Enable RegEx search # Enable RegEx search
docSearch.toggleRegEx.activate(QAction.Trigger) docSearch.toggleRegEx.activate(QAction.ActionEvent.Trigger)
assert docSearch.toggleRegEx.isChecked() assert docSearch.toggleRegEx.isChecked()
assert CONFIG.searchRegEx is True assert CONFIG.searchRegEx is True
@@ -1943,50 +1943,50 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
assert abs(docEditor.getCursorPosition() - 223) < 3 assert abs(docEditor.getCursorPosition() - 223) < 3
# Find next and then prev # Find next and then prev
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.ActionEvent.Trigger)
assert abs(docEditor.getCursorPosition() - 324) < 3 assert abs(docEditor.getCursorPosition() - 324) < 3
nwGUI.mainMenu.aFindPrev.activate(QAction.Trigger) nwGUI.mainMenu.aFindPrev.activate(QAction.ActionEvent.Trigger)
assert abs(docEditor.getCursorPosition() - 223) < 3 assert abs(docEditor.getCursorPosition() - 223) < 3
# Make RegEx case sensitive # Make RegEx case sensitive
docSearch.toggleCase.activate(QAction.Trigger) docSearch.toggleCase.activate(QAction.ActionEvent.Trigger)
assert docSearch.toggleCase.isChecked() assert docSearch.toggleCase.isChecked()
assert CONFIG.searchCase is True assert CONFIG.searchCase is True
# Find next/prev (one result) # Find next/prev (one result)
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.ActionEvent.Trigger)
assert abs(docEditor.getCursorPosition() - 626) < 3 assert abs(docEditor.getCursorPosition() - 626) < 3
nwGUI.mainMenu.aFindPrev.activate(QAction.Trigger) nwGUI.mainMenu.aFindPrev.activate(QAction.ActionEvent.Trigger)
assert abs(docEditor.getCursorPosition() - 626) < 3 assert abs(docEditor.getCursorPosition() - 626) < 3
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.ActionEvent.Trigger)
assert abs(docEditor.getCursorPosition() - 626) < 3 assert abs(docEditor.getCursorPosition() - 626) < 3
# Trigger replace # Trigger replace
nwGUI.mainMenu.aReplace.activate(QAction.Trigger) nwGUI.mainMenu.aReplace.activate(QAction.ActionEvent.Trigger)
docSearch.setReplaceText("foo") docSearch.setReplaceText("foo")
# Disable RegEx case sensitive # Disable RegEx case sensitive
docSearch.toggleCase.activate(QAction.Trigger) docSearch.toggleCase.activate(QAction.ActionEvent.Trigger)
assert docSearch.toggleCase.isChecked() is False assert docSearch.toggleCase.isChecked() is False
assert CONFIG.searchCase is False assert CONFIG.searchCase is False
# Toggle replace preserve case # Toggle replace preserve case
docSearch.toggleMatchCap.activate(QAction.Trigger) docSearch.toggleMatchCap.activate(QAction.ActionEvent.Trigger)
assert docSearch.toggleMatchCap.isChecked() assert docSearch.toggleMatchCap.isChecked()
assert CONFIG.searchMatchCap is True assert CONFIG.searchMatchCap is True
# Replace "Sus" with "Foo" via menu # Replace "Sus" with "Foo" via menu
docEditor.setCursorPosition(605) docEditor.setCursorPosition(605)
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.ActionEvent.Trigger)
nwGUI.mainMenu.aReplaceNext.activate(QAction.Trigger) nwGUI.mainMenu.aReplaceNext.activate(QAction.ActionEvent.Trigger)
assert docEditor.getText()[623:634] == "Foopendisse" assert docEditor.getText()[623:634] == "Foopendisse"
# Find next/prev to loop file # Find next/prev to loop file
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.ActionEvent.Trigger)
assert abs(docEditor.getCursorPosition() - 223) < 3 assert abs(docEditor.getCursorPosition() - 223) < 3
nwGUI.mainMenu.aFindPrev.activate(QAction.Trigger) nwGUI.mainMenu.aFindPrev.activate(QAction.ActionEvent.Trigger)
assert abs(docEditor.getCursorPosition() - 1805) < 3 assert abs(docEditor.getCursorPosition() - 1805) < 3
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.ActionEvent.Trigger)
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
@@ -1999,53 +1999,53 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
assert docEditor.getText() == origText assert docEditor.getText() == origText
# Disable RegEx search # Disable RegEx search
docSearch.toggleRegEx.activate(QAction.Trigger) docSearch.toggleRegEx.activate(QAction.ActionEvent.Trigger)
assert not docSearch.toggleRegEx.isChecked() assert not docSearch.toggleRegEx.isChecked()
assert CONFIG.searchRegEx is False assert CONFIG.searchRegEx is False
# Close search and select "est" again # Close search and select "est" again
docSearch.cancelSearch.activate(QAction.Trigger) docSearch.cancelSearch.activate(QAction.ActionEvent.Trigger)
docEditor.setCursorPosition(645) docEditor.setCursorPosition(645)
docEditor._makeSelection(QTextCursor.WordUnderCursor) docEditor._makeSelection(QTextCursor.WordUnderCursor)
cursor = docEditor.textCursor() cursor = docEditor.textCursor()
assert cursor.selectedText() == "est" assert cursor.selectedText() == "est"
# Activate search again # Activate search again
nwGUI.mainMenu.aFind.activate(QAction.Trigger) nwGUI.mainMenu.aFind.activate(QAction.ActionEvent.Trigger)
assert docSearch.isVisible() assert docSearch.isVisible()
assert docSearch.searchText == "est" assert docSearch.searchText == "est"
# Enable full word search # Enable full word search
docSearch.toggleWord.activate(QAction.Trigger) docSearch.toggleWord.activate(QAction.ActionEvent.Trigger)
assert docSearch.toggleWord.isChecked() assert docSearch.toggleWord.isChecked()
assert CONFIG.searchWord is True assert CONFIG.searchWord is True
# Only one match # Only one match
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.ActionEvent.Trigger)
assert abs(docEditor.getCursorPosition() - 647) < 3 assert abs(docEditor.getCursorPosition() - 647) < 3
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.ActionEvent.Trigger)
assert abs(docEditor.getCursorPosition() - 647) < 3 assert abs(docEditor.getCursorPosition() - 647) < 3
# Enable next doc search # Enable next doc search
docSearch.toggleProject.activate(QAction.Trigger) docSearch.toggleProject.activate(QAction.ActionEvent.Trigger)
assert docSearch.toggleProject.isChecked() assert docSearch.toggleProject.isChecked()
assert CONFIG.searchNextFile is True assert CONFIG.searchNextFile is True
# Next match # Next match
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.ActionEvent.Trigger)
assert docEditor.docHandle == "2426c6f0ca922" # Next document assert docEditor.docHandle == "2426c6f0ca922" # Next document
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.ActionEvent.Trigger)
assert abs(docEditor.getCursorPosition() - 620) < 3 assert abs(docEditor.getCursorPosition() - 620) < 3
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.ActionEvent.Trigger)
assert abs(docEditor.getCursorPosition() - 1127) < 3 assert abs(docEditor.getCursorPosition() - 1127) < 3
# Next doc, no match # Next doc, no match
assert CONFIG.searchNextFile is True assert CONFIG.searchNextFile is True
docSearch.setSearchText("abcdef") docSearch.setSearchText("abcdef")
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.ActionEvent.Trigger)
assert docEditor.docHandle != "2426c6f0ca922" assert docEditor.docHandle != "2426c6f0ca922"
assert docEditor.docHandle == "04468803b92e1" assert docEditor.docHandle == "04468803b92e1"
nwGUI.mainMenu.aFindNext.activate(QAction.Trigger) nwGUI.mainMenu.aFindNext.activate(QAction.ActionEvent.Trigger)
assert docEditor.docHandle != "04468803b92e1" assert docEditor.docHandle != "04468803b92e1"
assert docEditor.docHandle == "7a992350f3eb6" assert docEditor.docHandle == "7a992350f3eb6"
+1 -1
View File
@@ -133,7 +133,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
# Open again via menu # Open again via menu
assert nwGUI.projView.projTree.setSelectedHandle("88243afbe5ed8") assert nwGUI.projView.projTree.setSelectedHandle("88243afbe5ed8")
nwGUI.mainMenu.aViewDoc.activate(QAction.Trigger) nwGUI.mainMenu.aViewDoc.activate(QAction.ActionEvent.Trigger)
# Open context menu # Open context menu
menuOpened = False menuOpened = False
+76 -75
View File
@@ -38,6 +38,7 @@ from novelwriter.gui.noveltree import GuiNovelView
from novelwriter.gui.outline import GuiOutlineView from novelwriter.gui.outline import GuiOutlineView
from novelwriter.gui.projtree import GuiProjectTree from novelwriter.gui.projtree import GuiProjectTree
from novelwriter.tools.welcome import GuiWelcome from novelwriter.tools.welcome import GuiWelcome
from novelwriter.types import QtModCtrl, QtModShift
from tests.mocked import causeOSError from tests.mocked import causeOSError
from tests.tools import NWD_IGNORE, XML_IGNORE, C, buildTestProject, cmpFiles from tests.tools import NWD_IGNORE, XML_IGNORE, C, buildTestProject, cmpFiles
@@ -266,18 +267,18 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
# Type something into the document # Type something into the document
nwGUI.docEditor.setFocus() nwGUI.docEditor.setFocus()
qtbot.keyClick(docEditor, "a", modifier=Qt.ControlModifier, delay=KEY_DELAY) qtbot.keyClick(docEditor, "a", modifier=QtModCtrl, delay=KEY_DELAY)
for c in "# Jane Doe": for c in "# Jane Doe":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "@tag: Jane": for c in "@tag: Jane":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "This is a file about Jane.": for c in "This is a file about Jane.":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
# Add a Plot File # Add a Plot File
nwGUI._switchFocus(nwFocus.TREE) nwGUI._switchFocus(nwFocus.TREE)
@@ -288,18 +289,18 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
# Type something into the document # Type something into the document
nwGUI.docEditor.setFocus() nwGUI.docEditor.setFocus()
qtbot.keyClick(docEditor, "a", modifier=Qt.ControlModifier, delay=KEY_DELAY) qtbot.keyClick(docEditor, "a", modifier=QtModCtrl, delay=KEY_DELAY)
for c in "# Main Plot": for c in "# Main Plot":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "@tag: MainPlot": for c in "@tag: MainPlot":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "This is a file [i]detailing[/i] the main plot.": for c in "This is a file [i]detailing[/i] the main plot.":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
# Add a World File # Add a World File
nwGUI._switchFocus(nwFocus.TREE) nwGUI._switchFocus(nwFocus.TREE)
@@ -315,18 +316,18 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
# Type something into the document # Type something into the document
nwGUI.docEditor.setFocus() nwGUI.docEditor.setFocus()
qtbot.keyClick(docEditor, "a", modifier=Qt.ControlModifier, delay=KEY_DELAY) qtbot.keyClick(docEditor, "a", modifier=QtModCtrl, delay=KEY_DELAY)
for c in "# Main Location": for c in "# Main Location":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "@tag: Home": for c in "@tag: Home":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "This is a file describing Jane's home.": for c in "This is a file describing Jane's home.":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
# Trigger autosaves before making more changes # Trigger autosaves before making more changes
nwGUI._autoSaveDocument() nwGUI._autoSaveDocument()
@@ -342,67 +343,67 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
# Type something into the document # Type something into the document
nwGUI.docEditor.setFocus() nwGUI.docEditor.setFocus()
qtbot.keyClick(docEditor, "a", modifier=Qt.ControlModifier, delay=KEY_DELAY) qtbot.keyClick(docEditor, "a", modifier=QtModCtrl, delay=KEY_DELAY)
for c in "# Novel": for c in "# Novel":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "## Chapter": for c in "## Chapter":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "@pov: Jane": for c in "@pov: Jane":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "@plot: MainPlot": for c in "@plot: MainPlot":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "### Scene": for c in "### Scene":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "% How about a comment?": for c in "% How about a comment?":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "@pov: Jane": for c in "@pov: Jane":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "@plot: MainPlot": for c in "@plot: MainPlot":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "@location: Home": for c in "@location: Home":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "#### Some Section": for c in "#### Some Section":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "@char: Jane": for c in "@char: Jane":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "This is a paragraph of nonsense text.": for c in "This is a paragraph of nonsense text.":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
# Don't allow Shift+Enter to insert a line separator (issue #1150) # Don't allow Shift+Enter to insert a line separator (issue #1150)
for c in "This is another paragraph": for c in "This is another paragraph":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Enter, modifier=Qt.ShiftModifier, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Enter, modifier=QtModShift, delay=KEY_DELAY)
for c in "with a line separator in it.": for c in "with a line separator in it.":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
# Auto-Replace # Auto-Replace
# ============ # ============
@@ -422,23 +423,23 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
for c in "How about three hyphens - -": for c in "How about three hyphens - -":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Left, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Left, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Backspace, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Backspace, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Right, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Right, delay=KEY_DELAY)
for c in "- for long dash? It works too.": for c in "- for long dash? It works too.":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "\"Full line double quoted text.\"": for c in "\"Full line double quoted text.\"":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "'Full line single quoted text.'": for c in "'Full line single quoted text.'":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
# Insert spaces before and after quotes # Insert spaces before and after quotes
docEditor._typPadBefore = "\u201d" docEditor._typPadBefore = "\u201d"
@@ -446,8 +447,8 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
for c in "Some \"double quoted text with spaces padded\".": for c in "Some \"double quoted text with spaces padded\".":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
docEditor._typPadBefore = "" docEditor._typPadBefore = ""
docEditor._typPadAfter = "" docEditor._typPadAfter = ""
@@ -457,23 +458,23 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
for c in "@object: NoSpaceAdded": for c in "@object: NoSpaceAdded":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "% synopsis: No space before this colon.": for c in "% synopsis: No space before this colon.":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "Add space before this colon: See?": for c in "Add space before this colon: See?":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "But don't add a double space : See?": for c in "But don't add a double space : See?":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
docEditor._typPadBefore = "" docEditor._typPadBefore = ""
@@ -482,33 +483,33 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
for c in "\t\"Tab-indented text\"": for c in "\t\"Tab-indented text\"":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in ">\"Paragraph-indented text\"": for c in ">\"Paragraph-indented text\"":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in ">>\"Right-aligned text\"": for c in ">>\"Right-aligned text\"":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in "\t'Tab-indented text'": for c in "\t'Tab-indented text'":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in ">'Paragraph-indented text'": for c in ">'Paragraph-indented text'":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
for c in ">>'Right-aligned text'": for c in ">>'Right-aligned text'":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
docEditor.wCounterDoc.run() docEditor.wCounterDoc.run()
@@ -517,8 +518,8 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
for c in "Some text with tesst in it.": for c in "Some text with tesst in it.":
qtbot.keyClick(docEditor, c, delay=KEY_DELAY) qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
qtbot.keyClick(docEditor, Qt.Key_Return, delay=KEY_DELAY) qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
currPos = docEditor.getCursorPosition() currPos = docEditor.getCursorPosition()
assert docEditor._qDocument.spellErrorAtPos(currPos) == ("", -1, -1, []) assert docEditor._qDocument.spellErrorAtPos(currPos) == ("", -1, -1, [])
+1 -1
View File
@@ -50,7 +50,7 @@ def testGuiI18n_Localisation(qtbot, monkeypatch, language, nwGUI, projPath):
"""Test loading the gui with a specific language.""" """Test loading the gui with a specific language."""
monkeypatch.setattr(QDialog, "exec", lambda *a: None) monkeypatch.setattr(QDialog, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "exec", lambda *a: None) monkeypatch.setattr(QMessageBox, "exec", lambda *a: None)
monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.Yes)
# Set the test language # Set the test language
CONFIG.guiLocale = language CONFIG.guiLocale = language
+89 -88
View File
@@ -29,6 +29,7 @@ from novelwriter import CONFIG, SHARED
from novelwriter.constants import nwKeyWords, nwUnicode from novelwriter.constants import nwKeyWords, nwUnicode
from novelwriter.enum import nwDocAction, nwDocInsert from novelwriter.enum import nwDocAction, nwDocInsert
from novelwriter.gui.doceditor import GuiDocEditor from novelwriter.gui.doceditor import GuiDocEditor
from novelwriter.types import QtKeepAnchor, QtMoveRight
from tests.tools import C, buildTestProject, writeFile from tests.tools import C, buildTestProject, writeFile
@@ -49,45 +50,45 @@ def testGuiMainMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
cleanText = nwGUI.docEditor.getText()[54:101] cleanText = nwGUI.docEditor.getText()[54:101]
# Bold # Bold
nwGUI.mainMenu.aFmtBold.activate(QAction.Trigger) nwGUI.mainMenu.aFmtBold.activate(QAction.ActionEvent.Trigger)
fmtStr = "**Pellentesque** nec erat ut nulla posuere commodo." fmtStr = "**Pellentesque** nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:105] == fmtStr assert nwGUI.docEditor.getText()[54:105] == fmtStr
nwGUI.mainMenu.aFmtBold.activate(QAction.Trigger) nwGUI.mainMenu.aFmtBold.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[54:101] == cleanText assert nwGUI.docEditor.getText()[54:101] == cleanText
# Italic # Italic
nwGUI.mainMenu.aFmtItalic.activate(QAction.Trigger) nwGUI.mainMenu.aFmtItalic.activate(QAction.ActionEvent.Trigger)
fmtStr = "_Pellentesque_ nec erat ut nulla posuere commodo." fmtStr = "_Pellentesque_ nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:103] == fmtStr assert nwGUI.docEditor.getText()[54:103] == fmtStr
nwGUI.mainMenu.aFmtItalic.activate(QAction.Trigger) nwGUI.mainMenu.aFmtItalic.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[54:101] == cleanText assert nwGUI.docEditor.getText()[54:101] == cleanText
# Strikethrough # Strikethrough
nwGUI.mainMenu.aFmtStrike.activate(QAction.Trigger) nwGUI.mainMenu.aFmtStrike.activate(QAction.ActionEvent.Trigger)
fmtStr = "~~Pellentesque~~ nec erat ut nulla posuere commodo." fmtStr = "~~Pellentesque~~ nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:105] == fmtStr assert nwGUI.docEditor.getText()[54:105] == fmtStr
nwGUI.mainMenu.aFmtStrike.activate(QAction.Trigger) nwGUI.mainMenu.aFmtStrike.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[54:101] == cleanText assert nwGUI.docEditor.getText()[54:101] == cleanText
# Should get us back to plain # Should get us back to plain
nwGUI.mainMenu.aFmtBold.activate(QAction.Trigger) nwGUI.mainMenu.aFmtBold.activate(QAction.ActionEvent.Trigger)
nwGUI.mainMenu.aFmtItalic.activate(QAction.Trigger) nwGUI.mainMenu.aFmtItalic.activate(QAction.ActionEvent.Trigger)
nwGUI.mainMenu.aFmtItalic.activate(QAction.Trigger) nwGUI.mainMenu.aFmtItalic.activate(QAction.ActionEvent.Trigger)
nwGUI.mainMenu.aFmtBold.activate(QAction.Trigger) nwGUI.mainMenu.aFmtBold.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[54:101] == cleanText assert nwGUI.docEditor.getText()[54:101] == cleanText
# Double Quotes # Double Quotes
nwGUI.mainMenu.aFmtDQuote.activate(QAction.Trigger) nwGUI.mainMenu.aFmtDQuote.activate(QAction.ActionEvent.Trigger)
fmtStr = "“Pellentesque” nec erat ut nulla posuere commodo." fmtStr = "“Pellentesque” nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:103] == fmtStr assert nwGUI.docEditor.getText()[54:103] == fmtStr
nwGUI.mainMenu.aEditUndo.activate(QAction.Trigger) nwGUI.mainMenu.aEditUndo.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[54:101] == cleanText assert nwGUI.docEditor.getText()[54:101] == cleanText
# Single Quotes # Single Quotes
nwGUI.mainMenu.aFmtSQuote.activate(QAction.Trigger) nwGUI.mainMenu.aFmtSQuote.activate(QAction.ActionEvent.Trigger)
fmtStr = "Pellentesque nec erat ut nulla posuere commodo." fmtStr = "Pellentesque nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:103] == fmtStr assert nwGUI.docEditor.getText()[54:103] == fmtStr
nwGUI.mainMenu.aEditUndo.activate(QAction.Trigger) nwGUI.mainMenu.aEditUndo.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[54:101] == cleanText assert nwGUI.docEditor.getText()[54:101] == cleanText
# Block Formats # Block Formats
@@ -96,51 +97,51 @@ def testGuiMainMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
nwGUI.docEditor.setCursorPosition(57) nwGUI.docEditor.setCursorPosition(57)
# Header 1 # Header 1
nwGUI.mainMenu.aFmtHead1.activate(QAction.Trigger) nwGUI.mainMenu.aFmtHead1.activate(QAction.ActionEvent.Trigger)
fmtStr = "# Pellentesque nec erat ut nulla posuere commodo." fmtStr = "# Pellentesque nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:103] == fmtStr assert nwGUI.docEditor.getText()[54:103] == fmtStr
# Header 2 # Header 2
nwGUI.mainMenu.aFmtHead2.activate(QAction.Trigger) nwGUI.mainMenu.aFmtHead2.activate(QAction.ActionEvent.Trigger)
fmtStr = "## Pellentesque nec erat ut nulla posuere commodo." fmtStr = "## Pellentesque nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:104] == fmtStr assert nwGUI.docEditor.getText()[54:104] == fmtStr
# Header 3 # Header 3
nwGUI.mainMenu.aFmtHead3.activate(QAction.Trigger) nwGUI.mainMenu.aFmtHead3.activate(QAction.ActionEvent.Trigger)
fmtStr = "### Pellentesque nec erat ut nulla posuere commodo." fmtStr = "### Pellentesque nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:105] == fmtStr assert nwGUI.docEditor.getText()[54:105] == fmtStr
# Header 4 # Header 4
nwGUI.mainMenu.aFmtHead4.activate(QAction.Trigger) nwGUI.mainMenu.aFmtHead4.activate(QAction.ActionEvent.Trigger)
fmtStr = "#### Pellentesque nec erat ut nulla posuere commodo." fmtStr = "#### Pellentesque nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:106] == fmtStr assert nwGUI.docEditor.getText()[54:106] == fmtStr
# Title Format # Title Format
nwGUI.mainMenu.aFmtTitle.activate(QAction.Trigger) nwGUI.mainMenu.aFmtTitle.activate(QAction.ActionEvent.Trigger)
fmtStr = "#! Pellentesque nec erat ut nulla posuere commodo." fmtStr = "#! Pellentesque nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:104] == fmtStr assert nwGUI.docEditor.getText()[54:104] == fmtStr
# Unnumbered Chapter # Unnumbered Chapter
nwGUI.mainMenu.aFmtUnNum.activate(QAction.Trigger) nwGUI.mainMenu.aFmtUnNum.activate(QAction.ActionEvent.Trigger)
fmtStr = "##! Pellentesque nec erat ut nulla posuere commodo." fmtStr = "##! Pellentesque nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:105] == fmtStr assert nwGUI.docEditor.getText()[54:105] == fmtStr
# Hard Scene # Hard Scene
nwGUI.mainMenu.aFmtHardSc.activate(QAction.Trigger) nwGUI.mainMenu.aFmtHardSc.activate(QAction.ActionEvent.Trigger)
fmtStr = "###! Pellentesque nec erat ut nulla posuere commodo." fmtStr = "###! Pellentesque nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:106] == fmtStr assert nwGUI.docEditor.getText()[54:106] == fmtStr
# Clear Format # Clear Format
nwGUI.mainMenu.aFmtNoFormat.activate(QAction.Trigger) nwGUI.mainMenu.aFmtNoFormat.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[54:101] == cleanText assert nwGUI.docEditor.getText()[54:101] == cleanText
# Comment On # Comment On
nwGUI.mainMenu.aFmtComment.activate(QAction.Trigger) nwGUI.mainMenu.aFmtComment.activate(QAction.ActionEvent.Trigger)
fmtStr = "% Pellentesque nec erat ut nulla posuere commodo." fmtStr = "% Pellentesque nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:103] == fmtStr assert nwGUI.docEditor.getText()[54:103] == fmtStr
# Comment Off # Comment Off
nwGUI.mainMenu.aFmtComment.activate(QAction.Trigger) nwGUI.mainMenu.aFmtComment.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[54:101] == cleanText assert nwGUI.docEditor.getText()[54:101] == cleanText
# Check comment with no space before text # Check comment with no space before text
@@ -149,26 +150,26 @@ def testGuiMainMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
fmtStr = "%Pellentesque nec erat ut nulla posuere commodo." fmtStr = "%Pellentesque nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:102] == fmtStr assert nwGUI.docEditor.getText()[54:102] == fmtStr
nwGUI.mainMenu.aFmtNoFormat.activate(QAction.Trigger) nwGUI.mainMenu.aFmtNoFormat.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[54:101] == cleanText assert nwGUI.docEditor.getText()[54:101] == cleanText
# Undo/Redo # Undo/Redo
nwGUI.mainMenu.aEditUndo.activate(QAction.Trigger) nwGUI.mainMenu.aEditUndo.activate(QAction.ActionEvent.Trigger)
fmtStr = "%Pellentesque nec erat ut nulla posuere commodo." fmtStr = "%Pellentesque nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[54:102] == fmtStr assert nwGUI.docEditor.getText()[54:102] == fmtStr
nwGUI.mainMenu.aEditRedo.activate(QAction.Trigger) nwGUI.mainMenu.aEditRedo.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[54:101] == cleanText assert nwGUI.docEditor.getText()[54:101] == cleanText
# Cut, Copy and Paste # Cut, Copy and Paste
nwGUI.docEditor.setCursorPosition(54) nwGUI.docEditor.setCursorPosition(54)
nwGUI.docEditor._makeSelection(QTextCursor.WordUnderCursor) nwGUI.docEditor._makeSelection(QTextCursor.WordUnderCursor)
nwGUI.mainMenu.aEditCut.activate(QAction.Trigger) nwGUI.mainMenu.aEditCut.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[54:104] == ( assert nwGUI.docEditor.getText()[54:104] == (
" nec erat ut nulla posuere commodo. Curabitur nisi" " nec erat ut nulla posuere commodo. Curabitur nisi"
) )
nwGUI.mainMenu.aEditPaste.activate(QAction.Trigger) nwGUI.mainMenu.aEditPaste.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[54:104] == ( assert nwGUI.docEditor.getText()[54:104] == (
"Pellentesque nec erat ut nulla posuere commodo. Cu" "Pellentesque nec erat ut nulla posuere commodo. Cu"
) )
@@ -176,21 +177,21 @@ def testGuiMainMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
nwGUI.docEditor.setCursorPosition(54) nwGUI.docEditor.setCursorPosition(54)
nwGUI.docEditor._makeSelection(QTextCursor.WordUnderCursor) nwGUI.docEditor._makeSelection(QTextCursor.WordUnderCursor)
nwGUI.mainMenu.aEditCopy.activate(QAction.Trigger) nwGUI.mainMenu.aEditCopy.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[54:104] == ( assert nwGUI.docEditor.getText()[54:104] == (
"Pellentesque nec erat ut nulla posuere commodo. Cu" "Pellentesque nec erat ut nulla posuere commodo. Cu"
) )
nwGUI.docEditor.setCursorPosition(54) nwGUI.docEditor.setCursorPosition(54)
nwGUI.mainMenu.aEditPaste.activate(QAction.Trigger) nwGUI.mainMenu.aEditPaste.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[54:104] == ( assert nwGUI.docEditor.getText()[54:104] == (
"PellentesquePellentesque nec erat ut nulla posuere" "PellentesquePellentesque nec erat ut nulla posuere"
) )
nwGUI.mainMenu.aEditUndo.activate(QAction.Trigger) nwGUI.mainMenu.aEditUndo.activate(QAction.ActionEvent.Trigger)
# Select Paragraph/All # Select Paragraph/All
nwGUI.docEditor.setCursorPosition(57) nwGUI.docEditor.setCursorPosition(57)
nwGUI.mainMenu.aSelectPar.activate(QAction.Trigger) nwGUI.mainMenu.aSelectPar.activate(QAction.ActionEvent.Trigger)
cursor = nwGUI.docEditor.textCursor() cursor = nwGUI.docEditor.textCursor()
assert cursor.selectedText() == ( assert cursor.selectedText() == (
"Pellentesque nec erat ut nulla posuere commodo. Curabitur nisi augue, imperdiet et porta " "Pellentesque nec erat ut nulla posuere commodo. Curabitur nisi augue, imperdiet et porta "
@@ -203,7 +204,7 @@ def testGuiMainMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
) )
nwGUI.docEditor.setCursorPosition(57) nwGUI.docEditor.setCursorPosition(57)
nwGUI.mainMenu.aSelectAll.activate(QAction.Trigger) nwGUI.mainMenu.aSelectAll.activate(QAction.ActionEvent.Trigger)
cursor = nwGUI.docEditor.textCursor() cursor = nwGUI.docEditor.textCursor()
assert len(cursor.selectedText()) == 1910 assert len(cursor.selectedText()) == 1910
@@ -219,32 +220,32 @@ def testGuiMainMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
nwGUI.docEditor.setCursorPosition(0) nwGUI.docEditor.setCursorPosition(0)
# Left Align # Left Align
nwGUI.mainMenu.aFmtAlignLeft.activate(QAction.Trigger) nwGUI.mainMenu.aFmtAlignLeft.activate(QAction.ActionEvent.Trigger)
fmtStr = "A single, short paragraph. <<" fmtStr = "A single, short paragraph. <<"
assert nwGUI.docEditor.getText()[:29] == fmtStr assert nwGUI.docEditor.getText()[:29] == fmtStr
# Right Align # Right Align
nwGUI.mainMenu.aFmtAlignRight.activate(QAction.Trigger) nwGUI.mainMenu.aFmtAlignRight.activate(QAction.ActionEvent.Trigger)
fmtStr = ">> A single, short paragraph." fmtStr = ">> A single, short paragraph."
assert nwGUI.docEditor.getText()[:29] == fmtStr assert nwGUI.docEditor.getText()[:29] == fmtStr
# Centre Align # Centre Align
nwGUI.mainMenu.aFmtAlignCentre.activate(QAction.Trigger) nwGUI.mainMenu.aFmtAlignCentre.activate(QAction.ActionEvent.Trigger)
fmtStr = ">> A single, short paragraph. <<" fmtStr = ">> A single, short paragraph. <<"
assert nwGUI.docEditor.getText()[:32] == fmtStr assert nwGUI.docEditor.getText()[:32] == fmtStr
# Left Indent # Left Indent
nwGUI.mainMenu.aFmtIndentLeft.activate(QAction.Trigger) nwGUI.mainMenu.aFmtIndentLeft.activate(QAction.ActionEvent.Trigger)
fmtStr = "> A single, short paragraph." fmtStr = "> A single, short paragraph."
assert nwGUI.docEditor.getText()[:28] == fmtStr assert nwGUI.docEditor.getText()[:28] == fmtStr
# Right Indent # Right Indent
nwGUI.mainMenu.aFmtIndentRight.activate(QAction.Trigger) nwGUI.mainMenu.aFmtIndentRight.activate(QAction.ActionEvent.Trigger)
fmtStr = "> A single, short paragraph. <" fmtStr = "> A single, short paragraph. <"
assert nwGUI.docEditor.getText()[:30] == fmtStr assert nwGUI.docEditor.getText()[:30] == fmtStr
# No Format # No Format
nwGUI.mainMenu.aFmtNoFormat.activate(QAction.Trigger) nwGUI.mainMenu.aFmtNoFormat.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText()[:30] == cleanText assert nwGUI.docEditor.getText()[:30] == cleanText
# Other Checks # Other Checks
@@ -256,16 +257,16 @@ def testGuiMainMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
"Also text with \"double\" quotes which are \"less tricky\".\n\n" "Also text with \"double\" quotes which are \"less tricky\".\n\n"
)) ))
nwGUI.mainMenu.aSelectAll.activate(QAction.Trigger) nwGUI.mainMenu.aSelectAll.activate(QAction.ActionEvent.Trigger)
nwGUI.mainMenu.aFmtReplSng.activate(QAction.Trigger) nwGUI.mainMenu.aFmtReplSng.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == ( assert nwGUI.docEditor.getText() == (
"### New Text\n\n" "### New Text\n\n"
"Text with single quotes and tricky stuffs.\n\n" "Text with single quotes and tricky stuffs.\n\n"
"Also text with \"double\" quotes which are \"less tricky\".\n\n" "Also text with \"double\" quotes which are \"less tricky\".\n\n"
) )
nwGUI.mainMenu.aSelectAll.activate(QAction.Trigger) nwGUI.mainMenu.aSelectAll.activate(QAction.ActionEvent.Trigger)
nwGUI.mainMenu.aFmtReplDbl.activate(QAction.Trigger) nwGUI.mainMenu.aFmtReplDbl.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == ( assert nwGUI.docEditor.getText() == (
"### New Text\n\n" "### New Text\n\n"
"Text with single quotes and tricky stuffs.\n\n" "Text with single quotes and tricky stuffs.\n\n"
@@ -281,7 +282,7 @@ def testGuiMainMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
"Here is some text\non multiple\nlines.\n\n" "Here is some text\non multiple\nlines.\n\n"
"With another paragraph\nhere." "With another paragraph\nhere."
)) ))
nwGUI.mainMenu.aFmtRmBreaks.activate(QAction.Trigger) nwGUI.mainMenu.aFmtRmBreaks.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == ( assert nwGUI.docEditor.getText() == (
"### New Text\n\n" "### New Text\n\n"
"@char: Someone\n" "@char: Someone\n"
@@ -301,9 +302,9 @@ def testGuiMainMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
)) ))
cursor = nwGUI.docEditor.textCursor() cursor = nwGUI.docEditor.textCursor()
cursor.setPosition(74) cursor.setPosition(74)
cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor, 29) cursor.movePosition(QtMoveRight, QtKeepAnchor, 29)
nwGUI.docEditor.setTextCursor(cursor) nwGUI.docEditor.setTextCursor(cursor)
nwGUI.mainMenu.aFmtRmBreaks.activate(QAction.Trigger) nwGUI.mainMenu.aFmtRmBreaks.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == ( assert nwGUI.docEditor.getText() == (
"### New Text\n\n" "### New Text\n\n"
"@char: Someone\n" "@char: Someone\n"
@@ -367,95 +368,95 @@ def testGuiMainMenu_Insert(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockRnd
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
# Check Menu Entries # Check Menu Entries
nwGUI.mainMenu.aInsENDash.activate(QAction.Trigger) nwGUI.mainMenu.aInsENDash.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_ENDASH assert nwGUI.docEditor.getText() == nwUnicode.U_ENDASH
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsEMDash.activate(QAction.Trigger) nwGUI.mainMenu.aInsEMDash.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_EMDASH assert nwGUI.docEditor.getText() == nwUnicode.U_EMDASH
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsHorBar.activate(QAction.Trigger) nwGUI.mainMenu.aInsHorBar.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_HBAR assert nwGUI.docEditor.getText() == nwUnicode.U_HBAR
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsFigDash.activate(QAction.Trigger) nwGUI.mainMenu.aInsFigDash.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_FGDASH assert nwGUI.docEditor.getText() == nwUnicode.U_FGDASH
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsQuoteLS.activate(QAction.Trigger) nwGUI.mainMenu.aInsQuoteLS.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == CONFIG.fmtSQuoteOpen assert nwGUI.docEditor.getText() == CONFIG.fmtSQuoteOpen
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsQuoteRS.activate(QAction.Trigger) nwGUI.mainMenu.aInsQuoteRS.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == CONFIG.fmtSQuoteClose assert nwGUI.docEditor.getText() == CONFIG.fmtSQuoteClose
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsQuoteLD.activate(QAction.Trigger) nwGUI.mainMenu.aInsQuoteLD.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == CONFIG.fmtDQuoteOpen assert nwGUI.docEditor.getText() == CONFIG.fmtDQuoteOpen
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsQuoteRD.activate(QAction.Trigger) nwGUI.mainMenu.aInsQuoteRD.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == CONFIG.fmtDQuoteClose assert nwGUI.docEditor.getText() == CONFIG.fmtDQuoteClose
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsMSApos.activate(QAction.Trigger) nwGUI.mainMenu.aInsMSApos.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_MAPOS assert nwGUI.docEditor.getText() == nwUnicode.U_MAPOS
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsEllipsis.activate(QAction.Trigger) nwGUI.mainMenu.aInsEllipsis.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_HELLIP assert nwGUI.docEditor.getText() == nwUnicode.U_HELLIP
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsPrime.activate(QAction.Trigger) nwGUI.mainMenu.aInsPrime.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_PRIME assert nwGUI.docEditor.getText() == nwUnicode.U_PRIME
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsDPrime.activate(QAction.Trigger) nwGUI.mainMenu.aInsDPrime.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_DPRIME assert nwGUI.docEditor.getText() == nwUnicode.U_DPRIME
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsBullet.activate(QAction.Trigger) nwGUI.mainMenu.aInsBullet.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_BULL assert nwGUI.docEditor.getText() == nwUnicode.U_BULL
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsHyBull.activate(QAction.Trigger) nwGUI.mainMenu.aInsHyBull.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_HYBULL assert nwGUI.docEditor.getText() == nwUnicode.U_HYBULL
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsFlower.activate(QAction.Trigger) nwGUI.mainMenu.aInsFlower.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_FLOWER assert nwGUI.docEditor.getText() == nwUnicode.U_FLOWER
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsPerMille.activate(QAction.Trigger) nwGUI.mainMenu.aInsPerMille.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_PERMIL assert nwGUI.docEditor.getText() == nwUnicode.U_PERMIL
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsDegree.activate(QAction.Trigger) nwGUI.mainMenu.aInsDegree.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_DEGREE assert nwGUI.docEditor.getText() == nwUnicode.U_DEGREE
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsMinus.activate(QAction.Trigger) nwGUI.mainMenu.aInsMinus.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_MINUS assert nwGUI.docEditor.getText() == nwUnicode.U_MINUS
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsTimes.activate(QAction.Trigger) nwGUI.mainMenu.aInsTimes.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_TIMES assert nwGUI.docEditor.getText() == nwUnicode.U_TIMES
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsDivide.activate(QAction.Trigger) nwGUI.mainMenu.aInsDivide.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_DIVIDE assert nwGUI.docEditor.getText() == nwUnicode.U_DIVIDE
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsNBSpace.activate(QAction.Trigger) nwGUI.mainMenu.aInsNBSpace.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_NBSP assert nwGUI.docEditor.getText() == nwUnicode.U_NBSP
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsThinSpace.activate(QAction.Trigger) nwGUI.mainMenu.aInsThinSpace.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_THSP assert nwGUI.docEditor.getText() == nwUnicode.U_THSP
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
nwGUI.mainMenu.aInsThinNBSpace.activate(QAction.Trigger) nwGUI.mainMenu.aInsThinNBSpace.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == nwUnicode.U_THNBSP assert nwGUI.docEditor.getText() == nwUnicode.U_THNBSP
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
@@ -463,43 +464,43 @@ def testGuiMainMenu_Insert(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockRnd
# =============== # ===============
nwGUI.docEditor.setPlainText("Stuff") nwGUI.docEditor.setPlainText("Stuff")
nwGUI.mainMenu.mInsKWItems[nwKeyWords.TAG_KEY][0].activate(QAction.Trigger) nwGUI.mainMenu.mInsKWItems[nwKeyWords.TAG_KEY][0].activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.TAG_KEY assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.TAG_KEY
nwGUI.docEditor.setPlainText("Stuff") nwGUI.docEditor.setPlainText("Stuff")
nwGUI.mainMenu.mInsKWItems[nwKeyWords.POV_KEY][0].activate(QAction.Trigger) nwGUI.mainMenu.mInsKWItems[nwKeyWords.POV_KEY][0].activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.POV_KEY assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.POV_KEY
nwGUI.docEditor.setPlainText("Stuff") nwGUI.docEditor.setPlainText("Stuff")
nwGUI.mainMenu.mInsKWItems[nwKeyWords.FOCUS_KEY][0].activate(QAction.Trigger) nwGUI.mainMenu.mInsKWItems[nwKeyWords.FOCUS_KEY][0].activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.FOCUS_KEY assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.FOCUS_KEY
nwGUI.docEditor.setPlainText("Stuff") nwGUI.docEditor.setPlainText("Stuff")
nwGUI.mainMenu.mInsKWItems[nwKeyWords.CHAR_KEY][0].activate(QAction.Trigger) nwGUI.mainMenu.mInsKWItems[nwKeyWords.CHAR_KEY][0].activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.CHAR_KEY assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.CHAR_KEY
nwGUI.docEditor.setPlainText("Stuff") nwGUI.docEditor.setPlainText("Stuff")
nwGUI.mainMenu.mInsKWItems[nwKeyWords.PLOT_KEY][0].activate(QAction.Trigger) nwGUI.mainMenu.mInsKWItems[nwKeyWords.PLOT_KEY][0].activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.PLOT_KEY assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.PLOT_KEY
nwGUI.docEditor.setPlainText("Stuff") nwGUI.docEditor.setPlainText("Stuff")
nwGUI.mainMenu.mInsKWItems[nwKeyWords.TIME_KEY][0].activate(QAction.Trigger) nwGUI.mainMenu.mInsKWItems[nwKeyWords.TIME_KEY][0].activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.TIME_KEY assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.TIME_KEY
nwGUI.docEditor.setPlainText("Stuff") nwGUI.docEditor.setPlainText("Stuff")
nwGUI.mainMenu.mInsKWItems[nwKeyWords.WORLD_KEY][0].activate(QAction.Trigger) nwGUI.mainMenu.mInsKWItems[nwKeyWords.WORLD_KEY][0].activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.WORLD_KEY assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.WORLD_KEY
nwGUI.docEditor.setPlainText("Stuff") nwGUI.docEditor.setPlainText("Stuff")
nwGUI.mainMenu.mInsKWItems[nwKeyWords.OBJECT_KEY][0].activate(QAction.Trigger) nwGUI.mainMenu.mInsKWItems[nwKeyWords.OBJECT_KEY][0].activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.OBJECT_KEY assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.OBJECT_KEY
nwGUI.docEditor.setPlainText("Stuff") nwGUI.docEditor.setPlainText("Stuff")
nwGUI.mainMenu.mInsKWItems[nwKeyWords.ENTITY_KEY][0].activate(QAction.Trigger) nwGUI.mainMenu.mInsKWItems[nwKeyWords.ENTITY_KEY][0].activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.ENTITY_KEY assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.ENTITY_KEY
nwGUI.docEditor.setPlainText("Stuff") nwGUI.docEditor.setPlainText("Stuff")
nwGUI.mainMenu.mInsKWItems[nwKeyWords.CUSTOM_KEY][0].activate(QAction.Trigger) nwGUI.mainMenu.mInsKWItems[nwKeyWords.CUSTOM_KEY][0].activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.CUSTOM_KEY assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.CUSTOM_KEY
# Faulty Keyword Inserts # Faulty Keyword Inserts
@@ -514,26 +515,26 @@ def testGuiMainMenu_Insert(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockRnd
# ======================= # =======================
nwGUI.docEditor.setPlainText("Stuff\n") nwGUI.docEditor.setPlainText("Stuff\n")
nwGUI.mainMenu.aInsSynopsis.activate(QAction.Trigger) nwGUI.mainMenu.aInsSynopsis.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "Stuff\n%Synopsis: \n" assert nwGUI.docEditor.getText() == "Stuff\n%Synopsis: \n"
nwGUI.docEditor.setPlainText("Stuff\n") nwGUI.docEditor.setPlainText("Stuff\n")
nwGUI.mainMenu.aInsShort.activate(QAction.Trigger) nwGUI.mainMenu.aInsShort.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "Stuff\n%Short: \n" assert nwGUI.docEditor.getText() == "Stuff\n%Short: \n"
# Insert Break or Space # Insert Break or Space
# ===================== # =====================
nwGUI.docEditor.setPlainText("### Stuff\n") nwGUI.docEditor.setPlainText("### Stuff\n")
nwGUI.mainMenu.aInsNewPage.activate(QAction.Trigger) nwGUI.mainMenu.aInsNewPage.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "[newpage]\n### Stuff\n" assert nwGUI.docEditor.getText() == "[newpage]\n### Stuff\n"
nwGUI.docEditor.setPlainText("### Stuff\n") nwGUI.docEditor.setPlainText("### Stuff\n")
nwGUI.mainMenu.aInsVSpaceS.activate(QAction.Trigger) nwGUI.mainMenu.aInsVSpaceS.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "[vspace]\n### Stuff\n" assert nwGUI.docEditor.getText() == "[vspace]\n### Stuff\n"
nwGUI.docEditor.setPlainText("### Stuff\n") nwGUI.docEditor.setPlainText("### Stuff\n")
nwGUI.mainMenu.aInsVSpaceM.activate(QAction.Trigger) nwGUI.mainMenu.aInsVSpaceM.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "[vspace:2]\n### Stuff\n" assert nwGUI.docEditor.getText() == "[vspace:2]\n### Stuff\n"
nwGUI.docEditor.clear() nwGUI.docEditor.clear()
@@ -567,18 +568,18 @@ def testGuiMainMenu_Insert(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockRnd
# The document isn't empty, so the message box should pop # The document isn't empty, so the message box should pop
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QMessageBox, "result", lambda *a, **k: QMessageBox.No) mp.setattr(QMessageBox, "result", lambda *a, **k: QMessageBox.StandardButton.No)
assert not nwGUI.importDocument() assert not nwGUI.importDocument()
assert nwGUI.docEditor.getText() == "Bar" assert nwGUI.docEditor.getText() == "Bar"
# Finally, accept the replaced text, this time we use the menu entry to trigger it # Finally, accept the replaced text, this time we use the menu entry to trigger it
nwGUI.mainMenu.aImportFile.activate(QAction.Trigger) nwGUI.mainMenu.aImportFile.activate(QAction.ActionEvent.Trigger)
assert nwGUI.docEditor.getText() == "Foo" assert nwGUI.docEditor.getText() == "Foo"
# Reveal File Location # Reveal File Location
# ==================== # ====================
nwGUI.mainMenu.aFileDetails.activate(QAction.Trigger) nwGUI.mainMenu.aFileDetails.activate(QAction.ActionEvent.Trigger)
path = str(projPath / "content" / "000000000000f.nwd") path = str(projPath / "content" / "000000000000f.nwd")
assert SHARED.lastAlert.endswith(f"File Location: {path}") assert SHARED.lastAlert.endswith(f"File Location: {path}")
+4 -4
View File
@@ -32,7 +32,7 @@ from novelwriter import CONFIG, SHARED
from novelwriter.dialogs.editlabel import GuiEditLabel from novelwriter.dialogs.editlabel import GuiEditLabel
from novelwriter.enum import nwFocus, nwItemType from novelwriter.enum import nwFocus, nwItemType
from novelwriter.gui.noveltree import GuiNovelTree, NovelTreeColumn from novelwriter.gui.noveltree import GuiNovelTree, NovelTreeColumn
from novelwriter.types import QtMouseLeft from novelwriter.types import QtMouseLeft, QtMouseMiddle
from tests.tools import C, buildTestProject from tests.tools import C, buildTestProject
@@ -127,17 +127,17 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
scItem.setSelected(True) scItem.setSelected(True)
assert scItem.isSelected() assert scItem.isSelected()
assert nwGUI.docViewer.docHandle is None assert nwGUI.docViewer.docHandle is None
qtbot.mouseClick(vPort, Qt.MiddleButton, pos=vPort.rect().center(), delay=10) qtbot.mouseClick(vPort, QtMouseMiddle, pos=vPort.rect().center(), delay=10)
assert nwGUI.docViewer.docHandle is None assert nwGUI.docViewer.docHandle is None
scRect = novelTree.visualItemRect(scItem) scRect = novelTree.visualItemRect(scItem)
oldData = scItem.data(novelTree.C_TITLE, novelTree.D_HANDLE) oldData = scItem.data(novelTree.C_TITLE, novelTree.D_HANDLE)
scItem.setData(novelTree.C_TITLE, novelTree.D_HANDLE, None) scItem.setData(novelTree.C_TITLE, novelTree.D_HANDLE, None)
qtbot.mouseClick(vPort, Qt.MiddleButton, pos=scRect.center(), delay=10) qtbot.mouseClick(vPort, QtMouseMiddle, pos=scRect.center(), delay=10)
assert nwGUI.docViewer.docHandle is None assert nwGUI.docViewer.docHandle is None
scItem.setData(novelTree.C_TITLE, novelTree.D_HANDLE, oldData) scItem.setData(novelTree.C_TITLE, novelTree.D_HANDLE, oldData)
qtbot.mouseClick(vPort, Qt.MiddleButton, pos=scRect.center(), delay=10) qtbot.mouseClick(vPort, QtMouseMiddle, pos=scRect.center(), delay=10)
assert nwGUI.docViewer.docHandle == C.hSceneDoc assert nwGUI.docViewer.docHandle == C.hSceneDoc
# Last Column # Last Column
+10 -10
View File
@@ -26,11 +26,11 @@ from shutil import copyfile
import pytest import pytest
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QAction, QFileDialog, QWidget from PyQt5.QtWidgets import QAction, QFileDialog, QWidget
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.enum import nwItemClass, nwOutline, nwView from novelwriter.enum import nwItemClass, nwOutline, nwView
from novelwriter.types import QtScrollAlwaysOff, QtScrollAsNeeded
from tests.tools import buildTestProject, cmpFiles, writeFile from tests.tools import buildTestProject, cmpFiles, writeFile
@@ -53,18 +53,18 @@ def testGuiOutline_Main(qtbot, monkeypatch, nwGUI, projPath):
CONFIG.hideVScroll = True CONFIG.hideVScroll = True
CONFIG.hideHScroll = True CONFIG.hideHScroll = True
outlineView.initSettings() outlineView.initSettings()
assert outlineTree.verticalScrollBarPolicy() == Qt.ScrollBarAlwaysOff assert outlineTree.verticalScrollBarPolicy() == QtScrollAlwaysOff
assert outlineTree.horizontalScrollBarPolicy() == Qt.ScrollBarAlwaysOff assert outlineTree.horizontalScrollBarPolicy() == QtScrollAlwaysOff
assert outlineData.verticalScrollBarPolicy() == Qt.ScrollBarAlwaysOff assert outlineData.verticalScrollBarPolicy() == QtScrollAlwaysOff
assert outlineData.horizontalScrollBarPolicy() == Qt.ScrollBarAlwaysOff assert outlineData.horizontalScrollBarPolicy() == QtScrollAlwaysOff
CONFIG.hideVScroll = False CONFIG.hideVScroll = False
CONFIG.hideHScroll = False CONFIG.hideHScroll = False
outlineView.initSettings() outlineView.initSettings()
assert outlineTree.verticalScrollBarPolicy() == Qt.ScrollBarAsNeeded assert outlineTree.verticalScrollBarPolicy() == QtScrollAsNeeded
assert outlineTree.horizontalScrollBarPolicy() == Qt.ScrollBarAsNeeded assert outlineTree.horizontalScrollBarPolicy() == QtScrollAsNeeded
assert outlineData.verticalScrollBarPolicy() == Qt.ScrollBarAsNeeded assert outlineData.verticalScrollBarPolicy() == QtScrollAsNeeded
assert outlineData.horizontalScrollBarPolicy() == Qt.ScrollBarAsNeeded assert outlineData.horizontalScrollBarPolicy() == QtScrollAsNeeded
# Check focus # Check focus
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
@@ -152,7 +152,7 @@ def testGuiOutline_Main(qtbot, monkeypatch, nwGUI, projPath):
# Trigger the menu entry for all hidden columns # Trigger the menu entry for all hidden columns
for hItem in nwOutline: for hItem in nwOutline:
if outlineTree.DEF_HIDDEN[hItem]: if outlineTree.DEF_HIDDEN[hItem]:
outlineMenu.actionMap[hItem].activate(QAction.Trigger) outlineMenu.actionMap[hItem].activate(QAction.ActionEvent.Trigger)
# Now no columns should be hidden # Now no columns should be hidden
outlineTree._saveHeaderState() outlineTree._saveHeaderState()
+13 -10
View File
@@ -37,7 +37,10 @@ from novelwriter.dialogs.editlabel import GuiEditLabel
from novelwriter.enum import nwFocus, nwItemClass, nwItemLayout, nwItemType from novelwriter.enum import nwFocus, nwItemClass, nwItemLayout, nwItemType
from novelwriter.gui.projtree import GuiProjectTree, GuiProjectView, _TreeContextMenu from novelwriter.gui.projtree import GuiProjectTree, GuiProjectView, _TreeContextMenu
from novelwriter.guimain import GuiMain from novelwriter.guimain import GuiMain
from novelwriter.types import QtAccepted, QtModNone, QtMouseLeft, QtMouseMiddle, QtRejected from novelwriter.types import (
QtAccepted, QtModNone, QtMouseLeft, QtMouseMiddle, QtRejected,
QtScrollAlwaysOff, QtScrollAsNeeded
)
from tests.mocked import causeOSError from tests.mocked import causeOSError
from tests.tools import C, buildTestProject from tests.tools import C, buildTestProject
@@ -411,7 +414,7 @@ def testGuiProjTree_MoveItemToTrash(qtbot, caplog, monkeypatch, nwGUI, projPath,
# User cancels action # User cancels action
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No) mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
assert projTree.moveItemToTrash(C.hTitlePage) is False assert projTree.moveItemToTrash(C.hTitlePage) is False
assert project.tree.isTrash(C.hTitlePage) is False assert project.tree.isTrash(C.hTitlePage) is False
@@ -456,7 +459,7 @@ def testGuiProjTree_PermanentlyDeleteItem(qtbot, caplog, monkeypatch, nwGUI, pro
# User cancels action # User cancels action
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No) mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
assert projTree.permDeleteItem(C.hTitlePage) is False assert projTree.permDeleteItem(C.hTitlePage) is False
assert C.hTitlePage in project.tree assert C.hTitlePage in project.tree
@@ -506,7 +509,7 @@ def testGuiProjTree_EmptyTrash(qtbot, caplog, monkeypatch, nwGUI, projPath, mock
# User cancels # User cancels
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No) mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
assert projTree.emptyTrash() is False assert projTree.emptyTrash() is False
assert C.hTitlePage in project.tree assert C.hTitlePage in project.tree
assert C.hChapterDir in project.tree assert C.hChapterDir in project.tree
@@ -751,7 +754,7 @@ def testGuiProjTree_Duplicate(qtbot, monkeypatch, nwGUI: GuiMain, projPath, mock
# Duplicate title page, but select no # Duplicate title page, but select no
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No) mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
assert projTree._duplicateFromHandle(C.hTitlePage) is False assert projTree._duplicateFromHandle(C.hTitlePage) is False
assert len(SHARED.project.tree) == 8 assert len(SHARED.project.tree) == 8
@@ -957,14 +960,14 @@ def testGuiProjTree_Other(qtbot, monkeypatch, nwGUI: GuiMain, projPath, mockRnd)
CONFIG.hideVScroll = True CONFIG.hideVScroll = True
CONFIG.hideHScroll = True CONFIG.hideHScroll = True
projView.initSettings() projView.initSettings()
assert projTree.verticalScrollBarPolicy() == Qt.ScrollBarAlwaysOff assert projTree.verticalScrollBarPolicy() == QtScrollAlwaysOff
assert projTree.horizontalScrollBarPolicy() == Qt.ScrollBarAlwaysOff assert projTree.horizontalScrollBarPolicy() == QtScrollAlwaysOff
CONFIG.hideVScroll = False CONFIG.hideVScroll = False
CONFIG.hideHScroll = False CONFIG.hideHScroll = False
projView.initSettings() projView.initSettings()
assert projTree.verticalScrollBarPolicy() == Qt.ScrollBarAsNeeded assert projTree.verticalScrollBarPolicy() == QtScrollAsNeeded
assert projTree.horizontalScrollBarPolicy() == Qt.ScrollBarAsNeeded assert projTree.horizontalScrollBarPolicy() == QtScrollAsNeeded
# Method: revealNewTreeItem # Method: revealNewTreeItem
# ========================= # =========================
@@ -1313,7 +1316,7 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
# Click no on the dialog # Click no on the dialog
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No) mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
ctxMenu._covertFolderToFile(nwItemLayout.DOCUMENT) ctxMenu._covertFolderToFile(nwItemLayout.DOCUMENT)
assert SHARED.project.tree[hNewFolderOne].isFolderType() # type: ignore assert SHARED.project.tree[hNewFolderOne].isFolderType() # type: ignore
+1 -1
View File
@@ -35,7 +35,7 @@ from tests.tools import C, buildTestProject
def testToolLipsum_Main(qtbot, monkeypatch, nwGUI, projPath, mockRnd): def testToolLipsum_Main(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
"""Test the Lorem Ipsum tool.""" """Test the Lorem Ipsum tool."""
# Check that we cannot open when there is no project # Check that we cannot open when there is no project
nwGUI.mainMenu.aLipsumText.activate(QAction.Trigger) nwGUI.mainMenu.aLipsumText.activate(QAction.ActionEvent.Trigger)
assert SHARED.findTopLevelWidget(GuiLipsum) is None assert SHARED.findTopLevelWidget(GuiLipsum) is None
buildTestProject(nwGUI, projPath) buildTestProject(nwGUI, projPath)
+1 -1
View File
@@ -133,7 +133,7 @@ def testToolManuscriptBuild_Main(
manus.buildPath.setText(str(fncPath)) manus.buildPath.setText(str(fncPath))
manus.buildName.setText("TestBuild") manus.buildName.setText("TestBuild")
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.No) mp.setattr(QMessageBox, "result", lambda *a: QMessageBox.StandardButton.No)
assert manus._runBuild() is False assert manus._runBuild() is False
# Test that the open button works # Test that the open button works
+1 -1
View File
@@ -47,7 +47,7 @@ def testToolManuscript_Init(monkeypatch, qtbot, nwGUI, projPath, mockRnd):
SHARED.project.storage.getDocument(C.hChapterDoc).writeDocument("## A Chapter\n\n\t\tHi") SHARED.project.storage.getDocument(C.hChapterDoc).writeDocument("## A Chapter\n\n\t\tHi")
allText = "New Novel\nBy Jane Doe\nA Chapter\n\t\tHi" allText = "New Novel\nBy Jane Doe\nA Chapter\n\t\tHi"
nwGUI.mainMenu.aBuildManuscript.activate(QAction.Trigger) nwGUI.mainMenu.aBuildManuscript.activate(QAction.ActionEvent.Trigger)
qtbot.waitUntil(lambda: SHARED.findTopLevelWidget(GuiManuscript) is not None, timeout=1000) qtbot.waitUntil(lambda: SHARED.findTopLevelWidget(GuiManuscript) is not None, timeout=1000)
manus = SHARED.findTopLevelWidget(GuiManuscript) manus = SHARED.findTopLevelWidget(GuiManuscript)
assert isinstance(manus, GuiManuscript) assert isinstance(manus, GuiManuscript)
+1 -1
View File
@@ -45,7 +45,7 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, projPath, tstPaths):
sessFile = projPath / "meta" / nwFiles.SESS_FILE sessFile = projPath / "meta" / nwFiles.SESS_FILE
# Open the Writing Stats dialog # Open the Writing Stats dialog
nwGUI.mainMenu.aWritingStats.activate(QAction.Trigger) nwGUI.mainMenu.aWritingStats.activate(QAction.ActionEvent.Trigger)
qtbot.waitUntil(lambda: SHARED.findTopLevelWidget(GuiWritingStats) is not None, timeout=1000) qtbot.waitUntil(lambda: SHARED.findTopLevelWidget(GuiWritingStats) is not None, timeout=1000)
sessLog = SHARED.findTopLevelWidget(GuiWritingStats) sessLog = SHARED.findTopLevelWidget(GuiWritingStats)