Merge branch 'main' into dialogue_highlight

This commit is contained in:
Veronica Berglyd Olsen
2024-06-10 13:48:40 +02:00
committed by GitHub
11 changed files with 49 additions and 33 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ class GuiAbout(NDialog):
# Buttons # Buttons
self.btnBox = QDialogButtonBox(QtDialogClose, self) self.btnBox = QDialogButtonBox(QtDialogClose, self)
self.btnBox.rejected.connect(self.close) self.btnBox.rejected.connect(self.reject)
# Assemble # Assemble
self.innerBox = QVBoxLayout() self.innerBox = QVBoxLayout()
+11 -1
View File
@@ -27,7 +27,7 @@ from __future__ import annotations
import logging import logging
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
from PyQt5.QtGui import QCloseEvent from PyQt5.QtGui import QCloseEvent, QKeyEvent, QKeySequence
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAbstractButton, QCompleter, QDialogButtonBox, QFileDialog, QHBoxLayout, QAbstractButton, QCompleter, QDialogButtonBox, QFileDialog, QHBoxLayout,
QLineEdit, QPushButton, QVBoxLayout, QWidget QLineEdit, QPushButton, QVBoxLayout, QWidget
@@ -770,6 +770,16 @@ class GuiPreferences(NDialog):
self.softDelete() self.softDelete()
return return
def keyPressEvent(self, event: QKeyEvent) -> None:
"""Overload keyPressEvent and only accept escape. The main
purpose here is to prevent Enter/Return from closing the dialog
as it is used for the search box.
"""
if event.matches(QKeySequence.StandardKey.Cancel):
self.close()
event.ignore()
return
## ##
# Private Slots # Private Slots
## ##
+1 -1
View File
@@ -92,7 +92,7 @@ class GuiProjectSettings(NDialog):
# Buttons # Buttons
self.buttonBox = QDialogButtonBox(QtDialogSave | QtDialogCancel, self) self.buttonBox = QDialogButtonBox(QtDialogSave | QtDialogCancel, self)
self.buttonBox.accepted.connect(self._doSave) self.buttonBox.accepted.connect(self._doSave)
self.buttonBox.rejected.connect(self.close) self.buttonBox.rejected.connect(self.reject)
# Content # Content
SHARED.project.countStatus() SHARED.project.countStatus()
+1 -1
View File
@@ -109,7 +109,7 @@ class GuiWordList(NDialog):
# Buttons # Buttons
self.buttonBox = QDialogButtonBox(QtDialogSave | QtDialogClose, self) self.buttonBox = QDialogButtonBox(QtDialogSave | QtDialogClose, self)
self.buttonBox.accepted.connect(self._doSave) self.buttonBox.accepted.connect(self._doSave)
self.buttonBox.rejected.connect(self.close) self.buttonBox.rejected.connect(self.reject)
# Assemble # Assemble
self.outerBox = QVBoxLayout() self.outerBox = QVBoxLayout()
+7 -7
View File
@@ -30,8 +30,8 @@ from __future__ import annotations
from enum import Enum from enum import Enum
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from PyQt5.QtCore import QSize, Qt from PyQt5.QtCore import QSize, Qt, pyqtSlot
from PyQt5.QtGui import QKeyEvent, QKeySequence, QWheelEvent from PyQt5.QtGui import QWheelEvent
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QApplication, QComboBox, QDialog, QDoubleSpinBox, QSpinBox, QToolButton, QApplication, QComboBox, QDialog, QDoubleSpinBox, QSpinBox, QToolButton,
QWidget QWidget
@@ -54,11 +54,11 @@ class NDialog(QDialog):
self.setParent(None) # type: ignore self.setParent(None) # type: ignore
return return
def keyPressEvent(self, event: QKeyEvent) -> None: @pyqtSlot()
"""Overload keyPressEvent and forward escape to close.""" def reject(self) -> None:
if event.matches(QKeySequence.StandardKey.Cancel): """Overload the reject slot and also call close."""
self.close() super().reject()
event.ignore() self.close()
return return
+1 -7
View File
@@ -109,7 +109,7 @@ class GuiDictionaries(NNonBlockingDialog):
# Buttons # Buttons
self.buttonBox = QDialogButtonBox(QtDialogClose, self) self.buttonBox = QDialogButtonBox(QtDialogClose, self)
self.buttonBox.rejected.connect(self._doClose) self.buttonBox.rejected.connect(self.reject)
# Assemble # Assemble
self.innerBox = QVBoxLayout() self.innerBox = QVBoxLayout()
@@ -220,12 +220,6 @@ class GuiDictionaries(NNonBlockingDialog):
SHARED.error("Path not found.") SHARED.error("Path not found.")
return return
@pyqtSlot()
def _doClose(self) -> None:
"""Close the dialog."""
self.close()
return
## ##
# Internal Functions # Internal Functions
## ##
+3 -8
View File
@@ -26,7 +26,7 @@ from __future__ import annotations
import logging import logging
import random import random
from PyQt5.QtCore import Qt, pyqtSlot from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QDialogButtonBox, QGridLayout, QHBoxLayout, QLabel, QSpinBox, QVBoxLayout, QDialogButtonBox, QGridLayout, QHBoxLayout, QLabel, QSpinBox, QVBoxLayout,
QWidget QWidget
@@ -48,13 +48,10 @@ class GuiLipsum(NDialog):
logger.debug("Create: GuiLipsum") logger.debug("Create: GuiLipsum")
self.setObjectName("GuiLipsum") self.setObjectName("GuiLipsum")
if CONFIG.osDarwin: self.setWindowTitle(self.tr("Insert Placeholder Text"))
self.setWindowFlag(Qt.WindowType.Tool)
self._lipsumText = "" self._lipsumText = ""
self.setWindowTitle(self.tr("Insert Placeholder Text"))
vSp = CONFIG.pxInt(4) vSp = CONFIG.pxInt(4)
nPx = CONFIG.pxInt(64) nPx = CONFIG.pxInt(64)
@@ -96,7 +93,7 @@ class GuiLipsum(NDialog):
# Buttons # Buttons
self.buttonBox = QDialogButtonBox(self) self.buttonBox = QDialogButtonBox(self)
self.buttonBox.rejected.connect(self.close) self.buttonBox.rejected.connect(self.reject)
self.btnClose = self.buttonBox.addButton(QtDialogClose) self.btnClose = self.buttonBox.addButton(QtDialogClose)
self.btnClose.setAutoDefault(False) self.btnClose.setAutoDefault(False)
@@ -105,8 +102,6 @@ class GuiLipsum(NDialog):
self.btnInsert.clicked.connect(self._doInsert) self.btnInsert.clicked.connect(self._doInsert)
self.btnInsert.setAutoDefault(False) self.btnInsert.setAutoDefault(False)
self.rejected.connect(self.close)
# Assemble # Assemble
self.outerBox = QVBoxLayout() self.outerBox = QVBoxLayout()
self.outerBox.addLayout(self.innerBox) self.outerBox.addLayout(self.innerBox)
+1 -1
View File
@@ -97,7 +97,7 @@ class GuiNovelDetails(NNonBlockingDialog):
# Buttons # Buttons
self.buttonBox = QDialogButtonBox(QtDialogClose, self) self.buttonBox = QDialogButtonBox(QtDialogClose, self)
self.buttonBox.rejected.connect(self.close) self.buttonBox.rejected.connect(self.reject)
# Assemble # Assemble
self.topBox = QHBoxLayout() self.topBox = QHBoxLayout()
+20 -3
View File
@@ -22,10 +22,12 @@ from __future__ import annotations
import pytest import pytest
from PyQt5.QtCore import QPoint, QPointF, Qt from PyQt5.QtCore import QEvent, QPoint, QPointF, Qt
from PyQt5.QtGui import QWheelEvent from PyQt5.QtGui import QKeyEvent, QWheelEvent
from PyQt5.QtWidgets import QWidget
from novelwriter.extensions.modified import NComboBox, NDoubleSpinBox, NSpinBox from novelwriter.extensions.modified import NComboBox, NDialog, NDoubleSpinBox, NSpinBox
from novelwriter.types import QtModNone, QtRejected
from tests.tools import SimpleDialog from tests.tools import SimpleDialog
@@ -47,6 +49,21 @@ class MockWheelEvent(QWheelEvent):
return return
@pytest.mark.gui
def testExtModified_NDialog(qtbot, monkeypatch):
"""Test the NDialog class."""
widget = QWidget()
dialog = NDialog(widget)
assert dialog.parent() is widget
dialog.softDelete()
assert dialog.parent() is None
with qtbot.waitSignal(dialog.rejected, timeout=1000):
dialog.keyPressEvent(QKeyEvent(QEvent.Type.KeyPress, Qt.Key.Key_Escape, QtModNone))
assert dialog.result() == QtRejected
@pytest.mark.gui @pytest.mark.gui
def testExtModified_NComboBox(qtbot, monkeypatch): def testExtModified_NComboBox(qtbot, monkeypatch):
"""Test the NComboBox class.""" """Test the NComboBox class."""
@@ -152,6 +152,4 @@ def testToolDictionaries_Main(qtbot, monkeypatch, nwGUI, fncPath):
"Additional dictionaries found: 2" "Additional dictionaries found: 2"
) )
# Close
nwDicts._doClose()
# qtbot.stop() # qtbot.stop()
+3 -1
View File
@@ -25,6 +25,7 @@ import pytest
from PyQt5.QtWidgets import QAction from PyQt5.QtWidgets import QAction
from novelwriter import SHARED from novelwriter import SHARED
from novelwriter.enum import nwDocInsert
from novelwriter.tools.lipsum import GuiLipsum from novelwriter.tools.lipsum import GuiLipsum
from tests.tools import C, buildTestProject from tests.tools import C, buildTestProject
@@ -62,7 +63,8 @@ def testToolLipsum_Main(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(GuiLipsum, "exec", lambda *a: None) mp.setattr(GuiLipsum, "exec", lambda *a: None)
mp.setattr(GuiLipsum, "lipsumText", "FooBar") mp.setattr(GuiLipsum, "lipsumText", "FooBar")
nwGUI.mainMenu.aLipsumText.activate(QAction.Trigger) with qtbot.waitSignal(nwGUI.docEditor.textChanged):
nwGUI.docEditor.insertText(nwDocInsert.LIPSUM)
assert nwGUI.docEditor.getText() == "### New Scene\n\nFooBar" assert nwGUI.docEditor.getText() == "### New Scene\n\nFooBar"
# qtbot.stop() # qtbot.stop()