| 3 | from PySide2.QtWidgets import * |
| 4 | |
| 5 | class CicularProgress(QWidget): |
| 6 | def __init__(self): |
| 7 | QWidget.__init__(self) |
| 8 | |
| 9 | self.value = 0 |
| 10 | self.width = 180 |
| 11 | self.height = 180 |
| 12 | self.progress_width = 5 |
| 13 | self.progress_rounded_cap = True |
| 14 | self.progress_color = "#FFF" |
| 15 | self.max_value = 100 |
| 16 | self.suffix = "%" |
| 17 | self.text_color = "#FFF" |
| 18 | self.enable_shadow = True |
| 19 | self.enable_text = True |
| 20 | self.enable_bg = True |
| 21 | self.bg_color = '#383838' |
| 22 | |
| 23 | self.resize(self.width, self.height) |
| 24 | |
| 25 | def set_value(self, value): |
| 26 | if self.value != value: |
| 27 | self.value = value |
| 28 | self.update() |
| 29 | |
| 30 | def paintEvent(self, event): |
| 31 | width = self.width - self.progress_width |
| 32 | height = self.height - self.progress_width |
| 33 | margin = self.progress_width / 2 |
| 34 | value = self.value * 360 / self.max_value |
| 35 | |
| 36 | paint = QPainter() |
| 37 | paint.begin(self) |
| 38 | paint.setRenderHint(QPainter.Antialiasing) |
| 39 | |
| 40 | font = QFont() |
| 41 | font.setFamily(u"Segoe UI") |
| 42 | font.setPointSize(17) |
| 43 | font.setBold(True) |
| 44 | font.setWeight(75) |
| 45 | paint.setFont(font) |
| 46 | |
| 47 | rect = QRect(0, 0, self.width, self.height) |
| 48 | paint.setPen(Qt.NoPen) |
| 49 | paint.drawRect(rect) |
| 50 | |
| 51 | pen = QPen() |
| 52 | pen.setColor(QColor(self.progress_color)) |
| 53 | pen.setWidth(self.progress_width) |
| 54 | |
| 55 | if self.progress_rounded_cap: |
| 56 | pen.setCapStyle(Qt.RoundCap) |
| 57 | |
| 58 | if self.enable_bg: |
| 59 | pen.setColor(QColor(self.bg_color)) |
| 60 | paint.setPen(pen) |
| 61 | paint.drawArc(margin, margin, width, height, 0, 360 * 16) |
| 62 |
no outgoing calls
no test coverage detected