Remove redundant cssCol helper
This commit is contained in:
@@ -38,7 +38,7 @@ from urllib.parse import urljoin
|
||||
from urllib.request import pathname2url
|
||||
|
||||
from PyQt6.QtCore import QCoreApplication, QMimeData, QUrl
|
||||
from PyQt6.QtGui import QAction, QColor, QDesktopServices, QFont, QFontDatabase, QFontInfo
|
||||
from PyQt6.QtGui import QAction, QDesktopServices, QFont, QFontDatabase, QFontInfo
|
||||
from PyQt6.QtWidgets import QMenu, QMenuBar, QWidget
|
||||
|
||||
from novelwriter.constants import nwConst, nwLabels, nwUnicode, trConst
|
||||
@@ -417,11 +417,6 @@ def numberToRoman(value: int, toLower: bool = False) -> str:
|
||||
# Qt Helpers
|
||||
##
|
||||
|
||||
def cssCol(col: QColor, alpha: int | None = None) -> str:
|
||||
"""Convert a QColor object to an rgba entry to use in CSS."""
|
||||
return f"rgba({col.red()}, {col.green()}, {col.blue()}, {alpha or col.alpha()})"
|
||||
|
||||
|
||||
def describeFont(font: QFont) -> str:
|
||||
"""Describe a font in a way that can be displayed on the GUI."""
|
||||
if isinstance(font, QFont):
|
||||
|
||||
@@ -31,11 +31,11 @@ from PyQt6.QtWidgets import (
|
||||
)
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.common import cssCol, readTextFile
|
||||
from novelwriter.common import readTextFile
|
||||
from novelwriter.extensions.configlayout import NColorLabel
|
||||
from novelwriter.extensions.modified import NDialog
|
||||
from novelwriter.extensions.versioninfo import VersionInfoWidget
|
||||
from novelwriter.types import QtAlignRightTop, QtDialogClose
|
||||
from novelwriter.types import QtAlignRightTop, QtDialogClose, QtHexArgb
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -135,7 +135,7 @@ class GuiAbout(NDialog):
|
||||
|
||||
def _setStyleSheet(self) -> None:
|
||||
"""Set stylesheet text document."""
|
||||
baseCol = cssCol(self.palette().window().color())
|
||||
baseCol = self.palette().window().color().name(QtHexArgb)
|
||||
self.txtCredits.setStyleSheet(
|
||||
f"QTextBrowser {{border: none; background: {baseCol};}} "
|
||||
)
|
||||
|
||||
@@ -37,12 +37,12 @@ from PyQt6.QtGui import (
|
||||
from PyQt6.QtWidgets import QApplication
|
||||
|
||||
from novelwriter import CONFIG
|
||||
from novelwriter.common import NWConfigParser, cssCol, minmax
|
||||
from novelwriter.common import NWConfigParser, minmax
|
||||
from novelwriter.config import DEF_GUI, DEF_ICONS, DEF_SYNTAX
|
||||
from novelwriter.constants import nwLabels
|
||||
from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType
|
||||
from novelwriter.error import logException
|
||||
from novelwriter.types import QtBlack, QtPaintAntiAlias, QtTransparent
|
||||
from novelwriter.types import QtBlack, QtHexArgb, QtPaintAntiAlias, QtTransparent
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -528,27 +528,29 @@ class GuiTheme:
|
||||
"""Build default style sheets."""
|
||||
self._styleSheets = {}
|
||||
|
||||
tCol = palette.text().color()
|
||||
hCol = palette.highlight().color()
|
||||
text = palette.text().color()
|
||||
text.setAlpha(48)
|
||||
tCol = text.name(QtHexArgb)
|
||||
hCol = palette.highlight().color().name(QtHexArgb)
|
||||
|
||||
# Flat Tab Widget and Tab Bar:
|
||||
self._styleSheets[STYLES_FLAT_TABS] = (
|
||||
"QTabWidget::pane {border: 0;} "
|
||||
"QTabWidget QTabBar::tab {border: 0; padding: 4px 8px;} "
|
||||
f"QTabWidget QTabBar::tab:selected {{color: {cssCol(hCol)};}} "
|
||||
f"QTabWidget QTabBar::tab:selected {{color: {hCol};}} "
|
||||
)
|
||||
|
||||
# Minimal Tool Button
|
||||
self._styleSheets[STYLES_MIN_TOOLBUTTON] = (
|
||||
"QToolButton {padding: 2px; margin: 0; border: none; background: transparent;} "
|
||||
f"QToolButton:hover {{border: none; background: {cssCol(tCol, 48)};}} "
|
||||
f"QToolButton:hover {{border: none; background: {tCol};}} "
|
||||
"QToolButton::menu-indicator {image: none;} "
|
||||
)
|
||||
|
||||
# Big Tool Button
|
||||
self._styleSheets[STYLES_BIG_TOOLBUTTON] = (
|
||||
"QToolButton {padding: 6px; margin: 0; border: none; background: transparent;} "
|
||||
f"QToolButton:hover {{border: none; background: {cssCol(tCol, 48)};}} "
|
||||
f"QToolButton:hover {{border: none; background: {tCol};}} "
|
||||
"QToolButton::menu-indicator {image: none;} "
|
||||
)
|
||||
|
||||
|
||||
@@ -36,10 +36,10 @@ from PyQt6.QtWidgets import (
|
||||
)
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.common import cssCol, formatFileFilter, formatInt, getFileSize, openExternalPath
|
||||
from novelwriter.common import formatFileFilter, formatInt, getFileSize, openExternalPath
|
||||
from novelwriter.error import formatException
|
||||
from novelwriter.extensions.modified import NIconToolButton, NNonBlockingDialog
|
||||
from novelwriter.types import QtDialogClose
|
||||
from novelwriter.types import QtDialogClose, QtHexArgb
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -101,7 +101,6 @@ class GuiDictionaries(NNonBlockingDialog):
|
||||
# Info Box
|
||||
self.infoBox = QPlainTextEdit(self)
|
||||
self.infoBox.setReadOnly(True)
|
||||
self.infoBox.setFixedHeight(4*SHARED.theme.fontPixelSize)
|
||||
self.infoBox.setFrameStyle(QFrame.Shape.NoFrame)
|
||||
|
||||
# Buttons
|
||||
@@ -109,21 +108,16 @@ class GuiDictionaries(NNonBlockingDialog):
|
||||
self.buttonBox.rejected.connect(self.reject)
|
||||
|
||||
# Assemble
|
||||
self.innerBox = QVBoxLayout()
|
||||
self.innerBox.addWidget(self.huInfo)
|
||||
self.innerBox.addLayout(self.huPathBox)
|
||||
self.innerBox.addLayout(self.huAddBox)
|
||||
self.innerBox.addSpacing(8)
|
||||
self.innerBox.addWidget(self.inInfo)
|
||||
self.innerBox.addLayout(self.inBox)
|
||||
self.innerBox.addWidget(self.infoBox)
|
||||
self.innerBox.setSpacing(4)
|
||||
|
||||
self.outerBox = QVBoxLayout()
|
||||
self.outerBox.addLayout(self.innerBox, 0)
|
||||
self.outerBox.addStretch(1)
|
||||
self.outerBox.addWidget(self.huInfo, 0)
|
||||
self.outerBox.addLayout(self.huPathBox, 0)
|
||||
self.outerBox.addLayout(self.huAddBox, 0)
|
||||
self.outerBox.addSpacing(8)
|
||||
self.outerBox.addWidget(self.inInfo, 0)
|
||||
self.outerBox.addLayout(self.inBox, 0)
|
||||
self.outerBox.addWidget(self.infoBox, 1)
|
||||
self.outerBox.addSpacing(8)
|
||||
self.outerBox.addWidget(self.buttonBox, 0)
|
||||
self.outerBox.setSpacing(16)
|
||||
|
||||
self.setLayout(self.outerBox)
|
||||
|
||||
@@ -248,8 +242,8 @@ class GuiDictionaries(NNonBlockingDialog):
|
||||
cursor.movePosition(QTextCursor.MoveOperation.End)
|
||||
if cursor.position() > 0:
|
||||
cursor.insertText("\n")
|
||||
textCol = cssCol(SHARED.theme.errorText if err else self.palette().text().color())
|
||||
cursor.insertHtml(f"<font style='color: {textCol}'>{text}</font>")
|
||||
textCol = SHARED.theme.errorText if err else self.palette().text().color()
|
||||
cursor.insertHtml(f"<font style='color: {textCol.name(QtHexArgb)}'>{text}</font>")
|
||||
cursor.movePosition(QTextCursor.MoveOperation.End)
|
||||
cursor.deleteChar()
|
||||
self.infoBox.setTextCursor(cursor)
|
||||
|
||||
@@ -40,7 +40,7 @@ from PyQt6.QtWidgets import (
|
||||
)
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.common import cssCol, formatInt, makeFileNameSafe, qtAddAction, qtLambda
|
||||
from novelwriter.common import formatInt, makeFileNameSafe, qtAddAction, qtLambda
|
||||
from novelwriter.constants import nwFiles
|
||||
from novelwriter.core.coretools import ProjectBuilder
|
||||
from novelwriter.enum import nwItemClass
|
||||
@@ -48,7 +48,7 @@ from novelwriter.extensions.configlayout import NWrappedWidgetBox
|
||||
from novelwriter.extensions.modified import NDialog, NIconToolButton, NSpinBox
|
||||
from novelwriter.extensions.switch import NSwitch
|
||||
from novelwriter.extensions.versioninfo import VersionInfoWidget
|
||||
from novelwriter.types import QtAlignLeft, QtAlignRightTop, QtScrollAsNeeded, QtSelected
|
||||
from novelwriter.types import QtAlignLeft, QtAlignRightTop, QtHexArgb, QtScrollAsNeeded, QtSelected
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -301,7 +301,9 @@ class _OpenProjectPage(QWidget):
|
||||
|
||||
self._selectFirstItem()
|
||||
|
||||
baseCol = cssCol(self.palette().base().color(), PANEL_ALPHA)
|
||||
base = self.palette().base().color()
|
||||
base.setAlpha(PANEL_ALPHA)
|
||||
baseCol = base.name(QtHexArgb)
|
||||
self.setStyleSheet(
|
||||
f"QListView {{border: none; background: {baseCol};}} "
|
||||
f"QLineEdit {{border: none; background: {baseCol}; padding: 4px;}} "
|
||||
@@ -507,7 +509,9 @@ class _NewProjectPage(QWidget):
|
||||
# Styles
|
||||
# ======
|
||||
|
||||
baseCol = cssCol(self.palette().base().color(), PANEL_ALPHA)
|
||||
base = self.palette().base().color()
|
||||
base.setAlpha(PANEL_ALPHA)
|
||||
baseCol = base.name(QtHexArgb)
|
||||
self.setStyleSheet(
|
||||
f"QScrollArea {{border: none; background: {baseCol};}} "
|
||||
f"_NewProjectForm {{border: none; background: {baseCol};}} "
|
||||
|
||||
@@ -28,18 +28,17 @@ from xml.etree import ElementTree as ET
|
||||
import pytest
|
||||
|
||||
from PyQt6.QtCore import QMimeData, QUrl
|
||||
from PyQt6.QtGui import QColor, QDesktopServices, QFont, QFontDatabase, QFontInfo
|
||||
from PyQt6.QtGui import QDesktopServices, QFont, QFontDatabase, QFontInfo
|
||||
|
||||
from novelwriter.common import (
|
||||
NWConfigParser, checkBool, checkFloat, checkInt, checkIntTuple, checkPath,
|
||||
checkString, checkStringNone, checkUuid, compact, cssCol,
|
||||
decodeMimeHandles, describeFont, elide, encodeMimeHandles, firstFloat,
|
||||
fontMatcher, formatFileFilter, formatInt, formatTime, formatTimeStamp,
|
||||
formatVersion, fuzzyTime, getFileSize, hexToInt, isHandle, isItemClass,
|
||||
isItemLayout, isItemType, isListInstance, isTitleTag, jsonEncode,
|
||||
makeFileNameSafe, minmax, numberToRoman, openExternalPath, readTextFile,
|
||||
simplified, transferCase, uniqueCompact, xmlElement, xmlIndent, xmlSubElem,
|
||||
yesNo
|
||||
checkString, checkStringNone, checkUuid, compact, decodeMimeHandles,
|
||||
describeFont, elide, encodeMimeHandles, firstFloat, fontMatcher,
|
||||
formatFileFilter, formatInt, formatTime, formatTimeStamp, formatVersion,
|
||||
fuzzyTime, getFileSize, hexToInt, isHandle, isItemClass, isItemLayout,
|
||||
isItemType, isListInstance, isTitleTag, jsonEncode, makeFileNameSafe,
|
||||
minmax, numberToRoman, openExternalPath, readTextFile, simplified,
|
||||
transferCase, uniqueCompact, xmlElement, xmlIndent, xmlSubElem, yesNo
|
||||
)
|
||||
|
||||
from tests.mocked import causeOSError
|
||||
@@ -512,13 +511,6 @@ def testBaseCommon_numberToRoman():
|
||||
assert numberToRoman(999, True) == "cmxcix"
|
||||
|
||||
|
||||
@pytest.mark.base
|
||||
def testBaseCommon_cssCol():
|
||||
"""Test the cssCol function."""
|
||||
assert cssCol(QColor(0, 0, 0, 0)) == "rgba(0, 0, 0, 0)"
|
||||
assert cssCol(QColor(10, 20, 30, 40)) == "rgba(10, 20, 30, 40)"
|
||||
|
||||
|
||||
@pytest.mark.base
|
||||
def testBaseCommon_describeFont():
|
||||
"""Test the describeFont function."""
|
||||
|
||||
Reference in New Issue
Block a user