Use an enum to pass values to the status bar LEDs

This commit is contained in:
Veronica K. B. Olsen
2021-05-16 16:43:44 +02:00
parent e9ef4fd091
commit 0cad96fdca
4 changed files with 32 additions and 22 deletions
+1 -1
View File
@@ -1109,7 +1109,7 @@ class NWProject():
information to the GUI statusbar.
"""
self.projChanged = bValue
self.theParent.setProjectStatus(self.projChanged)
self.theParent.statusBar.doUpdateProjectStatus(bValue)
if bValue:
# If we've changed the project at all, this should be True
self.projAltered = True
+8
View File
@@ -112,6 +112,14 @@ class nwAlert(Enum):
# END Enum nwAlert
class nwState(Enum):
NONE = 0
BAD = 1
GOOD = 2
# END Enum nwState
class nwWidget(Enum):
TREE = 1
+20 -18
View File
@@ -34,6 +34,7 @@ from PyQt5.QtGui import QColor, QPainter
from PyQt5.QtWidgets import qApp, QStatusBar, QLabel, QAbstractButton
from nw.common import formatTime
from nw.enum import nwState
logger = logging.getLogger(__name__)
@@ -125,8 +126,8 @@ class GuiMainStatus(QStatusBar):
self.setRefTime(None)
self.setLanguage(None, "")
self.setStats(0, 0)
self.setProjectStatus(None)
self.setDocumentStatus(None)
self.setProjectStatus(nwState.NONE)
self.setDocumentStatus(nwState.NONE)
self.updateTime()
return True
@@ -147,16 +148,16 @@ class GuiMainStatus(QStatusBar):
qApp.processEvents()
return
def setProjectStatus(self, isChanged):
def setProjectStatus(self, theState):
"""Set the project status colour icon.
"""
self.projIcon.setState(isChanged)
self.projIcon.setState(theState)
return
def setDocumentStatus(self, isChanged):
def setDocumentStatus(self, theState):
"""Set the document status colour icon.
"""
self.docIcon.setState(isChanged)
self.docIcon.setState(theState)
return
def setStats(self, pWC, sWC):
@@ -221,26 +222,26 @@ class GuiMainStatus(QStatusBar):
def doUpdateProjectStatus(self, isChanged):
"""Slot for updating the project status.
"""
self.setProjectStatus(isChanged)
self.setProjectStatus(nwState.GOOD if isChanged else nwState.BAD)
return
@pyqtSlot(bool)
def doUpdateDocumentStatus(self, isChanged):
"""Slot for updating the document status.
"""
self.setDocumentStatus(isChanged)
self.setDocumentStatus(nwState.GOOD if isChanged else nwState.BAD)
return
# END Class GuiMainStatus
class StatusLED(QAbstractButton):
def __init__(self, colNone, colTrue, colFalse, sW, sH, parent=None):
def __init__(self, colNone, colGood, colBad, sW, sH, parent=None):
super().__init__(parent=parent)
self.colNone = colNone
self.colTrue = colTrue
self.colFalse = colFalse
self._colNone = colNone
self._colGood = colGood
self._colBad = colBad
self._theCol = colNone
self.setFixedWidth(sW)
@@ -255,11 +256,12 @@ class StatusLED(QAbstractButton):
def setState(self, theState):
"""Set the colour state.
"""
self._theCol = self.colNone
if theState is True:
self._theCol = self.colTrue
elif theState is False:
self._theCol = self.colFalse
if theState == nwState.GOOD:
self._theCol = self._colGood
elif theState == nwState.BAD:
self._theCol = self._colBad
else:
self._theCol = self._colNone
self.update()
@@ -269,7 +271,7 @@ class StatusLED(QAbstractButton):
# Events
##
def paintEvent(self, event):
def paintEvent(self, _):
"""Drawing the LED.
"""
qPalette = self.palette()
+3 -3
View File
@@ -49,7 +49,7 @@ from nw.dialogs import (
)
from nw.tools import GuiBuildNovel, GuiProjectWizard, GuiWritingStats
from nw.core import NWProject, NWIndex
from nw.enum import nwItemType, nwItemClass, nwAlert, nwWidget
from nw.enum import nwItemType, nwItemClass, nwAlert, nwWidget, nwState
from nw.common import getGuiItem, hexToInt
from nw.constants import nwLists
@@ -381,8 +381,8 @@ class GuiMain(QMainWindow):
self.docEditor.setDictionaries()
self.rebuildIndex(beQuiet=True)
self.statusBar.setRefTime(self.theProject.projOpened)
self.statusBar.setProjectStatus(True)
self.statusBar.setDocumentStatus(None)
self.statusBar.setProjectStatus(nwState.GOOD)
self.statusBar.setDocumentStatus(nwState.NONE)
self.statusBar.setStatus(self.tr("New project created ..."))
self._updateWindowTitle(self.theProject.projName)
else: