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