Fix various minor issues (#1954)
This commit is contained in:
@@ -29,8 +29,8 @@ import logging
|
|||||||
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
|
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
|
||||||
from PyQt5.QtGui import QCloseEvent, QKeyEvent, QKeySequence
|
from PyQt5.QtGui import QCloseEvent, QKeyEvent, QKeySequence
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QAbstractButton, QCompleter, QDialogButtonBox, QFileDialog, QHBoxLayout,
|
QCompleter, QDialogButtonBox, QFileDialog, QHBoxLayout, QLineEdit,
|
||||||
QLineEdit, QPushButton, QVBoxLayout, QWidget
|
QPushButton, QVBoxLayout, QWidget
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
@@ -43,10 +43,7 @@ from novelwriter.extensions.modified import (
|
|||||||
)
|
)
|
||||||
from novelwriter.extensions.pagedsidebar import NPagedSideBar
|
from novelwriter.extensions.pagedsidebar import NPagedSideBar
|
||||||
from novelwriter.extensions.switch import NSwitch
|
from novelwriter.extensions.switch import NSwitch
|
||||||
from novelwriter.types import (
|
from novelwriter.types import QtAlignCenter, QtDialogCancel, QtDialogSave
|
||||||
QtAlignCenter, QtDialogApply, QtDialogClose, QtDialogSave, QtRoleAccept,
|
|
||||||
QtRoleApply, QtRoleReject
|
|
||||||
)
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -89,8 +86,9 @@ class GuiPreferences(NDialog):
|
|||||||
self.mainForm.setHelpTextStyle(SHARED.theme.helpText)
|
self.mainForm.setHelpTextStyle(SHARED.theme.helpText)
|
||||||
|
|
||||||
# Buttons
|
# Buttons
|
||||||
self.buttonBox = QDialogButtonBox(QtDialogApply | QtDialogSave | QtDialogClose, self)
|
self.buttonBox = QDialogButtonBox(QtDialogSave | QtDialogCancel, self)
|
||||||
self.buttonBox.clicked.connect(self._dialogButtonClicked)
|
self.buttonBox.accepted.connect(self._doSave)
|
||||||
|
self.buttonBox.rejected.connect(self.reject)
|
||||||
|
|
||||||
# Assemble
|
# Assemble
|
||||||
self.searchBox = QHBoxLayout()
|
self.searchBox = QHBoxLayout()
|
||||||
@@ -784,19 +782,6 @@ class GuiPreferences(NDialog):
|
|||||||
# Private Slots
|
# Private Slots
|
||||||
##
|
##
|
||||||
|
|
||||||
@pyqtSlot("QAbstractButton*")
|
|
||||||
def _dialogButtonClicked(self, button: QAbstractButton) -> None:
|
|
||||||
"""Handle button clicks from the dialog button box."""
|
|
||||||
role = self.buttonBox.buttonRole(button)
|
|
||||||
if role == QtRoleApply:
|
|
||||||
self._saveValues()
|
|
||||||
elif role == QtRoleAccept:
|
|
||||||
self._saveValues()
|
|
||||||
self.close()
|
|
||||||
elif role == QtRoleReject:
|
|
||||||
self.close()
|
|
||||||
return
|
|
||||||
|
|
||||||
@pyqtSlot(int)
|
@pyqtSlot(int)
|
||||||
def _sidebarClicked(self, section: int) -> None:
|
def _sidebarClicked(self, section: int) -> None:
|
||||||
"""Process a user request to switch page."""
|
"""Process a user request to switch page."""
|
||||||
@@ -897,7 +882,7 @@ class GuiPreferences(NDialog):
|
|||||||
CONFIG.setPreferencesWinSize(self.width(), self.height())
|
CONFIG.setPreferencesWinSize(self.width(), self.height())
|
||||||
return
|
return
|
||||||
|
|
||||||
def _saveValues(self) -> None:
|
def _doSave(self) -> None:
|
||||||
"""Save the values set in the form."""
|
"""Save the values set in the form."""
|
||||||
updateTheme = False
|
updateTheme = False
|
||||||
needsRestart = False
|
needsRestart = False
|
||||||
@@ -1012,4 +997,6 @@ class GuiPreferences(NDialog):
|
|||||||
CONFIG.saveConfig()
|
CONFIG.saveConfig()
|
||||||
self.newPreferencesReady.emit(needsRestart, refreshTree, updateTheme, updateSyntax)
|
self.newPreferencesReady.emit(needsRestart, refreshTree, updateTheme, updateSyntax)
|
||||||
|
|
||||||
|
self.close()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -281,13 +281,28 @@ class NColourLabel(QLabel):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def setTextColors(self, *, color: QColor | None = None, faded: QColor | None = None) -> None:
|
||||||
|
"""Set or update the text colours."""
|
||||||
|
self._color = color or self._color
|
||||||
|
self._faded = faded or self._faded
|
||||||
|
self._refeshTextColor()
|
||||||
|
return
|
||||||
|
|
||||||
def setColorState(self, state: bool) -> None:
|
def setColorState(self, state: bool) -> None:
|
||||||
"""Change the colour state."""
|
"""Change the colour state."""
|
||||||
if self._state is not state:
|
if self._state is not state:
|
||||||
self._state = state
|
self._state = state
|
||||||
colour = self.palette()
|
self._refeshTextColor()
|
||||||
colour.setColor(QPalette.ColorRole.WindowText, self._color if state else self._faded)
|
return
|
||||||
self.setPalette(colour)
|
|
||||||
|
def _refeshTextColor(self) -> None:
|
||||||
|
"""Refresh the colour of the text on the label."""
|
||||||
|
palette = self.palette()
|
||||||
|
palette.setColor(
|
||||||
|
QPalette.ColorRole.WindowText,
|
||||||
|
self._color if self._state else self._faded,
|
||||||
|
)
|
||||||
|
self.setPalette(palette)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2919,10 +2919,10 @@ class GuiDocEditHeader(QWidget):
|
|||||||
palette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack)
|
palette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack)
|
||||||
palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText)
|
palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText)
|
||||||
palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
|
palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
|
||||||
|
|
||||||
self.setPalette(palette)
|
self.setPalette(palette)
|
||||||
self.itemTitle.setPalette(palette)
|
self.itemTitle.setTextColors(
|
||||||
|
color=palette.windowText().color(), faded=SHARED.theme.fadedText
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
def changeFocusState(self, state: bool) -> None:
|
def changeFocusState(self, state: bool) -> None:
|
||||||
|
|||||||
@@ -741,7 +741,9 @@ class GuiDocViewHeader(QWidget):
|
|||||||
palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText)
|
palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText)
|
||||||
palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
|
palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
|
||||||
self.setPalette(palette)
|
self.setPalette(palette)
|
||||||
self.itemTitle.setPalette(palette)
|
self.itemTitle.setTextColors(
|
||||||
|
color=palette.windowText().color(), faded=SHARED.theme.fadedText
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
def changeFocusState(self, state: bool) -> None:
|
def changeFocusState(self, state: bool) -> None:
|
||||||
|
|||||||
@@ -268,6 +268,7 @@ class GuiOutlineToolBar(QToolBar):
|
|||||||
self.aExport.setIcon(SHARED.theme.getIcon("export"))
|
self.aExport.setIcon(SHARED.theme.getIcon("export"))
|
||||||
self.tbColumns.setIcon(SHARED.theme.getIcon("menu"))
|
self.tbColumns.setIcon(SHARED.theme.getIcon("menu"))
|
||||||
self.tbColumns.setStyleSheet("QToolButton::menu-indicator {image: none;}")
|
self.tbColumns.setStyleSheet("QToolButton::menu-indicator {image: none;}")
|
||||||
|
self.novelLabel.setTextColors(color=self.palette().windowText().color())
|
||||||
return
|
return
|
||||||
|
|
||||||
def populateNovelList(self) -> None:
|
def populateNovelList(self) -> None:
|
||||||
|
|||||||
+30
-14
@@ -1006,32 +1006,48 @@ class GuiMain(QMainWindow):
|
|||||||
def _switchFocus(self, paneNo: nwFocus) -> None:
|
def _switchFocus(self, paneNo: nwFocus) -> None:
|
||||||
"""Switch focus between main GUI views."""
|
"""Switch focus between main GUI views."""
|
||||||
if paneNo == nwFocus.TREE:
|
if paneNo == nwFocus.TREE:
|
||||||
if self.projStack.currentWidget() is self.projView:
|
# Decision Matrix
|
||||||
if self.projView.treeHasFocus():
|
# vM | vP | fP | vN | fN | Focus
|
||||||
self._changeView(nwView.NOVEL)
|
# ----|----|----|----|----|---------
|
||||||
self.novelView.setTreeFocus()
|
# T | T | T | F | F | Novel
|
||||||
else:
|
# T | T | F | F | F | Project
|
||||||
self.projView.setTreeFocus()
|
# T | F | F | T | T | Project
|
||||||
elif self.projStack.currentWidget() is self.novelView:
|
# T | F | F | T | F | Novel
|
||||||
if self.novelView.treeHasFocus():
|
# T | F | F | F | F | Project
|
||||||
self._changeView(nwView.PROJECT)
|
# F | T | T | F | F | Project
|
||||||
self.projView.setTreeFocus()
|
# F | T | F | F | F | Project
|
||||||
else:
|
# F | F | F | T | T | Novel
|
||||||
self.novelView.setTreeFocus()
|
# F | F | F | T | F | Novel
|
||||||
|
# F | F | F | F | F | Project
|
||||||
|
|
||||||
|
vM = self.mainStack.currentWidget() is self.splitMain
|
||||||
|
vP = self.projStack.currentWidget() is self.projView
|
||||||
|
vN = self.projStack.currentWidget() is self.novelView
|
||||||
|
fP = self.projView.treeHasFocus()
|
||||||
|
fN = self.novelView.treeHasFocus()
|
||||||
|
|
||||||
|
self._changeView(nwView.EDITOR)
|
||||||
|
if (vM and (vP and fP or vN and not fN)) or (not vM and vN):
|
||||||
|
self._changeView(nwView.NOVEL)
|
||||||
|
self.novelView.setTreeFocus()
|
||||||
else:
|
else:
|
||||||
self._changeView(nwView.PROJECT)
|
self._changeView(nwView.PROJECT)
|
||||||
self.projView.setTreeFocus()
|
self.projView.setTreeFocus()
|
||||||
|
|
||||||
elif paneNo == nwFocus.DOCUMENT:
|
elif paneNo == nwFocus.DOCUMENT:
|
||||||
self._changeView(nwView.EDITOR)
|
self._changeView(nwView.EDITOR)
|
||||||
if self.docEditor.anyFocus():
|
hasViewer = self.splitView.isVisible()
|
||||||
|
if hasViewer and self.docEditor.anyFocus():
|
||||||
self.docViewer.setFocus()
|
self.docViewer.setFocus()
|
||||||
elif self.docViewer.anyFocus():
|
elif hasViewer and self.docViewer.anyFocus():
|
||||||
self.docEditor.setFocus()
|
self.docEditor.setFocus()
|
||||||
else:
|
else:
|
||||||
self.docEditor.setFocus()
|
self.docEditor.setFocus()
|
||||||
|
|
||||||
elif paneNo == nwFocus.OUTLINE:
|
elif paneNo == nwFocus.OUTLINE:
|
||||||
self._changeView(nwView.OUTLINE)
|
self._changeView(nwView.OUTLINE)
|
||||||
self.outlineView.setTreeFocus()
|
self.outlineView.setTreeFocus()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot(bool, bool, bool, bool)
|
@pyqtSlot(bool, bool, bool, bool)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ from novelwriter import CONFIG, SHARED
|
|||||||
from novelwriter.constants import nwUnicode
|
from novelwriter.constants import nwUnicode
|
||||||
from novelwriter.dialogs.preferences import GuiPreferences
|
from novelwriter.dialogs.preferences import GuiPreferences
|
||||||
from novelwriter.dialogs.quotes import GuiQuoteSelect
|
from novelwriter.dialogs.quotes import GuiQuoteSelect
|
||||||
from novelwriter.types import QtDialogApply, QtDialogClose, QtDialogSave, QtModNone
|
from novelwriter.types import QtDialogCancel, QtDialogSave, QtModNone
|
||||||
|
|
||||||
KEY_DELAY = 1
|
KEY_DELAY = 1
|
||||||
|
|
||||||
@@ -92,7 +92,8 @@ def testDlgPreferences_Actions(qtbot, monkeypatch, nwGUI):
|
|||||||
"""Test the preferences dialog actions."""
|
"""Test the preferences dialog actions."""
|
||||||
monkeypatch.setattr(SHARED._spelling, "listDictionaries", lambda: [("en", "English [en]")])
|
monkeypatch.setattr(SHARED._spelling, "listDictionaries", lambda: [("en", "English [en]")])
|
||||||
prefs = GuiPreferences(nwGUI)
|
prefs = GuiPreferences(nwGUI)
|
||||||
prefs.show()
|
with qtbot.waitExposed(prefs):
|
||||||
|
prefs.show()
|
||||||
|
|
||||||
# Check Navigation
|
# Check Navigation
|
||||||
vBar = prefs.mainForm.verticalScrollBar()
|
vBar = prefs.mainForm.verticalScrollBar()
|
||||||
@@ -116,12 +117,6 @@ def testDlgPreferences_Actions(qtbot, monkeypatch, nwGUI):
|
|||||||
prefs._gotoSearch()
|
prefs._gotoSearch()
|
||||||
assert value.args[0] < old
|
assert value.args[0] < old
|
||||||
|
|
||||||
# Check Apply Button
|
|
||||||
prefs.show()
|
|
||||||
with qtbot.waitSignal(prefs.newPreferencesReady) as signal:
|
|
||||||
prefs.buttonBox.button(QtDialogApply).click()
|
|
||||||
assert signal.args == [False, False, False, False]
|
|
||||||
|
|
||||||
# Check Save Button
|
# Check Save Button
|
||||||
prefs.show()
|
prefs.show()
|
||||||
with qtbot.waitSignal(prefs.newPreferencesReady) as signal:
|
with qtbot.waitSignal(prefs.newPreferencesReady) as signal:
|
||||||
@@ -130,7 +125,7 @@ def testDlgPreferences_Actions(qtbot, monkeypatch, nwGUI):
|
|||||||
|
|
||||||
# Check Close Button
|
# Check Close Button
|
||||||
prefs.show()
|
prefs.show()
|
||||||
prefs.buttonBox.button(QtDialogClose).click()
|
prefs.buttonBox.button(QtDialogCancel).click()
|
||||||
assert prefs.isHidden() is True
|
assert prefs.isHidden() is True
|
||||||
|
|
||||||
# Close Using Escape Key
|
# Close Using Escape Key
|
||||||
@@ -152,7 +147,8 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
|
|||||||
monkeypatch.setattr(CONFIG, "listLanguages", lambda *a: languages)
|
monkeypatch.setattr(CONFIG, "listLanguages", lambda *a: languages)
|
||||||
|
|
||||||
prefs = GuiPreferences(nwGUI)
|
prefs = GuiPreferences(nwGUI)
|
||||||
prefs.show()
|
with qtbot.waitExposed(prefs):
|
||||||
|
prefs.show()
|
||||||
|
|
||||||
# Appearance
|
# Appearance
|
||||||
prefs.guiLocale.setCurrentIndex(prefs.guiLocale.findData("en_US"))
|
prefs.guiLocale.setCurrentIndex(prefs.guiLocale.findData("en_US"))
|
||||||
@@ -315,7 +311,7 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
|
|||||||
with monkeypatch.context() as mp:
|
with monkeypatch.context() as mp:
|
||||||
mp.setattr(QFontDatabase, "families", lambda *a: ["TestFont"])
|
mp.setattr(QFontDatabase, "families", lambda *a: ["TestFont"])
|
||||||
with qtbot.waitSignal(prefs.newPreferencesReady) as signal:
|
with qtbot.waitSignal(prefs.newPreferencesReady) as signal:
|
||||||
prefs.buttonBox.button(QtDialogApply).click()
|
prefs.buttonBox.button(QtDialogSave).click()
|
||||||
assert signal.args == [True, True, True, True]
|
assert signal.args == [True, True, True, True]
|
||||||
|
|
||||||
# Check Settings
|
# Check Settings
|
||||||
|
|||||||
Reference in New Issue
Block a user