--- a/eric6/E5Gui/E5Led.py Tue Apr 27 17:42:00 2021 +0200 +++ b/eric6/E5Gui/E5Led.py Wed Apr 28 19:42:28 2021 +0200 @@ -9,27 +9,38 @@ It was inspired by KLed. """ +import enum + from PyQt5.QtCore import pyqtSignal, Qt, QSize, QPoint from PyQt5.QtGui import QColor, QRadialGradient, QPalette, QPainter, QBrush from PyQt5.QtWidgets import QWidget -E5LedRectangular = 0 -E5LedCircular = 1 + +class E5LedType(enum.Enum): + """ + Class defining the LED types. + """ + RECTANGULAR = 0 + CIRCULAR = 1 class E5Led(QWidget): """ Class implementing a LED widget. """ - def __init__(self, parent=None, color=None, shape=E5LedCircular, + def __init__(self, parent=None, color=None, shape=E5LedType.CIRCULAR, rectRatio=1): """ Constructor - @param parent reference to parent widget (QWidget) - @param color color of the LED (QColor) - @param shape shape of the LED (E5LedCircular, E5LedRectangular) - @param rectRatio ratio width to height, if shape is rectangular (float) + @param parent reference to parent widget + @type QWidget + @param color color of the LED + @type QColor + @param shape shape of the LED + @type E5LedType + @param rectRatio ratio width to height, if shape is rectangular + @type float """ super().__init__(parent) @@ -52,14 +63,10 @@ @param evt paint event object @type QPaintEvent - @exception TypeError The E5Led has an unsupported shape type. """ - if self.__shape not in (E5LedCircular, E5LedRectangular): - raise TypeError("Unsupported shape type for E5Led.") - - if self.__shape == E5LedCircular: + if self.__shape == E5LedType.CIRCULAR: self.__paintRound() - elif self.__shape == E5LedRectangular: + elif self.__shape == E5LedType.RECTANGULAR: self.__paintRectangular() def __getBestRoundSize(self): @@ -139,7 +146,8 @@ """ Public method to return the LED shape. - @return LED shape (E5LedCircular, E5LedRectangular) + @return LED shape + @rtype E5LedType """ return self.__shape @@ -173,7 +181,8 @@ """ Public method to set the LED shape. - @param shape new LED shape (E5LedCircular, E5LedRectangular) + @param shape new LED shape + @type E5LedType """ if self.__shape != shape: self.__shape = shape @@ -286,15 +295,19 @@ clicked = pyqtSignal(QPoint) middleClicked = pyqtSignal(QPoint) - def __init__(self, parent=None, color=None, shape=E5LedCircular, + def __init__(self, parent=None, color=None, shape=E5LedType.CIRCULAR, rectRatio=1): """ Constructor - @param parent reference to parent widget (QWidget) - @param color color of the LED (QColor) - @param shape shape of the LED (E5LedCircular, E5LedRectangular) - @param rectRatio ratio width to height, if shape is rectangular (float) + @param parent reference to parent widget + @type QWidget + @param color color of the LED + @type QColor + @param shape shape of the LED + @type E5LedType + @param rectRatio ratio width to height, if shape is rectangular + @type float """ super().__init__(parent, color, shape, rectRatio)