From 021827ff2d7125b929517dab14fbe83a12c86b5d Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Fri, 15 Nov 2024 20:49:45 +0100 Subject: [PATCH] Force the Build button to be default on the build dialog (#2101) --- novelwriter/tools/manusbuild.py | 18 ++++++++++++------ tests/test_tools/test_tools_manusbuild.py | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/novelwriter/tools/manusbuild.py b/novelwriter/tools/manusbuild.py index e37bfca5a..3eba76ac3 100644 --- a/novelwriter/tools/manusbuild.py +++ b/novelwriter/tools/manusbuild.py @@ -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 # ============ @@ -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) @@ -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") @@ -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() diff --git a/tests/test_tools/test_tools_manusbuild.py b/tests/test_tools/test_tools_manusbuild.py index 92c124900..c1e614bab 100644 --- a/tests/test_tools/test_tools_manusbuild.py +++ b/tests/test_tools/test_tools_manusbuild.py @@ -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" @@ -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()