From 250a41a84a04499dbeb883e98946c87abe42674c Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Fri, 18 Nov 2022 00:19:15 +0100 Subject: [PATCH] Move StatusLED class to new components module --- novelwriter/gui/components.py | 87 +++++++++++++++++++++++++++++++++++ novelwriter/gui/statusbar.py | 61 ++---------------------- 2 files changed, 90 insertions(+), 58 deletions(-) create mode 100644 novelwriter/gui/components.py diff --git a/novelwriter/gui/components.py b/novelwriter/gui/components.py new file mode 100644 index 00000000..dac50d28 --- /dev/null +++ b/novelwriter/gui/components.py @@ -0,0 +1,87 @@ +""" +novelWriter – GUI Components Module +=================================== +A module of various small GUI components + +File History: +Created: 2020-05-17 [0.5.1] StatusLED + +This file is a part of novelWriter +Copyright 2018–2022, Veronica Berglyd Olsen + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +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 . +""" + +import logging + +from PyQt5.QtGui import QPainter +from PyQt5.QtWidgets import QAbstractButton + +logger = logging.getLogger(__name__) + + +class StatusLED(QAbstractButton): + + S_NONE = 0 + S_BAD = 1 + S_GOOD = 2 + + def __init__(self, colNone, colGood, colBad, sW, sH, parent=None): + super().__init__(parent=parent) + + self._colNone = colNone + self._colGood = colGood + self._colBad = colBad + self._theCol = colNone + + self.setFixedWidth(sW) + self.setFixedHeight(sH) + + return + + ## + # Setters + ## + + def setState(self, theState): + """Set the colour state. + """ + if theState == self.S_GOOD: + self._theCol = self._colGood + elif theState == self.S_BAD: + self._theCol = self._colBad + else: + self._theCol = self._colNone + + self.update() + + return + + ## + # Events + ## + + def paintEvent(self, _): + """Drawing the LED. + """ + qPalette = self.palette() + qPaint = QPainter(self) + qPaint.setRenderHint(QPainter.Antialiasing, True) + qPaint.setPen(qPalette.dark().color()) + qPaint.setBrush(self._theCol) + qPaint.setOpacity(1.0) + qPaint.drawEllipse(1, 1, self.width() - 2, self.height() - 2) + return + +# END Class StatusLED diff --git a/novelwriter/gui/statusbar.py b/novelwriter/gui/statusbar.py index 9dcb97af..a5824214 100644 --- a/novelwriter/gui/statusbar.py +++ b/novelwriter/gui/statusbar.py @@ -30,10 +30,11 @@ import novelwriter from time import time from PyQt5.QtCore import pyqtSlot, QLocale -from PyQt5.QtGui import QColor, QPainter -from PyQt5.QtWidgets import qApp, QStatusBar, QLabel, QAbstractButton +from PyQt5.QtGui import QColor +from PyQt5.QtWidgets import qApp, QStatusBar, QLabel from novelwriter.common import formatTime +from novelwriter.gui.components import StatusLED logger = logging.getLogger(__name__) @@ -246,59 +247,3 @@ class GuiMainStatus(QStatusBar): return # END Class GuiMainStatus - - -class StatusLED(QAbstractButton): - - S_NONE = 0 - S_BAD = 1 - S_GOOD = 2 - - def __init__(self, colNone, colGood, colBad, sW, sH, parent=None): - super().__init__(parent=parent) - - self._colNone = colNone - self._colGood = colGood - self._colBad = colBad - self._theCol = colNone - - self.setFixedWidth(sW) - self.setFixedHeight(sH) - - return - - ## - # Setters - ## - - def setState(self, theState): - """Set the colour state. - """ - if theState == self.S_GOOD: - self._theCol = self._colGood - elif theState == self.S_BAD: - self._theCol = self._colBad - else: - self._theCol = self._colNone - - self.update() - - return - - ## - # Events - ## - - def paintEvent(self, _): - """Drawing the LED. - """ - qPalette = self.palette() - qPaint = QPainter(self) - qPaint.setRenderHint(QPainter.Antialiasing, True) - qPaint.setPen(qPalette.dark().color()) - qPaint.setBrush(self._theCol) - qPaint.setOpacity(1.0) - qPaint.drawEllipse(1, 1, self.width() - 2, self.height() - 2) - return - -# END Class StatusLED