Skip to content

Commit ce1c06d

Browse files
committed
Replace pillow dependency with pure PyQt6
1 parent 3915a39 commit ce1c06d

2 files changed

Lines changed: 72 additions & 55 deletions

File tree

BlocksScreen/lib/qrcode_gen.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import qrcode
2-
from PIL import ImageQt
2+
3+
from PyQt6.QtGui import QImage, QColor, QPainter
4+
from PyQt6.QtCore import Qt
35

46
BLOCKS_URL = "https://blockstec.com"
57
RF50_MANUAL_PAGE = "https://blockstec.com/RF50"
@@ -8,8 +10,8 @@
810
RF50_USER_MANUAL_PAGE = "https://blockstec.com/assets/files/rf50_user_manual.pdf"
911

1012

11-
def make_qrcode(data) -> ImageQt.ImageQt:
12-
"""Generate a QR code image from *data* and return it as a Qt-compatible image."""
13+
def make_qrcode(data: str) -> QImage:
14+
"""Generate a QR code image from *data* and return it as a QImage."""
1315
qr = qrcode.QRCode(
1416
version=1,
1517
error_correction=qrcode.ERROR_CORRECT_L,
@@ -18,9 +20,25 @@ def make_qrcode(data) -> ImageQt.ImageQt:
1820
)
1921
qr.add_data(data)
2022
qr.make(fit=True)
21-
img = qr.make_image(fill_color="black", back_color="white")
22-
pil_image = img.get_image()
23-
return ImageQt.toqimage(pil_image)
23+
24+
matrix = qr.get_matrix()
25+
box_size = 10
26+
size = len(matrix) * box_size
27+
28+
image = QImage(size, size, QImage.Format.Format_RGB32)
29+
image.fill(QColor("white"))
30+
31+
painter = QPainter(image)
32+
painter.setPen(Qt.PenStyle.NoPen)
33+
painter.setBrush(QColor("black"))
34+
35+
for y, row in enumerate(matrix):
36+
for x, cell in enumerate(row):
37+
if cell:
38+
painter.drawRect(x * box_size, y * box_size, box_size, box_size)
39+
40+
painter.end()
41+
return image
2442

2543

2644
_NM_TO_WIFI_QR_AUTH: dict[str, str] = {
@@ -36,7 +54,7 @@ def make_qrcode(data) -> ImageQt.ImageQt:
3654

3755
def generate_wifi_qrcode(
3856
ssid: str, password: str, auth_type: str, hidden: bool = False
39-
) -> ImageQt.ImageQt:
57+
) -> QImage:
4058
"""Build a Wi-Fi QR code for the given SSID/password/auth combination.
4159
4260
*auth_type* is a NetworkManager key-mgmt value (e.g. ``"wpa-psk"``,

pyproject.toml

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,28 @@ name = "BlocksScreen"
33
dynamic = ['version']
44
description = "GUI for BLOCKS Printers running Klipper"
55
authors = [
6-
{ name = "Hugo do Carmo Costa", email = "hugo.santos.costa@gmail.com" },
6+
{ name = "Hugo do Carmo Costa", email = "hugo.santos.costa@gmail.com" },
77
]
88
maintainers = [
9-
{ name = "Guilherme Costa", email = "guilherme.costa@blockstec.com" },
10-
{ name = "Roberto Martins ", email = "roberto.martins@blockstec.com" },
9+
{ name = "Guilherme Costa", email = "guilherme.costa@blockstec.com" },
10+
{ name = "Roberto Martins ", email = "roberto.martins@blockstec.com" },
1111
]
1212
dependencies = [
13-
'altgraph==0.17.4',
14-
'certifi==2025.10.5',
15-
'charset-normalizer==3.4.4',
16-
'idna==3.11',
17-
'numpy==2.3.4',
18-
'pefile==2024.8.26',
19-
'PyQt6==6.10.0',
20-
'PyQt6-Qt6==6.10.0',
21-
'PyQt6_sip==13.10.2',
22-
'requests>=2.32.5',
23-
'sdbus==0.14.1',
24-
'sdbus-networkmanager==2.0.0',
25-
'typing==3.7.4.3',
26-
'websocket-client==1.9.0',
27-
'qrcode==8.2',
28-
'pillow==12.1.1',
13+
'altgraph==0.17.4',
14+
'certifi==2025.10.5',
15+
'charset-normalizer==3.4.4',
16+
'idna==3.11',
17+
'numpy==2.3.4',
18+
'pefile==2024.8.26',
19+
'PyQt6==6.10.0',
20+
'PyQt6-Qt6==6.10.0',
21+
'PyQt6_sip==13.10.2',
22+
'requests>=2.32.5',
23+
'sdbus==0.14.1',
24+
'sdbus-networkmanager==2.0.0',
25+
'typing==3.7.4.3',
26+
'websocket-client==1.9.0',
27+
'qrcode==8.2',
2928
]
3029
requires-python = "==3.11.2"
3130
readme = "README.md"
@@ -46,35 +45,35 @@ Issues = "https://github.com/BlocksTechnology/BlocksScreen/issues"
4645
line-length = 88
4746
indent-width = 4
4847
exclude = [
49-
".bzr",
50-
".direnv",
51-
".eggs",
52-
".git",
53-
".git-rewrite",
54-
".hg",
55-
".ipynb_checkpoints",
56-
".mypy_cache",
57-
".nox",
58-
".pants.d",
59-
".pyenv",
60-
".pytest_cache",
61-
".pytype",
62-
".ruff_cache",
63-
".svn",
64-
".tox",
65-
".venv",
66-
".vscode",
67-
"__pypackages__",
68-
"_build",
69-
"buck-out",
70-
"build",
71-
"dist",
72-
"node_modules",
73-
"site-packages",
74-
"venv",
75-
"BlocksScreen/lib/ui",
76-
"extras",
77-
"tests"
48+
".bzr",
49+
".direnv",
50+
".eggs",
51+
".git",
52+
".git-rewrite",
53+
".hg",
54+
".ipynb_checkpoints",
55+
".mypy_cache",
56+
".nox",
57+
".pants.d",
58+
".pyenv",
59+
".pytest_cache",
60+
".pytype",
61+
".ruff_cache",
62+
".svn",
63+
".tox",
64+
".venv",
65+
".vscode",
66+
"__pypackages__",
67+
"_build",
68+
"buck-out",
69+
"build",
70+
"dist",
71+
"node_modules",
72+
"site-packages",
73+
"venv",
74+
"BlocksScreen/lib/ui",
75+
"extras",
76+
"tests",
7877
]
7978

8079
[tool.ruff.lint]

0 commit comments

Comments
 (0)