Skip to content

Commit

Permalink
Use Color and Colour consistently in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Jan 21, 2025
1 parent 41a32b4 commit 23398f2
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 105 deletions.
1 change: 0 additions & 1 deletion novelwriter/core/buildsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@
}

RENAMED = {
"odt.addColours": "doc.addColours",
"odt.pageHeader": "doc.pageHeader",
"odt.pageCountOffset": "doc.pageCountOffset",
}
Expand Down
4 changes: 2 additions & 2 deletions novelwriter/dialogs/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

from novelwriter import CONFIG, SHARED
from novelwriter.common import cssCol, readTextFile
from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.configlayout import NColorLabel
from novelwriter.extensions.modified import NDialog
from novelwriter.extensions.versioninfo import VersionInfoWidget
from novelwriter.types import QtAlignRightTop, QtDialogClose
Expand Down Expand Up @@ -68,7 +68,7 @@ def __init__(self, parent: QWidget) -> None:
self.nwLicence.setOpenExternalLinks(True)

# Credits
self.lblCredits = NColourLabel(
self.lblCredits = NColorLabel(
self.tr("Credits"), self, scale=1.6, bold=True
)

Expand Down
4 changes: 2 additions & 2 deletions novelwriter/dialogs/docmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
)

from novelwriter import SHARED
from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.configlayout import NColorLabel
from novelwriter.extensions.modified import NDialog
from novelwriter.extensions.switch import NSwitch
from novelwriter.types import QtAccepted, QtDialogCancel, QtDialogOk, QtDialogReset, QtUserRole
Expand All @@ -56,7 +56,7 @@ def __init__(self, parent: QWidget, sHandle: str, itemList: list[str]) -> None:

self.headLabel = QLabel(self.tr("Documents to Merge"), self)
self.headLabel.setFont(SHARED.theme.guiFontB)
self.helpLabel = NColourLabel(
self.helpLabel = NColorLabel(
self.tr("Drag and drop items to change the order, or uncheck to exclude."),
self, color=SHARED.theme.helpText, wrap=True
)
Expand Down
4 changes: 2 additions & 2 deletions novelwriter/dialogs/docsplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
)

from novelwriter import SHARED
from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.configlayout import NColorLabel
from novelwriter.extensions.modified import NDialog
from novelwriter.extensions.switch import NSwitch
from novelwriter.types import QtAccepted, QtDialogCancel, QtDialogOk, QtUserRole
Expand All @@ -60,7 +60,7 @@ def __init__(self, parent: QWidget, sHandle: str) -> None:

self.headLabel = QLabel(self.tr("Document Headings"), self)
self.headLabel.setFont(SHARED.theme.guiFontB)
self.helpLabel = NColourLabel(
self.helpLabel = NColorLabel(
self.tr("Select the maximum level to split into files."),
self, color=SHARED.theme.helpText, wrap=True
)
Expand Down
6 changes: 3 additions & 3 deletions novelwriter/dialogs/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from novelwriter.config import DEF_GUI, DEF_ICONS, DEF_SYNTAX, DEF_TREECOL
from novelwriter.constants import nwLabels, nwUnicode, trConst
from novelwriter.dialogs.quotes import GuiQuoteSelect
from novelwriter.extensions.configlayout import NColourLabel, NScrollableForm
from novelwriter.extensions.configlayout import NColorLabel, NScrollableForm
from novelwriter.extensions.modified import (
NComboBox, NDialog, NDoubleSpinBox, NIconToolButton, NSpinBox
)
Expand All @@ -63,9 +63,9 @@ def __init__(self, parent: QWidget) -> None:
self.resize(*CONFIG.prefsWinSize)

# Title
self.titleLabel = NColourLabel(
self.titleLabel = NColorLabel(
self.tr("Preferences"), self, color=SHARED.theme.helpText,
scale=NColourLabel.HEADER_SCALE, indent=4,
scale=NColorLabel.HEADER_SCALE, indent=4,
)

# Search Box
Expand Down
18 changes: 9 additions & 9 deletions novelwriter/dialogs/projectsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from novelwriter.constants import nwLabels, trConst
from novelwriter.core.status import NWStatus, StatusEntry
from novelwriter.enum import nwStatusShape
from novelwriter.extensions.configlayout import NColourLabel, NFixedPage, NScrollableForm
from novelwriter.extensions.configlayout import NColorLabel, NFixedPage, NScrollableForm
from novelwriter.extensions.modified import NComboBox, NDialog, NIconToolButton
from novelwriter.extensions.pagedsidebar import NPagedSideBar
from novelwriter.extensions.switch import NSwitch
Expand Down Expand Up @@ -78,9 +78,9 @@ def __init__(self, parent: QWidget, gotoPage: int = PAGE_SETTINGS) -> None:
)

# Title
self.titleLabel = NColourLabel(
self.titleLabel = NColorLabel(
self.tr("Project Settings"), self, color=SHARED.theme.helpText,
scale=NColourLabel.HEADER_SCALE, indent=4,
scale=NColorLabel.HEADER_SCALE, indent=4,
)

# SideBar
Expand Down Expand Up @@ -339,9 +339,9 @@ def __init__(self, parent: QWidget, isStatus: bool) -> None:
self.trSelColor = self.tr("Select Colour")

# Title
self.pageTitle = NColourLabel(
self.pageTitle = NColorLabel(
pageLabel, self, color=SHARED.theme.helpText,
scale=NColourLabel.HEADER_SCALE
scale=NColorLabel.HEADER_SCALE
)

# List Box
Expand Down Expand Up @@ -398,7 +398,7 @@ def __init__(self, parent: QWidget, isStatus: bool) -> None:
self.colorButton.setSizePolicy(QtSizeMinimum, QtSizeMinimumExpanding)
self.colorButton.setStyleSheet(buttonStyle)
self.colorButton.setEnabled(False)
self.colorButton.clicked.connect(self._onColourSelect)
self.colorButton.clicked.connect(self._onColorSelect)

def buildMenu(menu: QMenu | None, items: dict[nwStatusShape, str]) -> None:
if menu is not None:
Expand Down Expand Up @@ -494,7 +494,7 @@ def _onNameEdit(self, text: str) -> None:
return

@pyqtSlot()
def _onColourSelect(self) -> None:
def _onColorSelect(self) -> None:
"""Open a dialog to select the status icon colour."""
if (color := QColorDialog.getColor(self._color, self, self.trSelColor)).isValid():
self._color = color
Expand Down Expand Up @@ -675,9 +675,9 @@ def __init__(self, parent: QWidget) -> None:
wCol0 = SHARED.project.options.getInt("GuiProjectSettings", "replaceColW", 130)

# Title
self.pageTitle = NColourLabel(
self.pageTitle = NColorLabel(
self.tr("Text Auto-Replace for Preview and Build"), self,
color=SHARED.theme.helpText, scale=NColourLabel.HEADER_SCALE
color=SHARED.theme.helpText, scale=NColorLabel.HEADER_SCALE
)

# List Box
Expand Down
6 changes: 3 additions & 3 deletions novelwriter/dialogs/wordlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from novelwriter import CONFIG, SHARED
from novelwriter.common import formatFileFilter
from novelwriter.core.spellcheck import UserDictionary
from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.configlayout import NColorLabel
from novelwriter.extensions.modified import NDialog, NIconToolButton
from novelwriter.types import QtDialogClose, QtDialogSave

Expand Down Expand Up @@ -65,9 +65,9 @@ def __init__(self, parent: QWidget) -> None:
)

# Header
self.headLabel = NColourLabel(
self.headLabel = NColorLabel(
self.tr("Project Word List"), self, color=SHARED.theme.helpText,
scale=NColourLabel.HEADER_SCALE
scale=NColorLabel.HEADER_SCALE
)

self.importButton = NIconToolButton(self, iSz, "import", "green")
Expand Down
6 changes: 3 additions & 3 deletions novelwriter/extensions/configlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, parent: QWidget) -> None:
self._indent = 12

self._sections: dict[int, QLabel] = {}
self._editable: dict[str, NColourLabel] = {}
self._editable: dict[str, NColorLabel] = {}
self._index: dict[str, QWidget] = {}

self._layout = QVBoxLayout()
Expand Down Expand Up @@ -216,7 +216,7 @@ def addRow(
qLabel.setBuddy(qWidget)

if helpText:
qHelp = NColourLabel(
qHelp = NColorLabel(
str(helpText), self, color=self._helpCol,
scale=self._fontScale, wrap=True, indent=self._indent
)
Expand Down Expand Up @@ -257,7 +257,7 @@ def finalise(self) -> None:
return


class NColourLabel(QLabel):
class NColorLabel(QLabel):
"""Extension: A Coloured Label
A custom widget that draws a label in a specific colour, and
Expand Down
8 changes: 5 additions & 3 deletions novelwriter/extensions/progressbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, parent: QWidget, size: int, point: int) -> None:
self._cRect = QRect(point, point, size - 2*point, size - 2*point)
self._dPen = QPen(QtTransparent)
self._dBrush = QBrush(QtTransparent)
self.setColours(
self.setColors(
track=self.palette().alternateBase().color(),
bar=self.palette().highlight().color(),
text=self.palette().text().color()
Expand All @@ -66,8 +66,10 @@ def __init__(self, parent: QWidget, size: int, point: int) -> None:
self.setFixedHeight(size)
return

def setColours(self, back: QColor | None = None, track: QColor | None = None,
bar: QColor | None = None, text: QColor | None = None) -> None:
def setColors(
self, back: QColor | None = None, track: QColor | None = None,
bar: QColor | None = None, text: QColor | None = None
) -> None:
"""Set the colours of the widget."""
if isinstance(back, QColor):
self._dPen = QPen(back)
Expand Down
10 changes: 5 additions & 5 deletions novelwriter/gui/doceditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
nwChange, nwComment, nwDocAction, nwDocInsert, nwDocMode, nwItemClass,
nwItemType, nwTrinary
)
from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.configlayout import NColorLabel
from novelwriter.extensions.eventfilters import WheelEventFilter
from novelwriter.extensions.modified import NIconToggleButton, NIconToolButton
from novelwriter.gui.dochighlight import BLOCK_META, BLOCK_TITLE
Expand Down Expand Up @@ -303,7 +303,7 @@ def updateSyntaxColors(self) -> None:
palette.setColor(QPalette.ColorRole.Text, syntax.text)
viewport.setPalette(palette)

self.docHeader.matchColours()
self.docHeader.matchColors()
self.docFooter.matchColors()

return
Expand Down Expand Up @@ -2833,7 +2833,7 @@ def __init__(self, docEditor: GuiDocEditor) -> None:
self.setAutoFillBackground(True)

# Title Label
self.itemTitle = NColourLabel("", self, faded=SHARED.theme.fadedText)
self.itemTitle = NColorLabel("", self, faded=SHARED.theme.fadedText)
self.itemTitle.setMargin(0)
self.itemTitle.setContentsMargins(0, 0, 0, 0)
self.itemTitle.setAutoFillBackground(True)
Expand Down Expand Up @@ -2951,11 +2951,11 @@ def updateTheme(self) -> None:
self.minmaxButton.setStyleSheet(buttonStyle)
self.closeButton.setStyleSheet(buttonStyle)

self.matchColours()
self.matchColors()

return

def matchColours(self) -> None:
def matchColors(self) -> None:
"""Update the colours of the widget to match those of the syntax
theme rather than the main GUI.
"""
Expand Down
16 changes: 8 additions & 8 deletions novelwriter/gui/docviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from novelwriter.constants import nwConst, nwStyles, nwUnicode
from novelwriter.enum import nwChange, nwDocAction, nwDocMode, nwItemType
from novelwriter.error import logException
from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.configlayout import NColorLabel
from novelwriter.extensions.eventfilters import WheelEventFilter
from novelwriter.extensions.modified import NIconToolButton
from novelwriter.formats.shared import TextDocumentTheme
Expand Down Expand Up @@ -167,8 +167,8 @@ def initViewer(self) -> None:
palette.setColor(QPalette.ColorRole.Base, syntax.back)
palette.setColor(QPalette.ColorRole.Text, syntax.text)
viewport.setPalette(palette)
self.docHeader.matchColours()
self.docFooter.matchColours()
self.docHeader.matchColors()
self.docFooter.matchColors()

# Update theme colours
self._docTheme.text = syntax.text
Expand Down Expand Up @@ -644,7 +644,7 @@ def __init__(self, docViewer: GuiDocViewer) -> None:
self.setAutoFillBackground(True)

# Title Label
self.itemTitle = NColourLabel("", self, faded=SHARED.theme.fadedText)
self.itemTitle = NColorLabel("", self, faded=SHARED.theme.fadedText)
self.itemTitle.setMargin(0)
self.itemTitle.setContentsMargins(0, 0, 0, 0)
self.itemTitle.setAutoFillBackground(True)
Expand Down Expand Up @@ -775,11 +775,11 @@ def updateTheme(self) -> None:
self.refreshButton.setStyleSheet(buttonStyle)
self.closeButton.setStyleSheet(buttonStyle)

self.matchColours()
self.matchColors()

return

def matchColours(self) -> None:
def matchColors(self) -> None:
"""Update the colours of the widget to match those of the syntax
theme rather than the main GUI.
"""
Expand Down Expand Up @@ -961,11 +961,11 @@ def updateTheme(self) -> None:
self.showComments.setStyleSheet(buttonStyle)
self.showSynopsis.setStyleSheet(buttonStyle)

self.matchColours()
self.matchColors()

return

def matchColours(self) -> None:
def matchColors(self) -> None:
"""Update the colours of the widget to match those of the syntax
theme rather than the main GUI.
"""
Expand Down
6 changes: 3 additions & 3 deletions novelwriter/gui/outline.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from novelwriter.constants import nwKeyWords, nwLabels, nwStats, nwStyles, trConst
from novelwriter.enum import nwChange, nwDocMode, nwItemClass, nwItemLayout, nwItemType, nwOutline
from novelwriter.error import logException
from novelwriter.extensions.configlayout import NColourLabel
from novelwriter.extensions.configlayout import NColorLabel
from novelwriter.extensions.novelselector import NovelSelector
from novelwriter.types import (
QtAlignLeftTop, QtAlignRight, QtAlignRightTop, QtDecoration,
Expand Down Expand Up @@ -222,8 +222,8 @@ def __init__(self, outlineView: GuiOutlineView) -> None:
stretch.setSizePolicy(QtSizeExpanding, QtSizeExpanding)

# Novel Selector
self.novelLabel = NColourLabel(
self.tr("Outline of"), self, scale=NColourLabel.HEADER_SCALE, bold=True
self.novelLabel = NColorLabel(
self.tr("Outline of"), self, scale=NColorLabel.HEADER_SCALE, bold=True
)
self.novelLabel.setContentsMargins(0, 0, 12, 0)

Expand Down
Loading

0 comments on commit 23398f2

Please sign in to comment.