added more labels

master
Jan Umbach 2024-06-09 17:23:25 +02:00
parent 3ce2713605
commit aee37878c7
2 changed files with 52 additions and 0 deletions

BIN
label.pdf Normal file

Binary file not shown.

52
main.py
View File

@ -2,6 +2,7 @@ from pathlib import Path
import os import os
import time import time
import logging import logging
from PIL import Image
from watchdog.observers import Observer from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler from watchdog.events import LoggingEventHandler
@ -13,6 +14,10 @@ labelPathDir = downloads_path
labelPath = labelPathDir + "/label.pdf" labelPath = labelPathDir + "/label.pdf"
labelPathRot90 = labelPathDir + "/label_rot90.pdf" labelPathRot90 = labelPathDir + "/label_rot90.pdf"
versandLabelSHINNEX = labelPathDir + "/Versandlabel.png"
productLabelSHINNEX = labelPathDir + "/product-bag-label.png"
filamentLabelSHINNEX = labelPathDir + "/filament-roll-label.png"
printer_identifier = "tcp://192.168.1.70" printer_identifier = "tcp://192.168.1.70"
dpi = 300 dpi = 300
@ -20,6 +25,9 @@ dpi = 300
imageHeight29mm = 343 imageHeight29mm = 343
imageHeight62mm = 745 imageHeight62mm = 745
imageHeightVersand102 = 3505 imageHeightVersand102 = 3505
imageHeightVersandSHX = 1544
imageWidth102mm = 1020
def checkTolerance(isNum, shouldNum): def checkTolerance(isNum, shouldNum):
@ -68,10 +76,48 @@ def printPDF(path):
print("An exception occurred") print("An exception occurred")
os.remove(path) os.remove(path)
def printPNG(path):
if (os.path.isfile(path)):
print("label detected", path)
#try:
# copy path to tmp folder
os.system('cp ' + path + ' tmp/label.png')
# get image height from png
img = Image.open(path)
pngHeight = img.height
labelHeight = 0
options = ""
if (checkTolerance(pngHeight, imageHeightVersandSHX)):
labelHeight = 102
options = "-r 90 "
if (checkTolerance(img.width, imageWidth102mm)):
labelHeight = 102
if (labelHeight != 0):
os.system('brother_ql -m QL-1060N -p ' +
printer_identifier + ' print -d -c -l ' + str(labelHeight) + ' tmp/label.png ' + options + '--lq')
else:
print("UNKNOWN LABEL PICTURE HEIGHT!")
#except:
# print("An exception occurred")
os.remove(path)
printPDF(labelPath) printPDF(labelPath)
printPDF(labelPathRot90) printPDF(labelPathRot90)
printPNG(versandLabelSHINNEX)
printPNG(productLabelSHINNEX)
printPNG(filamentLabelSHINNEX)
class Event(LoggingEventHandler): class Event(LoggingEventHandler):
def on_modified(self, event): def on_modified(self, event):
@ -80,6 +126,12 @@ class Event(LoggingEventHandler):
print(labelPath) print(labelPath)
if (path == labelPath or path == labelPathRot90): if (path == labelPath or path == labelPathRot90):
printPDF(path) printPDF(path)
if (path == versandLabelSHINNEX):
printPNG(path)
if (path == productLabelSHINNEX):
printPNG(path)
if (path == filamentLabelSHINNEX):
printPNG(path)
if __name__ == "__main__": if __name__ == "__main__":