Skip to content

Commit

Permalink
Clean up warnings and deprecations in gui tools
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Jan 13, 2025
1 parent 5027b8d commit 7e280b2
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 323 deletions.
8 changes: 0 additions & 8 deletions novelwriter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,6 @@ def setTextFont(self, value: QFont | str | None) -> None:
# Methods
##

def pxInt(self, value: int) -> int:
"""Deprecated. Do not use."""
return value

def rpxInt(self, value: int) -> int:
"""Deprecated. Do not use."""
return value

def homePath(self) -> Path:
"""The user's home folder."""
return self._homePath
Expand Down
17 changes: 7 additions & 10 deletions novelwriter/tools/dictionaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,9 @@ def __init__(self, parent: QWidget) -> None:
self._currDicts = set()

iSz = SHARED.theme.baseIconSize
iPx = CONFIG.pxInt(4)
mPx = CONFIG.pxInt(8)
sPx = CONFIG.pxInt(16)

self.setMinimumWidth(CONFIG.pxInt(500))
self.setMinimumHeight(CONFIG.pxInt(300))
self.setMinimumWidth(500)
self.setMinimumHeight(300)

# Hunspell Dictionaries
foUrl = "https://www.freeoffice.com/en/download/dictionaries"
Expand All @@ -84,7 +81,7 @@ def __init__(self, parent: QWidget) -> None:
self.huPathBox = QHBoxLayout()
self.huPathBox.addWidget(self.huInput)
self.huPathBox.addWidget(self.huBrowse)
self.huPathBox.setSpacing(iPx)
self.huPathBox.setSpacing(4)
self.huAddBox = QHBoxLayout()
self.huAddBox.addStretch(1)
self.huAddBox.addWidget(self.huImport)
Expand All @@ -99,7 +96,7 @@ def __init__(self, parent: QWidget) -> None:
self.inBox = QHBoxLayout()
self.inBox.addWidget(self.inPath)
self.inBox.addWidget(self.inBrowse)
self.inBox.setSpacing(iPx)
self.inBox.setSpacing(4)

# Info Box
self.infoBox = QPlainTextEdit(self)
Expand All @@ -116,17 +113,17 @@ def __init__(self, parent: QWidget) -> None:
self.innerBox.addWidget(self.huInfo)
self.innerBox.addLayout(self.huPathBox)
self.innerBox.addLayout(self.huAddBox)
self.innerBox.addSpacing(mPx)
self.innerBox.addSpacing(8)
self.innerBox.addWidget(self.inInfo)
self.innerBox.addLayout(self.inBox)
self.innerBox.addWidget(self.infoBox)
self.innerBox.setSpacing(iPx)
self.innerBox.setSpacing(4)

self.outerBox = QVBoxLayout()
self.outerBox.addLayout(self.innerBox, 0)
self.outerBox.addStretch(1)
self.outerBox.addWidget(self.buttonBox, 0)
self.outerBox.setSpacing(sPx)
self.outerBox.setSpacing(16)

self.setLayout(self.outerBox)

Expand Down
21 changes: 10 additions & 11 deletions novelwriter/tools/lipsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,15 @@ def __init__(self, parent: QWidget) -> None:

self._lipsumText = ""

vSp = CONFIG.pxInt(4)
nPx = CONFIG.pxInt(64)

self.innerBox = QHBoxLayout()
self.innerBox.setSpacing(CONFIG.pxInt(16))
self.innerBox.setSpacing(16)

# Icon
self.docIcon = QLabel(self)
self.docIcon.setPixmap(SHARED.theme.getPixmap("text", (nPx, nPx), "blue"))
self.docIcon.setPixmap(SHARED.theme.getPixmap("text", (64, 64), "blue"))

self.leftBox = QVBoxLayout()
self.leftBox.setSpacing(vSp)
self.leftBox.setSpacing(4)
self.leftBox.addWidget(self.docIcon)
self.leftBox.addStretch(1)
self.innerBox.addLayout(self.leftBox)
Expand All @@ -87,7 +84,7 @@ def __init__(self, parent: QWidget) -> None:
self.formBox.addWidget(self.paraCount, 1, 1, 1, 1, QtAlignRight)
self.formBox.addWidget(self.randLabel, 2, 0, 1, 1, QtAlignLeft)
self.formBox.addWidget(self.randSwitch, 2, 1, 1, 1, QtAlignRight)
self.formBox.setVerticalSpacing(vSp)
self.formBox.setVerticalSpacing(4)
self.formBox.setRowStretch(3, 1)
self.innerBox.addLayout(self.formBox)

Expand All @@ -96,17 +93,19 @@ def __init__(self, parent: QWidget) -> None:
self.buttonBox.rejected.connect(self.reject)

self.btnClose = self.buttonBox.addButton(QtDialogClose)
self.btnClose.setAutoDefault(False)
if self.btnClose:
self.btnClose.setAutoDefault(False)

self.btnInsert = self.buttonBox.addButton(self.tr("Insert"), QtRoleAction)
self.btnInsert.clicked.connect(self._doInsert)
self.btnInsert.setAutoDefault(False)
if self.btnInsert:
self.btnInsert.clicked.connect(self._doInsert)
self.btnInsert.setAutoDefault(False)

# Assemble
self.outerBox = QVBoxLayout()
self.outerBox.addLayout(self.innerBox)
self.outerBox.addWidget(self.buttonBox)
self.outerBox.setSpacing(CONFIG.pxInt(16))
self.outerBox.setSpacing(16)
self.setLayout(self.outerBox)

logger.debug("Ready: GuiLipsum")
Expand Down
59 changes: 24 additions & 35 deletions novelwriter/tools/manusbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
QPushButton, QSplitter, QVBoxLayout, QWidget
)

from novelwriter import CONFIG, SHARED
from novelwriter import SHARED
from novelwriter.common import makeFileNameSafe, openExternalPath
from novelwriter.constants import nwLabels
from novelwriter.core.buildsettings import BuildSettings
Expand Down Expand Up @@ -68,21 +68,16 @@ def __init__(self, parent: QWidget, build: BuildSettings) -> None:
self._build = build

self.setWindowTitle(self.tr("Build Manuscript"))
self.setMinimumWidth(CONFIG.pxInt(500))
self.setMinimumHeight(CONFIG.pxInt(300))
self.setMinimumWidth(500)
self.setMinimumHeight(300)

iSz = SHARED.theme.baseIconSize
bSz = SHARED.theme.buttonIconSize
sp4 = CONFIG.pxInt(4)
sp8 = CONFIG.pxInt(8)
sp16 = CONFIG.pxInt(16)
wWin = CONFIG.pxInt(620)
hWin = CONFIG.pxInt(360)

pOptions = SHARED.project.options
self.resize(
CONFIG.pxInt(pOptions.getInt("GuiManuscriptBuild", "winWidth", wWin)),
CONFIG.pxInt(pOptions.getInt("GuiManuscriptBuild", "winHeight", hWin))
pOptions.getInt("GuiManuscriptBuild", "winWidth", 620),
pOptions.getInt("GuiManuscriptBuild", "winHeight", 360),
)

# Output Format
Expand Down Expand Up @@ -149,7 +144,7 @@ def __init__(self, parent: QWidget, build: BuildSettings) -> None:
self.pathBox = QHBoxLayout()
self.pathBox.addWidget(self.buildPath)
self.pathBox.addWidget(self.btnBrowse)
self.pathBox.setSpacing(sp8)
self.pathBox.setSpacing(8)

# Build Name
self.lblName = QLabel(self.tr("File Name"), self)
Expand All @@ -160,23 +155,23 @@ def __init__(self, parent: QWidget, build: BuildSettings) -> None:
self.nameBox = QHBoxLayout()
self.nameBox.addWidget(self.buildName)
self.nameBox.addWidget(self.btnReset)
self.nameBox.setSpacing(sp8)
self.nameBox.setSpacing(8)

# Build Progress
self.buildProgress = NProgressSimple(self)
self.buildProgress.setMinimum(0)
self.buildProgress.setValue(0)
self.buildProgress.setTextVisible(False)
self.buildProgress.setFixedHeight(sp8)
self.buildProgress.setFixedHeight(8)

# Build Box
self.buildBox = QGridLayout()
self.buildBox.addWidget(self.lblPath, 0, 0)
self.buildBox.addLayout(self.pathBox, 0, 1)
self.buildBox.addWidget(self.lblName, 1, 0)
self.buildBox.addLayout(self.nameBox, 1, 1)
self.buildBox.setHorizontalSpacing(sp8)
self.buildBox.setVerticalSpacing(sp4)
self.buildBox.setHorizontalSpacing(8)
self.buildBox.setVerticalSpacing(4)

# Dialog Buttons
self.buttonBox = QDialogButtonBox(self)
Expand All @@ -196,33 +191,34 @@ def __init__(self, parent: QWidget, build: BuildSettings) -> None:
self.buttonBox.addButton(self.btnBuild, QtRoleAction)

self.btnClose = self.buttonBox.addButton(QtDialogClose)
self.btnClose.setAutoDefault(False)
if self.btnClose:
self.btnClose.setAutoDefault(False)

# Assemble GUI
# ============

self.mainSplit = QSplitter(self)
self.mainSplit.addWidget(self.formatWidget)
self.mainSplit.addWidget(self.contentWidget)
self.mainSplit.setHandleWidth(sp16)
self.mainSplit.setHandleWidth(16)
self.mainSplit.setCollapsible(0, False)
self.mainSplit.setCollapsible(1, False)
self.mainSplit.setStretchFactor(0, 0)
self.mainSplit.setStretchFactor(1, 1)
self.mainSplit.setSizes([
CONFIG.pxInt(pOptions.getInt("GuiManuscriptBuild", "fmtWidth", wWin//2)),
CONFIG.pxInt(pOptions.getInt("GuiManuscriptBuild", "sumWidth", wWin//2)),
pOptions.getInt("GuiManuscriptBuild", "fmtWidth", 360),
pOptions.getInt("GuiManuscriptBuild", "sumWidth", 360),
])

self.outerBox = QVBoxLayout()
self.outerBox.addWidget(self.lblMain, 0, QtAlignCenter)
self.outerBox.addSpacing(sp16)
self.outerBox.addSpacing(16)
self.outerBox.addWidget(self.mainSplit, 1)
self.outerBox.addSpacing(sp4)
self.outerBox.addSpacing(4)
self.outerBox.addWidget(self.buildProgress, 0)
self.outerBox.addSpacing(sp4)
self.outerBox.addSpacing(4)
self.outerBox.addLayout(self.buildBox, 0)
self.outerBox.addSpacing(sp16)
self.outerBox.addSpacing(16)
self.outerBox.addWidget(self.buttonBox, 0)
self.outerBox.setSpacing(0)

Expand Down Expand Up @@ -363,21 +359,14 @@ def _getSelectedFormat(self) -> nwBuildFmt | None:

def _saveSettings(self) -> None:
"""Save the user GUI settings."""
winWidth = CONFIG.rpxInt(self.width())
winHeight = CONFIG.rpxInt(self.height())

mainSplit = self.mainSplit.sizes()
fmtWidth = CONFIG.rpxInt(mainSplit[0])
sumWidth = CONFIG.rpxInt(mainSplit[1])

logger.debug("Saving State: GuiManuscriptBuild")
mainSplit = self.mainSplit.sizes()
pOptions = SHARED.project.options
pOptions.setValue("GuiManuscriptBuild", "winWidth", winWidth)
pOptions.setValue("GuiManuscriptBuild", "winHeight", winHeight)
pOptions.setValue("GuiManuscriptBuild", "fmtWidth", fmtWidth)
pOptions.setValue("GuiManuscriptBuild", "sumWidth", sumWidth)
pOptions.setValue("GuiManuscriptBuild", "winWidth", self.width())
pOptions.setValue("GuiManuscriptBuild", "winHeight", self.height())
pOptions.setValue("GuiManuscriptBuild", "fmtWidth", mainSplit[0])
pOptions.setValue("GuiManuscriptBuild", "sumWidth", mainSplit[1])
pOptions.saveSettings()

return

def _populateContentList(self) -> None:
Expand Down
Loading

0 comments on commit 7e280b2

Please sign in to comment.