Skip to content

Commit

Permalink
Editor code cleanup, and a few other places (#2201)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo authored Jan 21, 2025
2 parents 3672ae8 + 23398f2 commit ca046d8
Show file tree
Hide file tree
Showing 24 changed files with 166 additions and 189 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
Loading

0 comments on commit ca046d8

Please sign in to comment.