Skip to content

Commit 8fb9e0b

Browse files
committed
Add docstring
1 parent df99ae8 commit 8fb9e0b

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

BlocksScreen/lib/utils/display_button.py

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55

66
class DisplayButton(QtWidgets.QPushButton):
7-
def __init__(
8-
self, parent: typing.Optional["QtWidgets.QWidget"] = None
9-
) -> None:
7+
def __init__(self, parent: typing.Optional["QtWidgets.QWidget"] = None) -> None:
108
if parent:
119
super().__init__(parent=parent)
1210
else:
@@ -19,22 +17,23 @@ def __init__(
1917
self._text: str = ""
2018
self._secondary_text: str = ""
2119
self._name: str = ""
22-
self.display_format: typing.Literal["normal", "upper_downer"] = (
23-
"normal"
24-
)
20+
self.display_format: typing.Literal["normal", "upper_downer"] = "normal"
2521
self.text_color: QtGui.QColor = QtGui.QColor(0, 0, 0)
2622
self.setAttribute(QtCore.Qt.WidgetAttribute.WA_AcceptTouchEvents, True)
2723

2824
@property
2925
def name(self):
26+
"""Widget name"""
3027
return self._name
3128

3229
def setPixmap(self, pixmap: QtGui.QPixmap) -> None:
30+
"""Set widget pixmap"""
3331
self.icon_pixmap = pixmap
3432
self.repaint()
3533

3634
@property
3735
def button_type(self) -> str:
36+
"""Widget button type"""
3837
return self._button_type
3938

4039
@button_type.setter
@@ -44,29 +43,28 @@ def button_type(self, type) -> None:
4443
self._button_type = type
4544

4645
def text(self) -> str:
46+
"""Widget text"""
4747
return self._text
4848

4949
def setText(self, text: str) -> None:
50+
"""Set widget text"""
5051
self._text = text
5152
self.update()
5253
super().setText(text)
5354

5455
@property
5556
def secondary_text(self) -> str:
57+
"""Widget secondary text"""
5658
return self._secondary_text
5759

5860
@secondary_text.setter
5961
def secondary_text(self, text: str) -> None:
62+
"""Set secondary text"""
6063
self._secondary_text = text
6164
self.update()
6265

63-
def resizeEvent(self, a0: QtGui.QResizeEvent) -> None:
64-
return super().resizeEvent(a0)
65-
66-
def mousePressEvent(self, e: QtGui.QMouseEvent) -> None:
67-
return super().mousePressEvent(e)
68-
6966
def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
67+
"""Re-implemented method, paint widget"""
7068
opt = QtWidgets.QStyleOptionButton()
7169
self.initStyleOption(opt)
7270
painter = QtWidgets.QStylePainter(self)
@@ -78,9 +76,7 @@ def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
7876

7977
if not _style or _rect is None:
8078
return
81-
margin = _style.pixelMetric(
82-
_style.PixelMetric.PM_ButtonMargin, opt, self
83-
)
79+
margin = _style.pixelMetric(_style.PixelMetric.PM_ButtonMargin, opt, self)
8480
# Rounded background edges
8581
path = QtGui.QPainterPath()
8682
path.addRoundedRect(
@@ -119,13 +115,11 @@ def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
119115
_pen.setBrush(_gradient)
120116
painter.fillPath(path, _pen.brush())
121117

122-
_icon_rect = (
123-
QtCore.QRectF( # x,y, width * size reduction factor, height
124-
0.0,
125-
0.0,
126-
(_rect.width() * 0.3) - 5.0,
127-
_rect.height() - 5,
128-
)
118+
_icon_rect = QtCore.QRectF( # x,y, width * size reduction factor, height
119+
0.0,
120+
0.0,
121+
(_rect.width() * 0.3) - 5.0,
122+
_rect.height() - 5,
129123
)
130124

131125
_icon_scaled = self.icon_pixmap.scaled(
@@ -192,9 +186,7 @@ def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
192186
QtCore.Qt.TextFlag.TextShowMnemonic
193187
| QtCore.Qt.AlignmentFlag.AlignHCenter
194188
| QtCore.Qt.AlignmentFlag.AlignVCenter,
195-
str(self.secondary_text)
196-
if self.secondary_text
197-
else str("?"),
189+
str(self.secondary_text) if self.secondary_text else str("?"),
198190
)
199191
painter.drawText(
200192
_mtl_rect,
@@ -205,9 +197,9 @@ def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
205197
)
206198
elif self.display_format == "upper_downer":
207199
_mtl = QtCore.QRectF(
208-
int(_icon_rect.width()) + margin ,
200+
int(_icon_rect.width()) + margin,
209201
0.0,
210-
int(_rect.width() - _icon_rect.width() - margin ),
202+
int(_rect.width() - _icon_rect.width() - margin),
211203
_rect.height(),
212204
)
213205
_upper_rect = QtCore.QRectF(
@@ -226,7 +218,9 @@ def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
226218
font.setPointSize(20)
227219
font.setFamily("Momcake-bold")
228220
painter.setFont(font)
229-
painter.setCompositionMode(painter.CompositionMode.CompositionMode_SourceAtop)
221+
painter.setCompositionMode(
222+
painter.CompositionMode.CompositionMode_SourceAtop
223+
)
230224
painter.drawText(
231225
_upper_rect,
232226
# QtCore.Qt.AlignmentFlag.AlignCenter,
@@ -237,7 +231,7 @@ def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
237231
font.setPointSize(15)
238232
painter.setPen(QtGui.QColor("#b6b0b0"))
239233
painter.setFont(font)
240-
234+
241235
painter.drawText(
242236
_downer_rect,
243237
QtCore.Qt.AlignmentFlag.AlignRight
@@ -258,6 +252,7 @@ def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
258252
return
259253

260254
def setProperty(self, name: str, value: typing.Any) -> bool:
255+
"""Re-implemented method, set widget properties"""
261256
if name == "icon_pixmap":
262257
self.icon_pixmap = value
263258
elif name == "button_type":

0 commit comments

Comments
 (0)