Use a signal for status bar messages
This commit is contained in:
@@ -71,9 +71,10 @@ class GuiDocEditor(QTextEdit):
|
||||
)
|
||||
|
||||
# Custom Signals
|
||||
spellDictionaryChanged = pyqtSignal(str, str)
|
||||
docEditedStatusChanged = pyqtSignal(bool)
|
||||
statusMessage = pyqtSignal(str)
|
||||
docCountsChanged = pyqtSignal(str, int, int, int)
|
||||
editedStatusChanged = pyqtSignal(bool)
|
||||
spellDictionaryChanged = pyqtSignal(str, str)
|
||||
loadDocumentTagRequest = pyqtSignal(str, Enum)
|
||||
novelStructureChanged = pyqtSignal()
|
||||
novelItemMetaChanged = pyqtSignal(str)
|
||||
@@ -454,9 +455,7 @@ class GuiDocEditor(QTextEdit):
|
||||
|
||||
# Update the status bar
|
||||
if self._nwItem is not None:
|
||||
self.mainGui.setStatus(
|
||||
self.tr("Opened Document: {0}").format(self._nwItem.itemName)
|
||||
)
|
||||
self.statusMessage.emit(self.tr("Opened Document: {0}").format(self._nwItem.itemName))
|
||||
|
||||
return True
|
||||
|
||||
@@ -562,9 +561,7 @@ class GuiDocEditor(QTextEdit):
|
||||
self.docFooter.updateInfo()
|
||||
|
||||
# Update the status bar
|
||||
self.mainGui.setStatus(
|
||||
self.tr("Saved Document: {0}").format(self._nwItem.itemName)
|
||||
)
|
||||
self.statusMessage.emit(self.tr("Saved Document: {0}").format(self._nwItem.itemName))
|
||||
|
||||
return True
|
||||
|
||||
@@ -639,7 +636,7 @@ class GuiDocEditor(QTextEdit):
|
||||
document change signal.
|
||||
"""
|
||||
self._docChanged = bValue
|
||||
self.docEditedStatusChanged.emit(self._docChanged)
|
||||
self.editedStatusChanged.emit(self._docChanged)
|
||||
return self._docChanged
|
||||
|
||||
def setCursorPosition(self, position):
|
||||
@@ -747,7 +744,7 @@ class GuiDocEditor(QTextEdit):
|
||||
|
||||
return True
|
||||
|
||||
def spellCheckDocument(self):
|
||||
def spellCheckDocument(self) -> None:
|
||||
"""Rerun the highlighter to update spell checking status of the
|
||||
currently loaded text. The fastest way to do this, at least as
|
||||
of Qt 5.13, is to clear the text and put it back. This clears
|
||||
@@ -763,9 +760,8 @@ class GuiDocEditor(QTextEdit):
|
||||
self.highLight.rehighlight()
|
||||
qApp.restoreOverrideCursor()
|
||||
logger.debug("Document highlighted in %.3f ms", 1000*(time() - start))
|
||||
self.mainGui.mainStatus.setStatus(self.tr("Spell check complete"))
|
||||
|
||||
return True
|
||||
self.statusMessage.emit(self.tr("Spell check complete"))
|
||||
return
|
||||
|
||||
##
|
||||
# General Class Methods
|
||||
|
||||
@@ -27,6 +27,7 @@ from __future__ import annotations
|
||||
import logging
|
||||
|
||||
from time import time
|
||||
from typing import TYPE_CHECKING, Literal
|
||||
|
||||
from PyQt5.QtCore import pyqtSlot, QLocale
|
||||
from PyQt5.QtGui import QColor
|
||||
@@ -34,21 +35,24 @@ from PyQt5.QtWidgets import qApp, QStatusBar, QLabel
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.common import formatTime
|
||||
from novelwriter.constants import nwConst
|
||||
from novelwriter.extensions.statusled import StatusLED
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from novelwriter.guimain import GuiMain
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class GuiMainStatus(QStatusBar):
|
||||
|
||||
def __init__(self, mainGui):
|
||||
def __init__(self, mainGui: GuiMain) -> None:
|
||||
super().__init__(parent=mainGui)
|
||||
|
||||
logger.debug("Create: GuiMainStatus")
|
||||
|
||||
self.mainGui = mainGui
|
||||
self.refTime = None
|
||||
self.userIdle = False
|
||||
self._refTime = -1.0
|
||||
self._userIdle = False
|
||||
|
||||
colNone = QColor(*SHARED.theme.statNone)
|
||||
colSaved = QColor(*SHARED.theme.statSaved)
|
||||
@@ -114,80 +118,59 @@ class GuiMainStatus(QStatusBar):
|
||||
|
||||
return
|
||||
|
||||
def clearStatus(self):
|
||||
"""Reset all widgets on the status bar to default values.
|
||||
"""
|
||||
self.setRefTime(None)
|
||||
def clearStatus(self) -> None:
|
||||
"""Reset all widgets on the status bar to default values."""
|
||||
self.setRefTime(-1.0)
|
||||
self.setLanguage(None, "")
|
||||
self.setProjectStats(0, 0)
|
||||
self.setProjectStatus(StatusLED.S_NONE)
|
||||
self.setDocumentStatus(StatusLED.S_NONE)
|
||||
self.updateTime()
|
||||
return True
|
||||
return
|
||||
|
||||
def updateTheme(self):
|
||||
"""Update theme elements.
|
||||
"""
|
||||
def updateTheme(self) -> None:
|
||||
"""Update theme elements."""
|
||||
iPx = SHARED.theme.baseIconSize
|
||||
|
||||
self.langIcon.setPixmap(SHARED.theme.getPixmap("status_lang", (iPx, iPx)))
|
||||
self.statsIcon.setPixmap(SHARED.theme.getPixmap("status_stats", (iPx, iPx)))
|
||||
|
||||
self.timePixmap = SHARED.theme.getPixmap("status_time", (iPx, iPx))
|
||||
self.idlePixmap = SHARED.theme.getPixmap("status_idle", (iPx, iPx))
|
||||
|
||||
self.timeIcon.setPixmap(self.timePixmap)
|
||||
|
||||
return
|
||||
|
||||
##
|
||||
# Setters
|
||||
##
|
||||
|
||||
def setRefTime(self, theTime):
|
||||
"""Set the reference time for the status bar clock.
|
||||
"""
|
||||
self.refTime = theTime
|
||||
def setRefTime(self, refTime: float) -> None:
|
||||
"""Set the reference time for the status bar clock."""
|
||||
self._refTime = refTime
|
||||
return
|
||||
|
||||
def setStatus(self, theMessage, timeOut=20.0):
|
||||
"""Set the status bar message to display for 'timeOut' seconds.
|
||||
"""
|
||||
self.showMessage(theMessage, int(timeOut*1000))
|
||||
qApp.processEvents()
|
||||
def setProjectStatus(self, state: Literal[0, 1, 2]) -> None:
|
||||
"""Set the project status colour icon."""
|
||||
self.projIcon.setState(state)
|
||||
return
|
||||
|
||||
def setProjectStatus(self, theState):
|
||||
"""Set the project status colour icon.
|
||||
"""
|
||||
self.projIcon.setState(theState)
|
||||
def setDocumentStatus(self, state: Literal[0, 1, 2]) -> None:
|
||||
"""Set the document status colour icon."""
|
||||
self.docIcon.setState(state)
|
||||
return
|
||||
|
||||
def setDocumentStatus(self, theState):
|
||||
"""Set the document status colour icon.
|
||||
"""
|
||||
self.docIcon.setState(theState)
|
||||
return
|
||||
|
||||
def setUserIdle(self, userIdle):
|
||||
"""Change the idle status icon.
|
||||
"""
|
||||
def setUserIdle(self, idle: bool) -> None:
|
||||
"""Change the idle status icon."""
|
||||
if not CONFIG.stopWhenIdle:
|
||||
userIdle = False
|
||||
|
||||
if self.userIdle != userIdle:
|
||||
if userIdle:
|
||||
idle = False
|
||||
if self._userIdle != idle:
|
||||
if idle:
|
||||
self.timeIcon.setPixmap(self.idlePixmap)
|
||||
else:
|
||||
self.timeIcon.setPixmap(self.timePixmap)
|
||||
|
||||
self.userIdle = userIdle
|
||||
|
||||
self._userIdle = idle
|
||||
return
|
||||
|
||||
def setProjectStats(self, pWC, sWC):
|
||||
"""Update the current project statistics.
|
||||
"""
|
||||
def setProjectStats(self, pWC: int, sWC: int) -> None:
|
||||
"""Update the current project statistics."""
|
||||
self.statsText.setText(self.tr("Words: {0} ({1})").format(f"{pWC:n}", f"{sWC:+n}"))
|
||||
if CONFIG.incNotesWCount:
|
||||
self.statsText.setToolTip(self.tr("Project word count (session change)"))
|
||||
@@ -195,53 +178,55 @@ class GuiMainStatus(QStatusBar):
|
||||
self.statsText.setToolTip(self.tr("Novel word count (session change)"))
|
||||
return
|
||||
|
||||
def updateTime(self, idleTime=0.0):
|
||||
"""Update the session clock.
|
||||
"""
|
||||
if self.refTime is None:
|
||||
def updateTime(self, idleTime: float = 0.0) -> None:
|
||||
"""Update the session clock."""
|
||||
if self._refTime < 0.0:
|
||||
self.timeText.setText("00:00:00")
|
||||
else:
|
||||
if CONFIG.stopWhenIdle:
|
||||
sessTime = round(time() - self.refTime - idleTime)
|
||||
sessTime = round(time() - self._refTime - idleTime)
|
||||
else:
|
||||
sessTime = round(time() - self.refTime)
|
||||
sessTime = round(time() - self._refTime)
|
||||
self.timeText.setText(formatTime(sessTime))
|
||||
return
|
||||
|
||||
##
|
||||
# Slots
|
||||
# Public Slots
|
||||
##
|
||||
|
||||
@pyqtSlot(str)
|
||||
def setStatusMessage(self, message: str) -> None:
|
||||
"""Set the status bar message to display."""
|
||||
self.showMessage(message, nwConst.STATUS_MSG_TIMEOUT)
|
||||
qApp.processEvents()
|
||||
return
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
def setLanguage(self, theLanguage, theProvider):
|
||||
"""Set the language code for the spell checker.
|
||||
"""
|
||||
if theLanguage == "None":
|
||||
def setLanguage(self, language: str, provider: str) -> None:
|
||||
"""Set the language code for the spell checker."""
|
||||
if language == "None":
|
||||
self.langText.setText(self.tr("None"))
|
||||
self.langText.setToolTip("")
|
||||
else:
|
||||
qLocal = QLocale(theLanguage)
|
||||
qLocal = QLocale(language)
|
||||
spLang = qLocal.nativeLanguageName().title()
|
||||
self.langText.setText(spLang)
|
||||
if theProvider:
|
||||
self.langText.setToolTip("%s (%s)" % (theLanguage, theProvider))
|
||||
if provider:
|
||||
self.langText.setToolTip("%s (%s)" % (language, provider))
|
||||
else:
|
||||
self.langText.setToolTip(theLanguage)
|
||||
|
||||
self.langText.setToolTip(language)
|
||||
return
|
||||
|
||||
@pyqtSlot(bool)
|
||||
def doUpdateProjectStatus(self, isChanged):
|
||||
"""Slot for updating the project status.
|
||||
"""
|
||||
self.setProjectStatus(StatusLED.S_BAD if isChanged else StatusLED.S_GOOD)
|
||||
def updateProjectStatus(self, status: bool) -> None:
|
||||
"""Update the project status."""
|
||||
self.setProjectStatus(StatusLED.S_BAD if status else StatusLED.S_GOOD)
|
||||
return
|
||||
|
||||
@pyqtSlot(bool)
|
||||
def doUpdateDocumentStatus(self, isChanged):
|
||||
"""Slot for updating the document status.
|
||||
"""
|
||||
self.setDocumentStatus(StatusLED.S_BAD if isChanged else StatusLED.S_GOOD)
|
||||
def updateDocumentStatus(self, status: bool) -> None:
|
||||
"""Update the document status."""
|
||||
self.setDocumentStatus(StatusLED.S_BAD if status else StatusLED.S_GOOD)
|
||||
return
|
||||
|
||||
# END Class GuiMainStatus
|
||||
|
||||
Reference in New Issue
Block a user