Update linting for main code
This commit is contained in:
+3
-64
@@ -20,7 +20,7 @@ General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
""" # noqa
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
@@ -68,7 +68,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class GuiMain(QMainWindow):
|
||||
"""Main GUI Window
|
||||
"""Main GUI Window.
|
||||
|
||||
The Main GUI window class is the entry point of the application. It
|
||||
is split up into GUI components, assembled in the init function.
|
||||
@@ -323,13 +323,10 @@ class GuiMain(QMainWindow):
|
||||
self.mainStatus.setStatusMessage(self.tr("novelWriter is ready ..."))
|
||||
CONFIG.splashMessage("novelWriter is ready ...")
|
||||
|
||||
return
|
||||
|
||||
def initMain(self) -> None:
|
||||
"""Initialise elements that depend on user settings."""
|
||||
self.asProjTimer.setInterval(int(CONFIG.autoSaveProj*1000))
|
||||
self.asDocTimer.setInterval(int(CONFIG.autoSaveDoc*1000))
|
||||
return
|
||||
|
||||
def postLaunchTasks(self, cmdOpen: str | None) -> None:
|
||||
"""Process tasks after the main window has been created."""
|
||||
@@ -351,8 +348,6 @@ class GuiMain(QMainWindow):
|
||||
# before showing any dialogs
|
||||
QTimer.singleShot(50, self.showPostLaunchDialogs)
|
||||
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def showPostLaunchDialogs(self) -> None:
|
||||
"""Show post launch dialogs."""
|
||||
@@ -370,8 +365,6 @@ class GuiMain(QMainWindow):
|
||||
).format(f"<a href='{nwConst.URL_RELEASES}'>", "</a>")
|
||||
SHARED.info(f"{trVersion}<br>{trRelease}")
|
||||
|
||||
return
|
||||
|
||||
##
|
||||
# Project Actions
|
||||
##
|
||||
@@ -534,7 +527,6 @@ class GuiMain(QMainWindow):
|
||||
SHARED.setFocusMode(False)
|
||||
self.saveDocument()
|
||||
self.docEditor.clearEditor()
|
||||
return
|
||||
|
||||
def openDocument(
|
||||
self,
|
||||
@@ -591,7 +583,6 @@ class GuiMain(QMainWindow):
|
||||
self.openDocument(nHandle, tLine=1, doScroll=True)
|
||||
elif wrapAround:
|
||||
self.openDocument(fHandle, tLine=1, doScroll=True)
|
||||
return
|
||||
|
||||
def saveDocument(self, force: bool = False) -> None:
|
||||
"""Save the current documents."""
|
||||
@@ -599,13 +590,11 @@ class GuiMain(QMainWindow):
|
||||
self.docEditor.saveCursorPosition()
|
||||
if force or self.docEditor.docChanged:
|
||||
self.docEditor.saveText()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def forceSaveDocument(self) -> None:
|
||||
"""Save document even of it has not changed."""
|
||||
self.saveDocument(force=True)
|
||||
return
|
||||
|
||||
def viewDocument(self, tHandle: str | None = None, sTitle: str | None = None) -> bool:
|
||||
"""Load a document for viewing in the view panel."""
|
||||
@@ -760,8 +749,6 @@ class GuiMain(QMainWindow):
|
||||
if not beQuiet:
|
||||
SHARED.info(self.tr("The project index has been successfully rebuilt."))
|
||||
|
||||
return
|
||||
|
||||
##
|
||||
# Main Dialogs
|
||||
##
|
||||
@@ -772,7 +759,6 @@ class GuiMain(QMainWindow):
|
||||
dialog = GuiWelcome(self)
|
||||
dialog.openProjectRequest.connect(self._openProjectFromWelcome)
|
||||
dialog.exec()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def showPreferencesDialog(self) -> None:
|
||||
@@ -780,7 +766,6 @@ class GuiMain(QMainWindow):
|
||||
dialog = GuiPreferences(self)
|
||||
dialog.newPreferencesReady.connect(self._processConfigChanges)
|
||||
dialog.exec()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
@pyqtSlot(int)
|
||||
@@ -790,7 +775,6 @@ class GuiMain(QMainWindow):
|
||||
dialog = GuiProjectSettings(self, gotoPage=focusTab)
|
||||
dialog.newProjectSettingsReady.connect(self._processProjectSettingsChanges)
|
||||
dialog.exec()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def showNovelDetailsDialog(self) -> None:
|
||||
@@ -799,7 +783,6 @@ class GuiMain(QMainWindow):
|
||||
dialog = GuiNovelDetails(self)
|
||||
dialog.activateDialog()
|
||||
dialog.updateValues()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def showBuildManuscriptDialog(self) -> None:
|
||||
@@ -809,7 +792,6 @@ class GuiMain(QMainWindow):
|
||||
dialog = GuiManuscript(self)
|
||||
dialog.activateDialog()
|
||||
dialog.loadContent()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def showProjectWordListDialog(self) -> None:
|
||||
@@ -818,7 +800,6 @@ class GuiMain(QMainWindow):
|
||||
dialog = GuiWordList(self)
|
||||
dialog.newWordListReady.connect(self._processWordListChanges)
|
||||
dialog.exec()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def showWritingStatsDialog(self) -> None:
|
||||
@@ -828,21 +809,18 @@ class GuiMain(QMainWindow):
|
||||
dialog = GuiWritingStats(self)
|
||||
dialog.activateDialog()
|
||||
dialog.populateGUI()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def showAboutNWDialog(self) -> None:
|
||||
"""Show the novelWriter about dialog."""
|
||||
dialog = GuiAbout(self)
|
||||
dialog.exec()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def showAboutQtDialog(self) -> None:
|
||||
"""Show the Qt about dialog."""
|
||||
msgBox = QMessageBox(self)
|
||||
msgBox.aboutQt(self, "About Qt")
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def showDictionariesDialog(self) -> None:
|
||||
@@ -852,7 +830,6 @@ class GuiMain(QMainWindow):
|
||||
if not dialog.initDialog():
|
||||
dialog.close()
|
||||
SHARED.error(self.tr("Could not initialise the dialog."))
|
||||
return
|
||||
|
||||
##
|
||||
# Main Window Actions
|
||||
@@ -915,7 +892,6 @@ class GuiMain(QMainWindow):
|
||||
self.refreshThemeColors(syntax=True)
|
||||
self.docEditor.initEditor()
|
||||
self.docViewer.initViewer()
|
||||
return
|
||||
|
||||
def refreshThemeColors(self, syntax: bool = False, force: bool = False) -> None:
|
||||
"""Refresh the GUI theme."""
|
||||
@@ -937,8 +913,6 @@ class GuiMain(QMainWindow):
|
||||
if syntax:
|
||||
self.docEditor.updateSyntaxColors()
|
||||
|
||||
return
|
||||
|
||||
##
|
||||
# Events
|
||||
##
|
||||
@@ -947,14 +921,12 @@ class GuiMain(QMainWindow):
|
||||
"""Capture application change events."""
|
||||
if int(event.type()) == 210: # ThemeChange
|
||||
self.checkThemeUpdate()
|
||||
return
|
||||
|
||||
def closeEvent(self, event: QCloseEvent) -> None:
|
||||
"""Capture the closing event of the GUI and call the close
|
||||
function to handle all the close process steps.
|
||||
"""
|
||||
event.accept() if self.closeMain() else event.ignore()
|
||||
return
|
||||
|
||||
##
|
||||
# Public Slots
|
||||
@@ -962,30 +934,26 @@ class GuiMain(QMainWindow):
|
||||
|
||||
@pyqtSlot()
|
||||
def toggleFullScreenMode(self) -> None:
|
||||
"""Toggle full screen mode"""
|
||||
"""Toggle full screen mode."""
|
||||
self.setWindowState(self.windowState() ^ Qt.WindowState.WindowFullScreen)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def closeDocEditor(self) -> None:
|
||||
"""Close the document editor. This does not hide the editor."""
|
||||
self.closeDocument()
|
||||
SHARED.project.data.setLastHandle(None, "editor")
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def closeDocViewer(self) -> None:
|
||||
"""Close the document viewer."""
|
||||
self.closeViewerPanel()
|
||||
SHARED.project.data.setLastHandle(None, "viewer")
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def toggleFocusMode(self) -> None:
|
||||
"""Toggle focus mode."""
|
||||
if self.docEditor.docHandle:
|
||||
SHARED.setFocusMode(not SHARED.focusMode)
|
||||
return
|
||||
|
||||
##
|
||||
# Private Slots
|
||||
@@ -1003,7 +971,6 @@ class GuiMain(QMainWindow):
|
||||
docViewer = True
|
||||
self.docEditor.changeFocusState(docEditor)
|
||||
self.docViewer.changeFocusState(docViewer)
|
||||
return
|
||||
|
||||
@pyqtSlot(bool)
|
||||
def _focusModeChanged(self, focusMode: bool) -> None:
|
||||
@@ -1034,7 +1001,6 @@ class GuiMain(QMainWindow):
|
||||
|
||||
if cursorVisible:
|
||||
self.docEditor.ensureCursorVisibleNoCentre()
|
||||
return
|
||||
|
||||
@pyqtSlot(nwFocus)
|
||||
def _switchFocus(self, paneNo: nwFocus) -> None:
|
||||
@@ -1082,8 +1048,6 @@ class GuiMain(QMainWindow):
|
||||
self._changeView(nwView.OUTLINE, exitFocus=True)
|
||||
self.outlineView.setTreeFocus()
|
||||
|
||||
return
|
||||
|
||||
@pyqtSlot(bool, bool, bool, bool)
|
||||
def _processConfigChanges(self, restart: bool, tree: bool, theme: bool, syntax: bool) -> None:
|
||||
"""Refresh GUI based on flags from the Preferences dialog."""
|
||||
@@ -1115,8 +1079,6 @@ class GuiMain(QMainWindow):
|
||||
"Some changes will not be applied until novelWriter has been restarted."
|
||||
))
|
||||
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _processProjectSettingsChanges(self) -> None:
|
||||
"""Refresh data dependent on project settings."""
|
||||
@@ -1124,7 +1086,6 @@ class GuiMain(QMainWindow):
|
||||
SHARED.updateSpellCheckLanguage()
|
||||
self.itemDetails.refreshDetails()
|
||||
self._updateWindowTitle(SHARED.project.data.name)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _processWordListChanges(self) -> None:
|
||||
@@ -1132,7 +1093,6 @@ class GuiMain(QMainWindow):
|
||||
logger.debug("Reloading word list")
|
||||
SHARED.updateSpellCheckLanguage(reload=True)
|
||||
self.docEditor.spellCheckDocument()
|
||||
return
|
||||
|
||||
@pyqtSlot(str, nwDocMode)
|
||||
def _followTag(self, tag: str, mode: nwDocMode) -> None:
|
||||
@@ -1151,7 +1111,6 @@ class GuiMain(QMainWindow):
|
||||
self.openDocument(tHandle, sTitle=sTitle)
|
||||
elif mode == nwDocMode.VIEW:
|
||||
self.viewDocument(tHandle=tHandle, sTitle=sTitle)
|
||||
return
|
||||
|
||||
@pyqtSlot(Path)
|
||||
def _openProjectFromWelcome(self, path: Path) -> None:
|
||||
@@ -1160,7 +1119,6 @@ class GuiMain(QMainWindow):
|
||||
self.openProject(path)
|
||||
if not SHARED.hasProject:
|
||||
self.showWelcomeDialog()
|
||||
return
|
||||
|
||||
@pyqtSlot(str, nwDocMode, str, bool)
|
||||
def _openDocument(self, tHandle: str, mode: nwDocMode, sTitle: str, setFocus: bool) -> None:
|
||||
@@ -1170,7 +1128,6 @@ class GuiMain(QMainWindow):
|
||||
self.openDocument(tHandle, sTitle=sTitle, changeFocus=setFocus)
|
||||
elif mode == nwDocMode.VIEW:
|
||||
self.viewDocument(tHandle=tHandle, sTitle=sTitle)
|
||||
return
|
||||
|
||||
@pyqtSlot(str, int, int, bool)
|
||||
def _openDocumentSelection(
|
||||
@@ -1179,7 +1136,6 @@ class GuiMain(QMainWindow):
|
||||
"""Open a document and select a section of the text."""
|
||||
if self.openDocument(tHandle, changeFocus=changeFocus):
|
||||
self.docEditor.setCursorSelection(selStart, selLength)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _reloadViewer(self) -> None:
|
||||
@@ -1188,7 +1144,6 @@ class GuiMain(QMainWindow):
|
||||
# If the two panels have the same document, save any changes in the editor
|
||||
self.saveDocument()
|
||||
self.docViewer.reloadText()
|
||||
return
|
||||
|
||||
@pyqtSlot(nwView)
|
||||
def _changeView(self, view: nwView, exitFocus: bool = False) -> None:
|
||||
@@ -1219,8 +1174,6 @@ class GuiMain(QMainWindow):
|
||||
isNovel = self.projStack.currentWidget() == self.novelView
|
||||
self.novelView.setActive(isMain and isNovel)
|
||||
|
||||
return
|
||||
|
||||
@pyqtSlot(nwDocAction)
|
||||
def _passDocumentAction(self, action: nwDocAction) -> None:
|
||||
"""Pass on a document action to the editor or viewer based on
|
||||
@@ -1230,7 +1183,6 @@ class GuiMain(QMainWindow):
|
||||
self.docEditor.docAction(action)
|
||||
elif self.docViewer.hasFocus():
|
||||
self.docViewer.docAction(action)
|
||||
return
|
||||
|
||||
@pyqtSlot(str)
|
||||
@pyqtSlot(nwDocInsert)
|
||||
@@ -1240,14 +1192,12 @@ class GuiMain(QMainWindow):
|
||||
"""
|
||||
if self.docEditor.hasFocus():
|
||||
self.docEditor.insertText(content)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _toggleViewerPanelVisibility(self) -> None:
|
||||
"""Toggle the visibility of the document viewer panel."""
|
||||
CONFIG.showViewerPanel = not CONFIG.showViewerPanel
|
||||
self.docViewerPanel.setVisible(CONFIG.showViewerPanel)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _timeTick(self) -> None:
|
||||
@@ -1263,7 +1213,6 @@ class GuiMain(QMainWindow):
|
||||
self._updateStatusWordCount()
|
||||
if CONFIG.memInfo: # pragma: no cover
|
||||
self.mainStatus.memInfo()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _autoSaveProject(self) -> None:
|
||||
@@ -1274,7 +1223,6 @@ class GuiMain(QMainWindow):
|
||||
if doSave:
|
||||
logger.debug("Auto-saving project")
|
||||
self.saveProject(autoSave=True)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _autoSaveDocument(self) -> None:
|
||||
@@ -1282,7 +1230,6 @@ class GuiMain(QMainWindow):
|
||||
if SHARED.hasProject and self.docEditor.docChanged:
|
||||
logger.debug("Auto-saving document")
|
||||
self.saveDocument()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _updateStatusWordCount(self) -> None:
|
||||
@@ -1312,8 +1259,6 @@ class GuiMain(QMainWindow):
|
||||
|
||||
self.mainStatus.setProjectStats(cTotal, cTotal - iTotal)
|
||||
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _keyPressReturn(self) -> None:
|
||||
"""Process a return or enter keypress in the main window."""
|
||||
@@ -1321,7 +1266,6 @@ class GuiMain(QMainWindow):
|
||||
self.projSearch.processReturn()
|
||||
else:
|
||||
self.openSelectedItem()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _keyPressEscape(self) -> None:
|
||||
@@ -1330,7 +1274,6 @@ class GuiMain(QMainWindow):
|
||||
self.docEditor.closeSearch()
|
||||
elif SHARED.focusMode:
|
||||
SHARED.setFocusMode(False)
|
||||
return
|
||||
|
||||
@pyqtSlot(int)
|
||||
def _mainStackChanged(self, index: int) -> None:
|
||||
@@ -1338,7 +1281,6 @@ class GuiMain(QMainWindow):
|
||||
if self.mainStack.widget(index) == self.outlineView:
|
||||
if SHARED.hasProject:
|
||||
self.outlineView.refreshTree()
|
||||
return
|
||||
|
||||
@pyqtSlot(int)
|
||||
def _projStackChanged(self, index: int) -> None:
|
||||
@@ -1350,7 +1292,6 @@ class GuiMain(QMainWindow):
|
||||
elif widget == self.novelView:
|
||||
sHandle, _ = self.novelView.getSelectedHandle()
|
||||
self.itemDetails.updateViewBox(sHandle)
|
||||
return
|
||||
|
||||
##
|
||||
# Internal Functions
|
||||
@@ -1363,9 +1304,7 @@ class GuiMain(QMainWindow):
|
||||
width = minmax(size[0], 900, availSize.width())
|
||||
height = minmax(size[1], 500, availSize.height())
|
||||
self.resize(width, height)
|
||||
return
|
||||
|
||||
def _updateWindowTitle(self, projName: str | None = None) -> None:
|
||||
"""Set the window title and add the project's name."""
|
||||
self.setWindowTitle(" - ".join(filter(None, [projName, CONFIG.appName])))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user