Add docstrings. Also add safe_cast function. Finally

fix some minor issues.
This commit is contained in:
alessandro90
2019-05-25 15:18:06 +02:00
parent a7e36505e9
commit 43a9ce954e
14 changed files with 531 additions and 181 deletions

View File

@@ -3,21 +3,29 @@ from PyQt5.QtCore import Qt
class FixedAspectRatioLabel(QLabel):
"""Subclass QLabel. A resizable label class."""
def __init__(self, parent = None):
"""Initialize the instance. Set the pixmap to None."""
super().__init__(parent)
self.pixmap = None
def set_default_stylesheet(self):
"""Set the initial stylesheet of the label."""
self.setStyleSheet("""border-width: 1px;
border-style: solid;
border-color: black;"""
)
def make_transparent(self):
"""Make the label transparent.
Remove text and border."""
self.setText('')
self.setStyleSheet("border-width: 0px;")
def apply_pixmap(self):
"""Apply a scaled pixmap without modifying the dimension of the original one."""
if self.pixmap:
self.setPixmap(
self.pixmap.scaled(
@@ -26,5 +34,6 @@ class FixedAspectRatioLabel(QLabel):
)
def rescale(self, size):
"""Rescale the widget and the displayed pixmap to the given size."""
self.resize(size)
self.apply_pixmap()