Sort out status leds and project closing (#1237)
This commit is contained in:
@@ -130,15 +130,6 @@ class nwAlert(Enum):
|
|||||||
# END Enum nwAlert
|
# END Enum nwAlert
|
||||||
|
|
||||||
|
|
||||||
class nwState(Enum):
|
|
||||||
|
|
||||||
NONE = 0
|
|
||||||
BAD = 1
|
|
||||||
GOOD = 2
|
|
||||||
|
|
||||||
# END Enum nwState
|
|
||||||
|
|
||||||
|
|
||||||
class nwView(Enum):
|
class nwView(Enum):
|
||||||
|
|
||||||
EDITOR = 0
|
EDITOR = 0
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ from PyQt5.QtGui import QColor, QPainter
|
|||||||
from PyQt5.QtWidgets import qApp, QStatusBar, QLabel, QAbstractButton
|
from PyQt5.QtWidgets import qApp, QStatusBar, QLabel, QAbstractButton
|
||||||
|
|
||||||
from novelwriter.common import formatTime
|
from novelwriter.common import formatTime
|
||||||
from novelwriter.enum import nwState
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -53,8 +52,8 @@ class GuiMainStatus(QStatusBar):
|
|||||||
self.userIdle = False
|
self.userIdle = False
|
||||||
|
|
||||||
colNone = QColor(*self.mainTheme.statNone)
|
colNone = QColor(*self.mainTheme.statNone)
|
||||||
colTrue = QColor(*self.mainTheme.statUnsaved)
|
colSaved = QColor(*self.mainTheme.statSaved)
|
||||||
colFalse = QColor(*self.mainTheme.statSaved)
|
colUnsaved = QColor(*self.mainTheme.statUnsaved)
|
||||||
|
|
||||||
iPx = self.mainTheme.baseIconSize
|
iPx = self.mainTheme.baseIconSize
|
||||||
|
|
||||||
@@ -72,7 +71,7 @@ class GuiMainStatus(QStatusBar):
|
|||||||
self.addPermanentWidget(self.langText)
|
self.addPermanentWidget(self.langText)
|
||||||
|
|
||||||
# The Editor Status
|
# The Editor Status
|
||||||
self.docIcon = StatusLED(colNone, colTrue, colFalse, iPx, iPx, self)
|
self.docIcon = StatusLED(colNone, colSaved, colUnsaved, iPx, iPx, self)
|
||||||
self.docText = QLabel(self.tr("Editor"))
|
self.docText = QLabel(self.tr("Editor"))
|
||||||
self.docIcon.setContentsMargins(0, 0, 0, 0)
|
self.docIcon.setContentsMargins(0, 0, 0, 0)
|
||||||
self.docText.setContentsMargins(0, 0, xM, 0)
|
self.docText.setContentsMargins(0, 0, xM, 0)
|
||||||
@@ -80,7 +79,7 @@ class GuiMainStatus(QStatusBar):
|
|||||||
self.addPermanentWidget(self.docText)
|
self.addPermanentWidget(self.docText)
|
||||||
|
|
||||||
# The Project Status
|
# The Project Status
|
||||||
self.projIcon = StatusLED(colNone, colTrue, colFalse, iPx, iPx, self)
|
self.projIcon = StatusLED(colNone, colSaved, colUnsaved, iPx, iPx, self)
|
||||||
self.projText = QLabel(self.tr("Project"))
|
self.projText = QLabel(self.tr("Project"))
|
||||||
self.projIcon.setContentsMargins(0, 0, 0, 0)
|
self.projIcon.setContentsMargins(0, 0, 0, 0)
|
||||||
self.projText.setContentsMargins(0, 0, xM, 0)
|
self.projText.setContentsMargins(0, 0, xM, 0)
|
||||||
@@ -122,8 +121,8 @@ class GuiMainStatus(QStatusBar):
|
|||||||
self.setRefTime(None)
|
self.setRefTime(None)
|
||||||
self.setLanguage(None, "")
|
self.setLanguage(None, "")
|
||||||
self.setProjectStats(0, 0)
|
self.setProjectStats(0, 0)
|
||||||
self.setProjectStatus(nwState.NONE)
|
self.setProjectStatus(StatusLED.S_NONE)
|
||||||
self.setDocumentStatus(nwState.NONE)
|
self.setDocumentStatus(StatusLED.S_NONE)
|
||||||
self.updateTime()
|
self.updateTime()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -236,14 +235,14 @@ 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(nwState.GOOD if isChanged else nwState.BAD)
|
self.setProjectStatus(StatusLED.S_BAD if isChanged else StatusLED.S_GOOD)
|
||||||
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(nwState.GOOD if isChanged else nwState.BAD)
|
self.setDocumentStatus(StatusLED.S_BAD if isChanged else StatusLED.S_GOOD)
|
||||||
return
|
return
|
||||||
|
|
||||||
# END Class GuiMainStatus
|
# END Class GuiMainStatus
|
||||||
@@ -251,6 +250,10 @@ class GuiMainStatus(QStatusBar):
|
|||||||
|
|
||||||
class StatusLED(QAbstractButton):
|
class StatusLED(QAbstractButton):
|
||||||
|
|
||||||
|
S_NONE = 0
|
||||||
|
S_BAD = 1
|
||||||
|
S_GOOD = 2
|
||||||
|
|
||||||
def __init__(self, colNone, colGood, colBad, sW, sH, parent=None):
|
def __init__(self, colNone, colGood, colBad, sW, sH, parent=None):
|
||||||
super().__init__(parent=parent)
|
super().__init__(parent=parent)
|
||||||
|
|
||||||
@@ -271,9 +274,9 @@ class StatusLED(QAbstractButton):
|
|||||||
def setState(self, theState):
|
def setState(self, theState):
|
||||||
"""Set the colour state.
|
"""Set the colour state.
|
||||||
"""
|
"""
|
||||||
if theState == nwState.GOOD:
|
if theState == self.S_GOOD:
|
||||||
self._theCol = self._colGood
|
self._theCol = self._colGood
|
||||||
elif theState == nwState.BAD:
|
elif theState == self.S_BAD:
|
||||||
self._theCol = self._colBad
|
self._theCol = self._colBad
|
||||||
else:
|
else:
|
||||||
self._theCol = self._colNone
|
self._theCol = self._colNone
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ class GuiMain(QMainWindow):
|
|||||||
# Work Area
|
# Work Area
|
||||||
self.docEditor.clearEditor()
|
self.docEditor.clearEditor()
|
||||||
self.docEditor.setDictionaries()
|
self.docEditor.setDictionaries()
|
||||||
self.closeDocViewer()
|
self.closeDocViewer(byUser=False)
|
||||||
self.outlineView.clearProject()
|
self.outlineView.clearProject()
|
||||||
|
|
||||||
# General
|
# General
|
||||||
@@ -1220,14 +1220,19 @@ class GuiMain(QMainWindow):
|
|||||||
self.theProject.data.setLastHandle(None, "editor")
|
self.theProject.data.setLastHandle(None, "editor")
|
||||||
return
|
return
|
||||||
|
|
||||||
def closeDocViewer(self):
|
def closeDocViewer(self, byUser=True):
|
||||||
"""Close the document view panel.
|
"""Close the document view panel.
|
||||||
"""
|
"""
|
||||||
self.docViewer.clearViewer()
|
self.docViewer.clearViewer()
|
||||||
self.theProject.data.setLastHandle(None, "viewer")
|
if byUser:
|
||||||
|
# Only reset the last handle if the user called this
|
||||||
|
self.theProject.data.setLastHandle(None, "viewer")
|
||||||
|
|
||||||
|
# Hide the panel
|
||||||
bPos = self.splitMain.sizes()
|
bPos = self.splitMain.sizes()
|
||||||
self.splitView.setVisible(False)
|
self.splitView.setVisible(False)
|
||||||
self.splitDocs.setSizes([bPos[1], 0])
|
self.splitDocs.setSizes([bPos[1], 0])
|
||||||
|
|
||||||
return not self.splitView.isVisible()
|
return not self.splitView.isVisible()
|
||||||
|
|
||||||
def toggleFocusMode(self):
|
def toggleFocusMode(self):
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import pytest
|
|||||||
|
|
||||||
from tools import C, buildTestProject
|
from tools import C, buildTestProject
|
||||||
|
|
||||||
from novelwriter.enum import nwState
|
from novelwriter.gui.statusbar import StatusLED
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.gui
|
@pytest.mark.gui
|
||||||
@@ -44,19 +44,19 @@ def testGuiStatusBar_Main(qtbot, nwGUI, projPath, mockRnd):
|
|||||||
assert nwGUI.mainStatus.refTime == refTime
|
assert nwGUI.mainStatus.refTime == refTime
|
||||||
|
|
||||||
# Project Status
|
# Project Status
|
||||||
nwGUI.mainStatus.setProjectStatus(nwState.NONE)
|
nwGUI.mainStatus.setProjectStatus(StatusLED.S_NONE)
|
||||||
assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colNone
|
assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colNone
|
||||||
nwGUI.mainStatus.setProjectStatus(nwState.BAD)
|
nwGUI.mainStatus.setProjectStatus(StatusLED.S_BAD)
|
||||||
assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colBad
|
assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colBad
|
||||||
nwGUI.mainStatus.setProjectStatus(nwState.GOOD)
|
nwGUI.mainStatus.setProjectStatus(StatusLED.S_GOOD)
|
||||||
assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colGood
|
assert nwGUI.mainStatus.projIcon._theCol == nwGUI.mainStatus.projIcon._colGood
|
||||||
|
|
||||||
# Document Status
|
# Document Status
|
||||||
nwGUI.mainStatus.setDocumentStatus(nwState.NONE)
|
nwGUI.mainStatus.setDocumentStatus(StatusLED.S_NONE)
|
||||||
assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colNone
|
assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colNone
|
||||||
nwGUI.mainStatus.setDocumentStatus(nwState.BAD)
|
nwGUI.mainStatus.setDocumentStatus(StatusLED.S_BAD)
|
||||||
assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colBad
|
assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colBad
|
||||||
nwGUI.mainStatus.setDocumentStatus(nwState.GOOD)
|
nwGUI.mainStatus.setDocumentStatus(StatusLED.S_GOOD)
|
||||||
assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colGood
|
assert nwGUI.mainStatus.docIcon._theCol == nwGUI.mainStatus.docIcon._colGood
|
||||||
|
|
||||||
# Idle Status
|
# Idle Status
|
||||||
|
|||||||
Reference in New Issue
Block a user