Skip to content

Commit 7eee55f

Browse files
author
Bar
committed
sticker fixes
1 parent 12c8731 commit 7eee55f

File tree

1 file changed

+66
-13
lines changed

1 file changed

+66
-13
lines changed

plugins/stickers.py

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,30 +134,55 @@ def thtprint(self):
134134
options={"copies": str(self.copies), "page-ranges": "1"},
135135
)
136136

137-
def foodprint(self):
137+
def toolprint(self):
138+
if re.compile("^[0-9A-Z]+$").match(self.name):
139+
print("Qrcode: alphanum")
140+
qrcode_image = pyqrcode.create(
141+
self.name, error="L", version=1, mode="alphanumeric"
142+
).png_as_base64_str(scale=5)
143+
else:
144+
print("Qrcode: binary")
145+
qrcode_image = pyqrcode.create(
146+
self.name, error="L", version=2, mode="binary"
147+
).png_as_base64_str(scale=5)
148+
149+
# Create an image object
138150
img = Image.new("RGB", self.SMALL, self.WHITE)
139151
draw = ImageDraw.Draw(img)
140152

141-
LOGO = Image.open(self.LOGOFILE)
142-
LOGO = LOGO.resize(
143-
self.LOGOSMALLSIZE, resample=Image.LANCZOS # pylint: disable=no-member
153+
# Load the QR code as an image
154+
qrcode_img = Image.open(io.BytesIO(base64.b64decode(qrcode_image)))
155+
156+
# Calculate size for QR code
157+
size = self.SMALL[1] // (qrcode_img.size[0] + 4 * self.SPACE)
158+
qrcode_img = qrcode_img.resize(
159+
(size * qrcode_img.size[0], size * qrcode_img.size[1]),
160+
resample=Image.LANCZOS, # pylint: disable=no-member
144161
)
145-
img.paste(LOGO, (0, 0))
146162

163+
# Place QR code on the image
164+
img.paste(qrcode_img, (self.SPACE, self.SPACE))
165+
166+
# Load a font
147167
font = ImageFont.truetype(self.FONT, 40)
148-
draw.text((0, self.SMALL[1] - 15), self.name, fill=self.BLACK, font=font)
149168

150-
font = ImageFont.truetype(self.FONT, 50)
151-
draw.text((320, 120), time.strftime("%Y-%m-%d"), fill=self.BLACK, font=font)
169+
# Add text to the image
170+
draw.text((64, self.SMALL[1]), self.name, fill=self.BLACK, font=font)
152171

153-
img.save("data/foodout.png")
172+
# Save the image
173+
img.save("data/toollabel.jpg", "JPEG", dpi=(300, 300))
174+
175+
# Print the file
176+
options={"copies": str(self.copies), "page-ranges": "1", "media": "media=custom_61.98x100mm_61.98x100mm"}
154177
cups.Connection().printFile( # pylint: disable=no-member
155178
self.printer,
156-
"data/foodout.png",
157-
title="Voedsel",
158-
options={"copies": str(self.copies), "page-ranges": "1"},
179+
"data/toollabel.jpg",
180+
title="Toollabel",
181+
options=options,
159182
)
160183

184+
185+
161186
def eigendomprint(self):
162187
img = Image.new("RGB", self.SMALL, self.WHITE)
163188
draw = ImageDraw.Draw(img)
@@ -309,7 +334,24 @@ def thtnum(self, text):
309334
except:
310335
traceback.print_exc()
311336
return self.messageandbuttons(
312-
"foodnum", "numbers", "NaN ; How many do you want?"
337+
"thtnum", "numbers", "NaN ; How many do you want?"
338+
)
339+
340+
def toolnum(self, text):
341+
if text == "abort":
342+
return self.master.callhook("abort", None)
343+
try:
344+
self.copies = int(text)
345+
if not 0 < self.copies < 100:
346+
return self.messageandbuttons(
347+
"toolnum", "numbers", "Only 1 <> 99 allowed; How many do you want?"
348+
)
349+
self.toolprint()
350+
return True
351+
except:
352+
traceback.print_exc()
353+
return self.messageandbuttons(
354+
"toolnum", "numbers", "NaN ; How many do you want?"
313355
)
314356

315357
def foodname(self, text):
@@ -324,6 +366,12 @@ def thtname(self, text):
324366
self.datum = text
325367
return self.messageandbuttons("thtnum", "numbers", "How many do you want?")
326368

369+
def toolname(self, text):
370+
if text == "abort":
371+
return self.master.callhook("abort", None)
372+
self.name = text
373+
return self.messageandbuttons("toolnum", "numbers", "How many do you want?")
374+
327375
def input(self, text):
328376
if text == "eigendom":
329377
self.large = False
@@ -355,6 +403,10 @@ def input(self, text):
355403
True, "buttons", json.dumps({"special": "accounts"})
356404
)
357405
return True
406+
if text == "toollabel":
407+
self.master.donext(self, "toolname")
408+
self.master.send_message(True, "message", "What is the Toolname?")
409+
return True
358410
if text == "barcode":
359411
return self.messageandbuttons(
360412
"barcodecount", "products", "What product do you want a barcode for?"
@@ -366,6 +418,7 @@ def input(self, text):
366418
custom.append({"text": "eigendomlarge", "display": "Large Property label"})
367419
custom.append({"text": "foodlabel", "display": "Food label"})
368420
custom.append({"text": "thtlabel", "display": "THT label"})
421+
custom.append({"text": "toollabel", "display": "Tool label"})
369422
self.master.send_message(
370423
True, "buttons", json.dumps({"special": "custom", "custom": custom})
371424
)

0 commit comments

Comments
 (0)