Made most menu entries lambda functions

This commit is contained in:
Veronica K. B. Olsen
2020-09-19 16:36:41 +02:00
parent adbbe3fc83
commit 43fc829c4f
+27 -45
View File
@@ -130,13 +130,7 @@ class GuiMainMenu(QMenuBar):
# Menu Action # Menu Action
## ##
def _menuExit(self): def _toggleSpellCheck(self, isChecked=False):
"""Exit novelWriter.
"""
self.theParent.closeMain()
return
def _toggleSpellCheck(self):
"""Toggle spell checking. The active status of the spell check """Toggle spell checking. The active status of the spell check
flag is handled by the document editor class, so we make no flag is handled by the document editor class, so we make no
decision, just pass a None to the function and let it decide. decision, just pass a None to the function and let it decide.
@@ -150,7 +144,7 @@ class GuiMainMenu(QMenuBar):
self.theProject.setAutoOutline(theMode) self.theProject.setAutoOutline(theMode)
return True return True
def _openAssistant(self): def _openAssistant(self, isChecked=False):
"""Open the documentation in Qt Assistant. """Open the documentation in Qt Assistant.
""" """
if not self.mainConf.hasHelp: if not self.mainConf.hasHelp:
@@ -178,18 +172,6 @@ class GuiMainMenu(QMenuBar):
QDesktopServices.openUrl(QUrl(nw.__issuesurl__)) QDesktopServices.openUrl(QUrl(nw.__issuesurl__))
return True return True
def _showDocumentLocation(self):
"""Open the dialog showing the location of the editor document.
"""
self.theParent.docEditor.revealLocation()
return True
def _doBackup(self):
"""Call the backup function for the project.
"""
self.theProject.zipIt(True)
return True
## ##
# Menu Builders # Menu Builders
## ##
@@ -210,14 +192,14 @@ class GuiMainMenu(QMenuBar):
self.aOpenProject = QAction("Open Project", self) self.aOpenProject = QAction("Open Project", self)
self.aOpenProject.setStatusTip("Open project") self.aOpenProject.setStatusTip("Open project")
self.aOpenProject.setShortcut("Ctrl+Shift+O") self.aOpenProject.setShortcut("Ctrl+Shift+O")
self.aOpenProject.triggered.connect(self.theParent.manageProjects) self.aOpenProject.triggered.connect(lambda: self.theParent.manageProjects())
self.projMenu.addAction(self.aOpenProject) self.projMenu.addAction(self.aOpenProject)
# Project > Save Project # Project > Save Project
self.aSaveProject = QAction("Save Project", self) self.aSaveProject = QAction("Save Project", self)
self.aSaveProject.setStatusTip("Save project") self.aSaveProject.setStatusTip("Save project")
self.aSaveProject.setShortcut("Ctrl+Shift+S") self.aSaveProject.setShortcut("Ctrl+Shift+S")
self.aSaveProject.triggered.connect(self.theParent.saveProject) self.aSaveProject.triggered.connect(lambda: self.theParent.saveProject())
self.projMenu.addAction(self.aSaveProject) self.projMenu.addAction(self.aSaveProject)
# Project > Close Project # Project > Close Project
@@ -231,7 +213,7 @@ class GuiMainMenu(QMenuBar):
self.aProjectSettings = QAction("Project Settings", self) self.aProjectSettings = QAction("Project Settings", self)
self.aProjectSettings.setStatusTip("Project settings") self.aProjectSettings.setStatusTip("Project settings")
self.aProjectSettings.setShortcut("Ctrl+Shift+,") self.aProjectSettings.setShortcut("Ctrl+Shift+,")
self.aProjectSettings.triggered.connect(self.theParent.editProjectDialog) self.aProjectSettings.triggered.connect(lambda: self.theParent.editProjectDialog())
self.projMenu.addAction(self.aProjectSettings) self.projMenu.addAction(self.aProjectSettings)
# Project > Separator # Project > Separator
@@ -284,7 +266,7 @@ class GuiMainMenu(QMenuBar):
# Project > Empty Trash # Project > Empty Trash
self.aEmptyTrash = QAction("Empty Trash", self) self.aEmptyTrash = QAction("Empty Trash", self)
self.aEmptyTrash.setStatusTip("Permanently delete all files in the Trash folder") self.aEmptyTrash.setStatusTip("Permanently delete all files in the Trash folder")
self.aEmptyTrash.triggered.connect(self.theParent.treeView.emptyTrash) self.aEmptyTrash.triggered.connect(lambda: self.theParent.treeView.emptyTrash())
self.projMenu.addAction(self.aEmptyTrash) self.projMenu.addAction(self.aEmptyTrash)
# Project > Separator # Project > Separator
@@ -294,7 +276,7 @@ class GuiMainMenu(QMenuBar):
self.aExitNW = QAction("Exit", self) self.aExitNW = QAction("Exit", self)
self.aExitNW.setStatusTip("Exit %s" % self.mainConf.appName) self.aExitNW.setStatusTip("Exit %s" % self.mainConf.appName)
self.aExitNW.setShortcut("Ctrl+Q") self.aExitNW.setShortcut("Ctrl+Q")
self.aExitNW.triggered.connect(self._menuExit) self.aExitNW.triggered.connect(lambda: self.theParent.closeMain())
self.projMenu.addAction(self.aExitNW) self.projMenu.addAction(self.aExitNW)
return return
@@ -316,21 +298,21 @@ class GuiMainMenu(QMenuBar):
self.aOpenDoc = QAction("Open Document", self) self.aOpenDoc = QAction("Open Document", self)
self.aOpenDoc.setStatusTip("Open selected document") self.aOpenDoc.setStatusTip("Open selected document")
self.aOpenDoc.setShortcut("Ctrl+O") self.aOpenDoc.setShortcut("Ctrl+O")
self.aOpenDoc.triggered.connect(self.theParent.openSelectedItem) self.aOpenDoc.triggered.connect(lambda: self.theParent.openSelectedItem())
self.docuMenu.addAction(self.aOpenDoc) self.docuMenu.addAction(self.aOpenDoc)
# Document > Save # Document > Save
self.aSaveDoc = QAction("Save Document", self) self.aSaveDoc = QAction("Save Document", self)
self.aSaveDoc.setStatusTip("Save current document") self.aSaveDoc.setStatusTip("Save current document")
self.aSaveDoc.setShortcut("Ctrl+S") self.aSaveDoc.setShortcut("Ctrl+S")
self.aSaveDoc.triggered.connect(self.theParent.saveDocument) self.aSaveDoc.triggered.connect(lambda: self.theParent.saveDocument())
self.docuMenu.addAction(self.aSaveDoc) self.docuMenu.addAction(self.aSaveDoc)
# Document > Close # Document > Close
self.aCloseDoc = QAction("Close Document", self) self.aCloseDoc = QAction("Close Document", self)
self.aCloseDoc.setStatusTip("Close current document") self.aCloseDoc.setStatusTip("Close current document")
self.aCloseDoc.setShortcut("Ctrl+W") self.aCloseDoc.setShortcut("Ctrl+W")
self.aCloseDoc.triggered.connect(self.theParent.closeDocEditor) self.aCloseDoc.triggered.connect(lambda: self.theParent.closeDocEditor())
self.docuMenu.addAction(self.aCloseDoc) self.docuMenu.addAction(self.aCloseDoc)
# Document > Separator # Document > Separator
@@ -347,7 +329,7 @@ class GuiMainMenu(QMenuBar):
self.aCloseView = QAction("Close Document View", self) self.aCloseView = QAction("Close Document View", self)
self.aCloseView.setStatusTip("Close document view pane") self.aCloseView.setStatusTip("Close document view pane")
self.aCloseView.setShortcut("Ctrl+Shift+R") self.aCloseView.setShortcut("Ctrl+Shift+R")
self.aCloseView.triggered.connect(self.theParent.closeDocViewer) self.aCloseView.triggered.connect(lambda: self.theParent.closeDocViewer())
self.docuMenu.addAction(self.aCloseView) self.docuMenu.addAction(self.aCloseView)
# Document > Separator # Document > Separator
@@ -358,26 +340,26 @@ class GuiMainMenu(QMenuBar):
self.aFileDetails.setStatusTip( self.aFileDetails.setStatusTip(
"Shows a message box with the document location in the project folder" "Shows a message box with the document location in the project folder"
) )
self.aFileDetails.triggered.connect(self._showDocumentLocation) self.aFileDetails.triggered.connect(lambda: self.theParent.docEditor.revealLocation())
self.docuMenu.addAction(self.aFileDetails) self.docuMenu.addAction(self.aFileDetails)
# Document > Import From File # Document > Import From File
self.aImportFile = QAction("Import from File", self) self.aImportFile = QAction("Import from File", self)
self.aImportFile.setStatusTip("Import document from a text or markdown file") self.aImportFile.setStatusTip("Import document from a text or markdown file")
self.aImportFile.setShortcut("Ctrl+Shift+I") self.aImportFile.setShortcut("Ctrl+Shift+I")
self.aImportFile.triggered.connect(self.theParent.importDocument) self.aImportFile.triggered.connect(lambda: self.theParent.importDocument())
self.docuMenu.addAction(self.aImportFile) self.docuMenu.addAction(self.aImportFile)
# Document > Merge Documents # Document > Merge Documents
self.aMergeDocs = QAction("Merge Folder to Document", self) self.aMergeDocs = QAction("Merge Folder to Document", self)
self.aMergeDocs.setStatusTip("Merge a folder of documents to a single document") self.aMergeDocs.setStatusTip("Merge a folder of documents to a single document")
self.aMergeDocs.triggered.connect(self.theParent.mergeDocuments) self.aMergeDocs.triggered.connect(lambda: self.theParent.mergeDocuments())
self.docuMenu.addAction(self.aMergeDocs) self.docuMenu.addAction(self.aMergeDocs)
# Document > Split Document # Document > Split Document
self.aSplitDoc = QAction("Split Document to Folder", self) self.aSplitDoc = QAction("Split Document to Folder", self)
self.aSplitDoc.setStatusTip("Split a document into a folder of multiple documents") self.aSplitDoc.setStatusTip("Split a document into a folder of multiple documents")
self.aSplitDoc.triggered.connect(self.theParent.splitDocument) self.aSplitDoc.triggered.connect(lambda: self.theParent.splitDocument())
self.docuMenu.addAction(self.aSplitDoc) self.docuMenu.addAction(self.aSplitDoc)
return return
@@ -479,14 +461,14 @@ class GuiMainMenu(QMenuBar):
self.aViewPrev = QAction("Go Backward", self) self.aViewPrev = QAction("Go Backward", self)
self.aViewPrev.setStatusTip("Move backward in the view history of the right pane") self.aViewPrev.setStatusTip("Move backward in the view history of the right pane")
self.aViewPrev.setShortcut("Alt+Left") self.aViewPrev.setShortcut("Alt+Left")
self.aViewPrev.triggered.connect(self.theParent.docViewer.navBackward) self.aViewPrev.triggered.connect(lambda: self.theParent.docViewer.navBackward())
self.viewMenu.addAction(self.aViewPrev) self.viewMenu.addAction(self.aViewPrev)
# View > Go Forward # View > Go Forward
self.aViewNext = QAction("Go Forward", self) self.aViewNext = QAction("Go Forward", self)
self.aViewNext.setStatusTip("Move forward in the view history of the right pane") self.aViewNext.setStatusTip("Move forward in the view history of the right pane")
self.aViewNext.setShortcut("Alt+Right") self.aViewNext.setShortcut("Alt+Right")
self.aViewNext.triggered.connect(self.theParent.docViewer.navForward) self.aViewNext.triggered.connect(lambda: self.theParent.docViewer.navForward())
self.viewMenu.addAction(self.aViewNext) self.viewMenu.addAction(self.aViewNext)
# View > Separator # View > Separator
@@ -505,7 +487,7 @@ class GuiMainMenu(QMenuBar):
self.aFullScreen = QAction("Full Screen Mode", self) self.aFullScreen = QAction("Full Screen Mode", self)
self.aFullScreen.setStatusTip("Maximises the main window") self.aFullScreen.setStatusTip("Maximises the main window")
self.aFullScreen.setShortcut("F11") self.aFullScreen.setShortcut("F11")
self.aFullScreen.triggered.connect(self.theParent.toggleFullScreenMode) self.aFullScreen.triggered.connect(lambda: self.theParent.toggleFullScreenMode())
self.viewMenu.addAction(self.aFullScreen) self.viewMenu.addAction(self.aFullScreen)
return return
@@ -806,7 +788,7 @@ class GuiMainMenu(QMenuBar):
self.aReRunSpell = QAction("Re-Run Spell Check", self) self.aReRunSpell = QAction("Re-Run Spell Check", self)
self.aReRunSpell.setStatusTip("Run the spell checker on current document") self.aReRunSpell.setStatusTip("Run the spell checker on current document")
self.aReRunSpell.setShortcut("F7") self.aReRunSpell.setShortcut("F7")
self.aReRunSpell.triggered.connect(self.theParent.docEditor.spellCheckDocument) self.aReRunSpell.triggered.connect(lambda: self.theParent.docEditor.spellCheckDocument())
self.toolsMenu.addAction(self.aReRunSpell) self.toolsMenu.addAction(self.aReRunSpell)
# Tools > Separator # Tools > Separator
@@ -816,14 +798,14 @@ class GuiMainMenu(QMenuBar):
self.aRebuildIndex = QAction("Rebuild Index", self) self.aRebuildIndex = QAction("Rebuild Index", self)
self.aRebuildIndex.setStatusTip("Rebuild the tag indices and word counts") self.aRebuildIndex.setStatusTip("Rebuild the tag indices and word counts")
self.aRebuildIndex.setShortcut("F9") self.aRebuildIndex.setShortcut("F9")
self.aRebuildIndex.triggered.connect(self.theParent.rebuildIndex) self.aRebuildIndex.triggered.connect(lambda: self.theParent.rebuildIndex())
self.toolsMenu.addAction(self.aRebuildIndex) self.toolsMenu.addAction(self.aRebuildIndex)
# Tools > Rebuild Outline # Tools > Rebuild Outline
self.aRebuildOutline = QAction("Rebuild Outline", self) self.aRebuildOutline = QAction("Rebuild Outline", self)
self.aRebuildOutline.setStatusTip("Rebuild the novel outline tree") self.aRebuildOutline.setStatusTip("Rebuild the novel outline tree")
self.aRebuildOutline.setShortcut("F10") self.aRebuildOutline.setShortcut("F10")
self.aRebuildOutline.triggered.connect(self.theParent.rebuildOutline) self.aRebuildOutline.triggered.connect(lambda: self.theParent.rebuildOutline())
self.toolsMenu.addAction(self.aRebuildOutline) self.toolsMenu.addAction(self.aRebuildOutline)
# Tools > Toggle Auto Build Outline # Tools > Toggle Auto Build Outline
@@ -840,28 +822,28 @@ class GuiMainMenu(QMenuBar):
# Tools > Backup # Tools > Backup
self.aBackupProject = QAction("Backup Project Folder", self) self.aBackupProject = QAction("Backup Project Folder", self)
self.aBackupProject.setStatusTip("Backup Project") self.aBackupProject.setStatusTip("Backup Project")
self.aBackupProject.triggered.connect(self._doBackup) self.aBackupProject.triggered.connect(lambda: self.theProject.zipIt(True))
self.toolsMenu.addAction(self.aBackupProject) self.toolsMenu.addAction(self.aBackupProject)
# Tools > Export Project # Tools > Export Project
self.aBuildProject = QAction("Build Novel Project", self) self.aBuildProject = QAction("Build Novel Project", self)
self.aBuildProject.setStatusTip("Launch the Build novel project tool") self.aBuildProject.setStatusTip("Launch the Build novel project tool")
self.aBuildProject.setShortcut("F5") self.aBuildProject.setShortcut("F5")
self.aBuildProject.triggered.connect(self.theParent.buildProjectDialog) self.aBuildProject.triggered.connect(lambda: self.theParent.buildProjectDialog())
self.toolsMenu.addAction(self.aBuildProject) self.toolsMenu.addAction(self.aBuildProject)
# Tools > Writing Stats # Tools > Writing Stats
self.aWritingStats = QAction("Writing Statistics", self) self.aWritingStats = QAction("Writing Statistics", self)
self.aWritingStats.setStatusTip("Show the writing statistics dialog") self.aWritingStats.setStatusTip("Show the writing statistics dialog")
self.aWritingStats.setShortcut("F6") self.aWritingStats.setShortcut("F6")
self.aWritingStats.triggered.connect(self.theParent.showWritingStatsDialog) self.aWritingStats.triggered.connect(lambda: self.theParent.showWritingStatsDialog())
self.toolsMenu.addAction(self.aWritingStats) self.toolsMenu.addAction(self.aWritingStats)
# Tools > Settings # Tools > Settings
self.aPreferences = QAction("Preferences", self) self.aPreferences = QAction("Preferences", self)
self.aPreferences.setStatusTip("Preferences") self.aPreferences.setStatusTip("Preferences")
self.aPreferences.setShortcut("Ctrl+,") self.aPreferences.setShortcut("Ctrl+,")
self.aPreferences.triggered.connect(self.theParent.editConfigDialog) self.aPreferences.triggered.connect(lambda: self.theParent.editConfigDialog())
self.toolsMenu.addAction(self.aPreferences) self.toolsMenu.addAction(self.aPreferences)
return return
@@ -875,13 +857,13 @@ class GuiMainMenu(QMenuBar):
# Help > About # Help > About
self.aAboutNW = QAction("About %s" % self.mainConf.appName, self) self.aAboutNW = QAction("About %s" % self.mainConf.appName, self)
self.aAboutNW.setStatusTip("About %s" % self.mainConf.appName) self.aAboutNW.setStatusTip("About %s" % self.mainConf.appName)
self.aAboutNW.triggered.connect(self.theParent.showAboutNWDialog) self.aAboutNW.triggered.connect(lambda: self.theParent.showAboutNWDialog())
self.helpMenu.addAction(self.aAboutNW) self.helpMenu.addAction(self.aAboutNW)
# Help > About Qt5 # Help > About Qt5
self.aAboutQt = QAction("About Qt5", self) self.aAboutQt = QAction("About Qt5", self)
self.aAboutQt.setStatusTip("About Qt5") self.aAboutQt.setStatusTip("About Qt5")
self.aAboutQt.triggered.connect(self.theParent.showAboutQtDialog) self.aAboutQt.triggered.connect(lambda: self.theParent.showAboutQtDialog())
self.helpMenu.addAction(self.aAboutQt) self.helpMenu.addAction(self.aAboutQt)
# Help > Separator # Help > Separator