mocodoeditor 0.2.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mocodoeditor/icons.py ADDED
@@ -0,0 +1,44 @@
1
+ """Icônes de la barre d'outils : traits fins à bouts arrondis, dans l'esprit des symboles SF.
2
+
3
+ Dessinées en SVG (grille 24 × 24) et teintées à la demande, pour suivre le thème clair/sombre."""
4
+ from PyQt6.QtCore import QByteArray, QRectF, Qt
5
+ from PyQt6.QtGui import QIcon, QImage, QPainter, QPixmap
6
+ from PyQt6.QtSvg import QSvgRenderer
7
+
8
+ SIZE = 20 # points
9
+
10
+ PATHS = {
11
+ "new": "M14 3.5H7.5a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2V8z M14 3.5V8h4.5 M12 11.5v5 M9.5 14h5",
12
+ "open": "M3.5 7.5a2 2 0 0 1 2-2h4l2 2.2h7a2 2 0 0 1 2 2v7.8a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2z",
13
+ "save": "M12 4v11 M7.5 10.8l4.5 4.5 4.5-4.5 M5 15.5v2a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-2",
14
+ "export": "M12 15V4 M7.8 8.2L12 4l4.2 4.2 M8 11.5H7a2 2 0 0 0-2 2V18a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-4.5a2 2 0 0 0-2-2h-1",
15
+ "zoom_in": "M10.5 4.3a6.2 6.2 0 1 0 0 12.4 6.2 6.2 0 0 0 0-12.4z M15.2 15.2L20 20 M8 10.5h5 M10.5 8v5",
16
+ "zoom_out": "M10.5 4.3a6.2 6.2 0 1 0 0 12.4 6.2 6.2 0 0 0 0-12.4z M15.2 15.2L20 20 M8 10.5h5",
17
+ "fit": "M4 9V6a2 2 0 0 1 2-2h3 M15 4h3a2 2 0 0 1 2 2v3 M20 15v3a2 2 0 0 1-2 2h-3 M9 20H6a2 2 0 0 1-2-2v-3",
18
+ "retouches": "M10 5L11.9 9.6 16.5 11.5 11.9 13.4 10 18 8.1 13.4 3.5 11.5 8.1 9.6z M18 3.5v4 M16 5.5h4 M18 16v4 M16 18h4",
19
+ "options": "M5 5.5h14a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-9a2 2 0 0 1 2-2z M14.5 5.5v13 M17.2 9.5h1 M17.2 12h1 M17.2 14.5h1",
20
+ "search": "M10.5 4.3a6.2 6.2 0 1 0 0 12.4 6.2 6.2 0 0 0 0-12.4z M15.2 15.2L20 20",
21
+ }
22
+
23
+
24
+ def pixmap(name: str, color: str, alpha: float = 1.0, ratio: float = 2.0) -> QPixmap:
25
+ svg = (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" '
26
+ f'stroke="{color}" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">'
27
+ f'<path d="{PATHS[name]}"/></svg>')
28
+ px = int(SIZE * ratio)
29
+ image = QImage(px, px, QImage.Format.Format_ARGB32_Premultiplied)
30
+ image.fill(Qt.GlobalColor.transparent)
31
+ painter = QPainter(image)
32
+ painter.setOpacity(alpha)
33
+ QSvgRenderer(QByteArray(svg.encode())).render(painter, QRectF(0, 0, px, px))
34
+ painter.end()
35
+ pm = QPixmap.fromImage(image)
36
+ pm.setDevicePixelRatio(ratio)
37
+ return pm
38
+
39
+
40
+ def icon(name: str, color: str) -> QIcon:
41
+ result = QIcon()
42
+ result.addPixmap(pixmap(name, color), QIcon.Mode.Normal)
43
+ result.addPixmap(pixmap(name, color, alpha=0.3), QIcon.Mode.Disabled)
44
+ return result