From 1307fccc593918e5fdca74e7625da3223a65cadb Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 11 Jan 2025 21:42:37 +0100 Subject: [PATCH] Fix some minor GUI issues --- novelwriter/extensions/switch.py | 10 ++++------ novelwriter/tools/welcome.py | 17 +++-------------- tests/test_tools/test_tools_welcome.py | 12 ++++-------- 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/novelwriter/extensions/switch.py b/novelwriter/extensions/switch.py index 7b8c401d..9ee155a7 100644 --- a/novelwriter/extensions/switch.py +++ b/novelwriter/extensions/switch.py @@ -23,15 +23,13 @@ along with this program. If not, see . """ from __future__ import annotations -from PyQt6.QtCore import QByteArray, QPropertyAnimation, Qt +from PyQt6.QtCore import QPropertyAnimation, Qt, pyqtProperty from PyQt6.QtGui import QEnterEvent, QMouseEvent, QPainter, QPaintEvent, QResizeEvent from PyQt6.QtWidgets import QAbstractButton, QWidget from novelwriter import CONFIG, SHARED from novelwriter.types import QtMouseLeft, QtNoPen, QtPaintAntiAlias, QtSizeFixed -OFFSET = QByteArray(b"offset") # type: ignore - class NSwitch(QAbstractButton): @@ -59,11 +57,11 @@ class NSwitch(QAbstractButton): # Properties ## - @property + @pyqtProperty(int) def offset(self) -> int: # type: ignore return self._offset - @offset.setter # type: ignore + @offset.setter def offset(self, offset: int) -> None: self._offset = offset self.update() @@ -123,7 +121,7 @@ class NSwitch(QAbstractButton): """Animate the switch on mouse release.""" super().mouseReleaseEvent(event) if event.button() == QtMouseLeft: - anim = QPropertyAnimation(self, OFFSET, self) + anim = QPropertyAnimation(self, b"offset", self) anim.setDuration(120) anim.setStartValue(self._offset) anim.setEndValue((self._xW - self._xR) if self.isChecked() else self._xR) diff --git a/novelwriter/tools/welcome.py b/novelwriter/tools/welcome.py index 885a7da7..7dc2298e 100644 --- a/novelwriter/tools/welcome.py +++ b/novelwriter/tools/welcome.py @@ -29,8 +29,8 @@ from datetime import datetime from pathlib import Path from PyQt6.QtCore import ( - QAbstractListModel, QEvent, QModelIndex, QObject, QPoint, QSize, Qt, - pyqtSignal, pyqtSlot + QAbstractListModel, QModelIndex, QObject, QPoint, QSize, Qt, pyqtSignal, + pyqtSlot ) from PyQt6.QtGui import QAction, QCloseEvent, QColor, QFont, QPainter, QPaintEvent, QPen, QShortcut from PyQt6.QtWidgets import ( @@ -590,7 +590,7 @@ class _NewProjectForm(QWidget): self.browseFill = NIconToolButton(self, iSz, "document_add", "blue") - self.fillMenu = _PopLeftDirectionMenu(self.browseFill) + self.fillMenu = QMenu(self.browseFill) self.fillBlank = self.fillMenu.addAction(self.tr("Create a fresh project")) self.fillBlank.setIcon(SHARED.theme.getIcon("document")) @@ -802,14 +802,3 @@ class _NewProjectForm(QWidget): self.extraWidget.setVisible(self._fillMode == self.FILL_BLANK) return - - -class _PopLeftDirectionMenu(QMenu): - - def event(self, event: QEvent) -> bool: - """Overload the show event and move the menu popup location.""" - if event.type() == QEvent.Type.Show: - if isinstance(parent := self.parent(), QWidget): - offset = QPoint(parent.width() - self.width(), parent.height()) - self.move(parent.mapToGlobal(offset)) - return super(_PopLeftDirectionMenu, self).event(event) diff --git a/tests/test_tools/test_tools_welcome.py b/tests/test_tools/test_tools_welcome.py index 82b84a87..228b162f 100644 --- a/tests/test_tools/test_tools_welcome.py +++ b/tests/test_tools/test_tools_welcome.py @@ -28,7 +28,6 @@ import pytest from PyQt6.QtCore import QPoint from PyQt6.QtGui import QAction from PyQt6.QtWidgets import QFileDialog, QMenu -from pytestqt.qtbot import QtBot from novelwriter import CONFIG, SHARED from novelwriter.constants import nwFiles @@ -38,7 +37,7 @@ from novelwriter.types import QtMouseLeft @pytest.mark.gui -def testToolWelcome_Main(qtbot: QtBot, monkeypatch, nwGUI, fncPath): +def testToolWelcome_Main(qtbot, monkeypatch, nwGUI, fncPath): """Test the main Welcome window.""" welcome = GuiWelcome(nwGUI) with qtbot.waitExposed(welcome): @@ -68,7 +67,7 @@ def testToolWelcome_Main(qtbot: QtBot, monkeypatch, nwGUI, fncPath): @pytest.mark.gui -def testToolWelcome_Open(qtbot: QtBot, monkeypatch, nwGUI, fncPath): +def testToolWelcome_Open(qtbot, monkeypatch, nwGUI, fncPath): """Test the open tab in the Welcome window.""" monkeypatch.setattr(QMenu, "exec", lambda *a: None) @@ -163,9 +162,9 @@ def testToolWelcome_Open(qtbot: QtBot, monkeypatch, nwGUI, fncPath): welcome.close() -@pytest.mark.skip +# @pytest.mark.skip @pytest.mark.gui -def testToolWelcome_New(qtbot: QtBot, caplog, monkeypatch, nwGUI, fncPath): +def testToolWelcome_New(qtbot, caplog, monkeypatch, nwGUI, fncPath): """Test the new project tab in the Welcome window.""" welcome = GuiWelcome(nwGUI) with qtbot.waitExposed(welcome): @@ -205,10 +204,7 @@ def testToolWelcome_New(qtbot: QtBot, caplog, monkeypatch, nwGUI, fncPath): assert newForm.extraWidget.isVisible() is False # Change back to fill blank using the menu - newForm.browseFill.click() - assert newForm.fillMenu.isVisible() is True newForm.fillMenu.actions()[0].activate(QAction.ActionEvent.Trigger) - newForm.fillMenu.close() assert newForm._fillMode == newForm.FILL_BLANK assert newForm.projFill.text() == "Fresh Project" assert newForm.extraWidget.isVisible() is True