Fix some minor GUI issues

This commit is contained in:
Veronica Berglyd Olsen
2025-01-11 21:42:37 +01:00
parent 86f210cfbf
commit 1307fccc59
3 changed files with 11 additions and 28 deletions
+4 -6
View File
@@ -23,15 +23,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
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)
+3 -14
View File
@@ -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)
+4 -8
View File
@@ -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