-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicon.py
More file actions
35 lines (25 loc) · 1.09 KB
/
Copy pathicon.py
File metadata and controls
35 lines (25 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Application icon helpers."""
from __future__ import annotations
def create_icon(size: int = 64): # pragma: no cover - requires PyQt at runtime
"""Create a :class:`~PyQt5.QtGui.QIcon` used by the GUI.
The import is performed lazily so that automated tests do not require a
graphical backend.
"""
try:
from PyQt5.QtGui import QColor, QFont, QIcon, QPainter, QPen, QPixmap, QBrush
from PyQt5.QtCore import Qt
except Exception as exc: # pragma: no cover - depends on environment
raise RuntimeError("PyQt5 is required to generate the application icon") from exc
pixmap = QPixmap(size, size)
pixmap.fill(Qt.transparent)
painter = QPainter(pixmap)
painter.setRenderHint(QPainter.Antialiasing)
painter.setBrush(QBrush(QColor("#88C0D0")))
painter.setPen(Qt.NoPen)
painter.drawEllipse(4, 4, size - 8, size - 8)
painter.setPen(QPen(Qt.white, 2))
painter.setFont(QFont("Arial", size // 3, QFont.Bold))
painter.drawText(pixmap.rect(), Qt.AlignCenter, "Q")
painter.end()
return QIcon(pixmap)
__all__ = ["create_icon"]