Update linting for main code
This commit is contained in:
+8
-39
@@ -21,7 +21,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
|
||||
@@ -57,6 +57,12 @@ RX_HTML = re.compile(r"<.*?>")
|
||||
|
||||
|
||||
class SharedData(QObject):
|
||||
"""Shared Data Singleton.
|
||||
|
||||
This is the class instantiated as the SHARED singleton. It holds
|
||||
various globally needed data and pointers to important objects like
|
||||
the main GUI, the current project, and the GUI theme.
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"_gui", "_idleRefTime", "_idleTime", "_lastAlert", "_lockedBy",
|
||||
@@ -96,8 +102,6 @@ class SharedData(QObject):
|
||||
self._clock.setInterval(1000)
|
||||
self._clock.timeout.connect(lambda: self.mainClockTick.emit())
|
||||
|
||||
return
|
||||
|
||||
##
|
||||
# Properties
|
||||
##
|
||||
@@ -169,7 +173,6 @@ class SharedData(QObject):
|
||||
if state is not self._focusMode:
|
||||
self._focusMode = state
|
||||
self.focusModeChanged.emit(state)
|
||||
return
|
||||
|
||||
##
|
||||
# Methods
|
||||
@@ -181,7 +184,6 @@ class SharedData(QObject):
|
||||
"""
|
||||
self._theme = theme
|
||||
self._theme.initThemes()
|
||||
return
|
||||
|
||||
def initSharedData(self, gui: GuiMain) -> None:
|
||||
"""Initialise the SharedData instance. This must be called as
|
||||
@@ -194,7 +196,6 @@ class SharedData(QObject):
|
||||
logger.debug("Ready: SharedData")
|
||||
if pool := QThreadPool.globalInstance():
|
||||
logger.debug("Thread Pool Max Count: %d", pool.maxThreadCount())
|
||||
return
|
||||
|
||||
def closeDocument(self, tHandle: str | None = None) -> None:
|
||||
"""Close the document editor, optionally a specific document."""
|
||||
@@ -202,7 +203,6 @@ class SharedData(QObject):
|
||||
self.mainGui.closeDocument()
|
||||
if tHandle is None or tHandle == self.mainGui.docViewer.docHandle:
|
||||
self.mainGui.closeViewerPanel()
|
||||
return
|
||||
|
||||
def saveEditor(self, tHandle: str | None = None) -> None:
|
||||
"""Save the editor content, optionally a specific document."""
|
||||
@@ -213,7 +213,6 @@ class SharedData(QObject):
|
||||
):
|
||||
logger.debug("Saving editor document before action")
|
||||
docEditor.saveText()
|
||||
return
|
||||
|
||||
def openProject(self, path: str | Path, clearLock: bool = False) -> bool:
|
||||
"""Open a project."""
|
||||
@@ -246,7 +245,6 @@ class SharedData(QObject):
|
||||
self.project.closeProject(self._idleTime)
|
||||
self._resetProject()
|
||||
self._resetIdleTimer()
|
||||
return
|
||||
|
||||
def updateSpellCheckLanguage(self, reload: bool = False) -> None:
|
||||
"""Update the active spell check language from settings."""
|
||||
@@ -256,7 +254,6 @@ class SharedData(QObject):
|
||||
self.spelling.setLanguage(language)
|
||||
_, provider = self.spelling.describeDict()
|
||||
self.spellLanguageChanged.emit(language, provider)
|
||||
return
|
||||
|
||||
def updateIdleTime(self, currTime: float, userIdle: bool) -> None:
|
||||
"""Update the idle time record. If the userIdle flag is True,
|
||||
@@ -267,47 +264,40 @@ class SharedData(QObject):
|
||||
if userIdle:
|
||||
self._idleTime += currTime - self._idleRefTime
|
||||
self._idleRefTime = currTime
|
||||
return
|
||||
|
||||
def initMainProgress(self, maximum: int, inclusive: bool = False) -> None:
|
||||
"""Start a session for the main progress bar."""
|
||||
if gui := self._gui:
|
||||
gui.mainProgress.setMaximum(maximum - (1 if inclusive else 0))
|
||||
gui.mainProgress.setValue(0)
|
||||
return
|
||||
|
||||
def incMainProgress(self) -> None:
|
||||
"""Increment the value for the main progress bar."""
|
||||
if gui := self._gui:
|
||||
gui.mainProgress.setValue(gui.mainProgress.value() + 1)
|
||||
QApplication.processEvents()
|
||||
return
|
||||
|
||||
def clearMainProgress(self, delay: float = 1.0) -> None:
|
||||
"""Clear the main progress bar."""
|
||||
if gui := self._gui:
|
||||
QTimer.singleShot(int(delay*1000), gui.mainProgress.reset)
|
||||
return
|
||||
|
||||
def newStatusMessage(self, message: str) -> None:
|
||||
"""Request a new status message. This is a callable function for
|
||||
core classes that cannot emit signals on their own.
|
||||
"""
|
||||
self.projectStatusMessage.emit(message)
|
||||
return
|
||||
|
||||
def setGlobalProjectState(self, state: bool) -> None:
|
||||
"""Change the global project status. This is a callable function
|
||||
for core classes that cannot emit signals on their own.
|
||||
"""
|
||||
self.projectStatusChanged.emit(state)
|
||||
return
|
||||
|
||||
def runInThreadPool(self, runnable: QRunnable, priority: int = 0) -> None:
|
||||
"""Queue a runnable in the application thread pool."""
|
||||
if pool := QThreadPool.globalInstance():
|
||||
pool.start(runnable, priority=priority)
|
||||
return
|
||||
|
||||
def getProjectPath(
|
||||
self, parent: QWidget,
|
||||
@@ -346,13 +336,11 @@ class SharedData(QObject):
|
||||
def openWebsite(self, url: str) -> None:
|
||||
"""Open a URL in the system's default browser."""
|
||||
QDesktopServices.openUrl(QUrl(url))
|
||||
return
|
||||
|
||||
@pyqtSlot(str, nwItemClass)
|
||||
def createNewNote(self, tag: str, itemClass: nwItemClass) -> None:
|
||||
"""Process new note request."""
|
||||
self.project.createNewNote(tag, itemClass)
|
||||
return
|
||||
|
||||
##
|
||||
# Signal Proxies
|
||||
@@ -364,37 +352,31 @@ class SharedData(QObject):
|
||||
"""Emit the indexChangedTags signal."""
|
||||
if self._project and self._project.data.uuid == project.data.uuid:
|
||||
self.indexChangedTags.emit(updated, deleted)
|
||||
return
|
||||
|
||||
def emitIndexCleared(self, project: NWProject) -> None:
|
||||
"""Emit the indexCleared signal."""
|
||||
if self._project and self._project.data.uuid == project.data.uuid:
|
||||
self.indexCleared.emit()
|
||||
return
|
||||
|
||||
def emitIndexAvailable(self, project: NWProject) -> None:
|
||||
"""Emit the indexAvailable signal."""
|
||||
if self._project and self._project.data.uuid == project.data.uuid:
|
||||
self.indexAvailable.emit()
|
||||
return
|
||||
|
||||
def emitStatusLabelsChanged(self, project: NWProject, kind: T_StatusKind) -> None:
|
||||
"""Emit the statusLabelsChanged signal."""
|
||||
if self._project and self._project.data.uuid == project.data.uuid:
|
||||
self.statusLabelsChanged.emit(kind)
|
||||
return
|
||||
|
||||
def emitProjectItemChanged(self, project: NWProject, handle: str, change: nwChange) -> None:
|
||||
"""Emit the projectItemChanged signal."""
|
||||
if self._project and self._project.data.uuid == project.data.uuid:
|
||||
self.projectItemChanged.emit(handle, change)
|
||||
return
|
||||
|
||||
def emitRootFolderChanged(self, project: NWProject, handle: str, change: nwChange) -> None:
|
||||
"""Emit the rootFolderChanged signal."""
|
||||
if self._project and self._project.data.uuid == project.data.uuid:
|
||||
self.rootFolderChanged.emit(handle, change)
|
||||
return
|
||||
|
||||
##
|
||||
# Alert Boxes
|
||||
@@ -409,7 +391,6 @@ class SharedData(QObject):
|
||||
if log:
|
||||
self._logMessage(self._lastAlert, logger.info)
|
||||
alert.exec()
|
||||
return
|
||||
|
||||
def warn(self, text: str, info: str = "", details: str = "", log: bool = True) -> None:
|
||||
"""Open a warning alert box."""
|
||||
@@ -420,7 +401,6 @@ class SharedData(QObject):
|
||||
if log:
|
||||
self._logMessage(self._lastAlert, logger.warning)
|
||||
alert.exec()
|
||||
return
|
||||
|
||||
def error(self, text: str, info: str = "", details: str = "", log: bool = True,
|
||||
exc: Exception | None = None) -> None:
|
||||
@@ -434,7 +414,6 @@ class SharedData(QObject):
|
||||
if log:
|
||||
self._logMessage(self._lastAlert, logger.error)
|
||||
alert.exec()
|
||||
return
|
||||
|
||||
def question(self, text: str, info: str = "", details: str = "", warn: bool = False) -> bool:
|
||||
"""Open a question box."""
|
||||
@@ -443,8 +422,7 @@ class SharedData(QObject):
|
||||
alert.setAlertType(_GuiAlert.WARN if warn else _GuiAlert.ASK, True)
|
||||
self._lastAlert = alert.logMessage
|
||||
alert.exec()
|
||||
isYes = alert.result() == QMessageBox.StandardButton.Yes
|
||||
return isYes
|
||||
return alert.result() == QMessageBox.StandardButton.Yes
|
||||
|
||||
##
|
||||
# Internal Functions
|
||||
@@ -454,7 +432,6 @@ class SharedData(QObject):
|
||||
"""Print message to log."""
|
||||
for text in message.split("<br>"):
|
||||
log(RX_HTML.sub("", text), stacklevel=3)
|
||||
return
|
||||
|
||||
def _resetProject(self) -> None:
|
||||
"""Create a new project and spell checking instance."""
|
||||
@@ -467,13 +444,11 @@ class SharedData(QObject):
|
||||
self._spelling = NWSpellEnchant(self._project)
|
||||
self.updateSpellCheckLanguage()
|
||||
self._focusMode = False
|
||||
return
|
||||
|
||||
def _resetIdleTimer(self) -> None:
|
||||
"""Reset the timer data for the idle timer."""
|
||||
self._idleRefTime = time()
|
||||
self._idleTime = 0.0
|
||||
return
|
||||
|
||||
def _closeToolDialogs(self) -> None:
|
||||
"""Close all open tool dialogs."""
|
||||
@@ -481,7 +456,6 @@ class SharedData(QObject):
|
||||
for widget in self.mainGui.children():
|
||||
if isinstance(widget, NToolDialog):
|
||||
widget.close()
|
||||
return
|
||||
|
||||
|
||||
class _GuiAlert(QMessageBox):
|
||||
@@ -496,11 +470,9 @@ class _GuiAlert(QMessageBox):
|
||||
self._theme = theme
|
||||
self._message = ""
|
||||
logger.debug("Ready: _GuiAlert")
|
||||
return
|
||||
|
||||
def __del__(self) -> None: # pragma: no cover
|
||||
logger.debug("Delete: _GuiAlert")
|
||||
return
|
||||
|
||||
@property
|
||||
def logMessage(self) -> str:
|
||||
@@ -512,14 +484,12 @@ class _GuiAlert(QMessageBox):
|
||||
self.setText(text)
|
||||
self.setInformativeText(info)
|
||||
self.setDetailedText(details)
|
||||
return
|
||||
|
||||
def setException(self, exception: Exception) -> None:
|
||||
"""Add exception details."""
|
||||
info = self.informativeText()
|
||||
text = f"<b>{type(exception).__name__}</b>: {exception!s}"
|
||||
self.setInformativeText(f"{info}<br>{text}" if info else text)
|
||||
return
|
||||
|
||||
def setAlertType(self, level: int, isYesNo: bool) -> None:
|
||||
"""Set the type of alert and whether the dialog should have
|
||||
@@ -542,4 +512,3 @@ class _GuiAlert(QMessageBox):
|
||||
elif level == self.ASK:
|
||||
self.setIconPixmap(self._theme.getPixmap("alert_question", (pSz, pSz), "blue"))
|
||||
self.setWindowTitle(self.tr("Question"))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user