Skip to content

Commit

Permalink
Fix default button issue on Build dialog (#2105)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo authored Nov 15, 2024
2 parents 97312ae + 021827f commit 49bb7f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 12 additions & 6 deletions novelwriter/tools/manusbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,20 @@ def __init__(self, parent: QWidget, build: BuildSettings) -> None:
self.buildBox.setVerticalSpacing(sp4)

# Dialog Buttons
self.buttonBox = QDialogButtonBox(self)

self.btnOpen = QPushButton(SHARED.theme.getIcon("browse"), self.tr("Open Folder"), self)
self.btnOpen.setIconSize(bSz)
self.btnOpen.setAutoDefault(False)
self.buttonBox.addButton(self.btnOpen, QtRoleAction)

self.btnBuild = QPushButton(SHARED.theme.getIcon("export"), self.tr("&Build"), self)
self.btnBuild.setIconSize(bSz)
self.btnBuild.setAutoDefault(True)
self.buttonBox.addButton(self.btnBuild, QtRoleAction)

self.dlgButtons = QDialogButtonBox(QtDialogClose, self)
self.dlgButtons.addButton(self.btnOpen, QtRoleAction)
self.dlgButtons.addButton(self.btnBuild, QtRoleAction)
self.btnClose = self.buttonBox.addButton(QtDialogClose)
self.btnClose.setAutoDefault(False)

# Assemble GUI
# ============
Expand All @@ -213,7 +219,7 @@ def __init__(self, parent: QWidget, build: BuildSettings) -> None:
self.outerBox.addSpacing(sp4)
self.outerBox.addLayout(self.buildBox, 0)
self.outerBox.addSpacing(sp16)
self.outerBox.addWidget(self.dlgButtons, 0)
self.outerBox.addWidget(self.buttonBox, 0)
self.outerBox.setSpacing(0)

self.setLayout(self.outerBox)
Expand All @@ -229,7 +235,7 @@ def __init__(self, parent: QWidget, build: BuildSettings) -> None:
# Signals
self.btnReset.clicked.connect(self._doResetBuildName)
self.btnBrowse.clicked.connect(self._doSelectPath)
self.dlgButtons.clicked.connect(self._dialogButtonClicked)
self.buttonBox.clicked.connect(self._dialogButtonClicked)
self.listFormats.itemSelectionChanged.connect(self._resetProgress)

logger.debug("Ready: GuiManuscriptBuild")
Expand Down Expand Up @@ -260,7 +266,7 @@ def closeEvent(self, event: QCloseEvent) -> None:
@pyqtSlot("QAbstractButton*")
def _dialogButtonClicked(self, button: QAbstractButton) -> None:
"""Handle button clicks from the dialog button box."""
role = self.dlgButtons.buttonRole(button)
role = self.buttonBox.buttonRole(button)
if role == QtRoleAction:
if button == self.btnBuild:
self._runBuild()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_tools/test_tools_manusbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def selectFormat(fmt):
assert (fncPath / "TestBuild").with_suffix(nwLabels.BUILD_EXT[fmt]).exists()
lastFmt = fmt

manus._dialogButtonClicked(manus.dlgButtons.button(QtDialogClose))
manus._dialogButtonClicked(manus.buttonBox.button(QtDialogClose))
manus.deleteLater()

assert build.lastBuildName == "TestBuild"
Expand Down Expand Up @@ -150,5 +150,5 @@ def mockOpenUrl(url: QUrl) -> None:
assert lastUrl.startswith("file://")

# Finish
manus._dialogButtonClicked(manus.dlgButtons.button(QtDialogClose))
manus._dialogButtonClicked(manus.buttonBox.button(QtDialogClose))
# qtbot.stop()

0 comments on commit 49bb7f3

Please sign in to comment.