Update label generation, websocket listen mode
This commit is contained in:
parent
33af359a86
commit
24d959da71
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,3 +21,4 @@ map*.png
|
||||
build
|
||||
# Generated label images
|
||||
labels
|
||||
temp
|
26
cables.txt
Normal file
26
cables.txt
Normal file
@ -0,0 +1,26 @@
|
||||
1172C
|
||||
86104CY
|
||||
FIT-221-1_4
|
||||
10GXW13
|
||||
10GXW53
|
||||
29501F
|
||||
29512
|
||||
3092A
|
||||
3105A
|
||||
3106A
|
||||
6300FE
|
||||
6300UE
|
||||
7922A
|
||||
7958A
|
||||
8760
|
||||
9841
|
||||
FI4X012W0
|
||||
FISX012W0
|
||||
IOP6U
|
||||
RA500P
|
||||
SPE101
|
||||
SPE102
|
||||
TF-1LF-006-RS5
|
||||
TF-SD9-006-RI5
|
||||
TT-SLG-024-HTN
|
||||
3050
|
51
label_document.py
Executable file
51
label_document.py
Executable file
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
import fitz # PyMuPDF
|
||||
from reportlab.pdfgen import canvas
|
||||
from reportlab.lib.pagesizes import letter
|
||||
import os
|
||||
|
||||
|
||||
def generate_pdf(path="labels"):
|
||||
# Open the existing PDF
|
||||
image_folder_path = path
|
||||
doc = fitz.open('label_template.pdf')
|
||||
page = doc[0] # Assuming you want to read from the first page
|
||||
|
||||
placeholders = []
|
||||
for shape in page.get_drawings():
|
||||
if shape['type'] == 's': # Checking for rectangle types
|
||||
placeholders.append({
|
||||
'x': shape['rect'].x0,
|
||||
'y': shape['rect'].y0,
|
||||
'width': shape['rect'].width,
|
||||
'height': shape['rect'].height
|
||||
})
|
||||
|
||||
# List all PNG images in the folder
|
||||
image_files = [f for f in os.listdir(image_folder_path) if f.endswith('.png')]
|
||||
image_paths = [os.path.join(image_folder_path, file) for file in image_files]
|
||||
|
||||
# Create a new PDF with ReportLab
|
||||
c = canvas.Canvas(path + "/print.pdf", pagesize=letter)
|
||||
current_placeholder = 0 # Track the current placeholder index
|
||||
|
||||
for image_path in image_paths:
|
||||
if current_placeholder >= len(placeholders): # Check if a new page is needed
|
||||
c.showPage()
|
||||
current_placeholder = 0 # Reset placeholder index for new page
|
||||
|
||||
# Get current placeholder
|
||||
placeholder = placeholders[current_placeholder]
|
||||
|
||||
# Place image at the placeholder position
|
||||
c.drawImage(image_path, placeholder['x'], page.rect.height - placeholder['y'] - placeholder['height'], width=placeholder['width'], height=placeholder['height'])
|
||||
current_placeholder += 1
|
||||
|
||||
# Save the final PDF
|
||||
c.save()
|
||||
|
||||
# Close the original PDF
|
||||
doc.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
generate_pdf("labels")
|
@ -9,6 +9,7 @@ import os
|
||||
import signal
|
||||
from PIL import Image
|
||||
from label_image import generate_code
|
||||
from label_document import generate_pdf
|
||||
|
||||
|
||||
def input_cable():
|
||||
@ -22,7 +23,7 @@ def input_cable():
|
||||
print("Input part number:", inputnum)
|
||||
print("Searching databases for cables...")
|
||||
# Search both AW and BL sites
|
||||
status, output = get_multi(["BL"+inputnum, "AW"+inputnum], delay=0.1, dir="temp/" + str(uuid.uuid4()) + "/", cache=False)
|
||||
status, output = get_multi(["BL"+inputnum, "AW"+inputnum], delay=0.1, dir="temp/" + str(uuid.uuid4()) + "/", webport=":9000", cache=False)
|
||||
print("")
|
||||
if len(output) > 1:
|
||||
for i in output:
|
||||
@ -70,6 +71,8 @@ def gen_label(partnum, path="labels"):
|
||||
img = generate_code(partnum)
|
||||
os.makedirs(path, exist_ok=True)
|
||||
img.save(path + "/" + partnum + ".png")
|
||||
generate_pdf(path)
|
||||
|
||||
|
||||
def delete_folder(path):
|
||||
# Check if the path is a directory
|
||||
|
@ -269,10 +269,10 @@ def qr_image(data, width=600):
|
||||
png_image_io = "belden-logo-superhires.png"
|
||||
png_image_pillow = Image.open(png_image_io)
|
||||
png_width, png_height = png_image_pillow.size
|
||||
png_image_pillow = png_image_pillow.resize((int(width*5.2), int(width*5.2/png_width*png_height)))
|
||||
png_image_pillow = png_image_pillow.resize((int(width*4), int(width*4/png_width*png_height)))
|
||||
png_width, png_height = png_image_pillow.size
|
||||
# paste belden logo first because it has a big border that would cover stuff up
|
||||
img.paste(png_image_pillow, (int(width*5-png_width/2), int(width*4.25 - png_height/2)))
|
||||
img.paste(png_image_pillow, (int(width*5-png_width/2), int(width*3.25 - png_height/2)))
|
||||
|
||||
# draw circle border
|
||||
#draw.arc(((width - width/5, width - width/5), (width*9 + width/5, width*9 + width/5)),0,360,fill='blue', width = int(width/8))
|
||||
@ -289,7 +289,7 @@ def qr_image(data, width=600):
|
||||
text_width = font.getlength(partnum[2:])
|
||||
|
||||
txtx = (int(width * 10) - text_width) / 2
|
||||
txty = (int(width * 10)) / 2
|
||||
txty = (int(width * 7.5)) / 2
|
||||
# draw part number text
|
||||
draw.text((txtx,txty),partnum[2:], "black", font)
|
||||
|
||||
@ -298,10 +298,11 @@ def qr_image(data, width=600):
|
||||
qrcode = segno.make('HTTPS://BLDN.APP/' + partnum,micro=False,boost_error=False,error="L",mask=3)
|
||||
out = io.BytesIO()
|
||||
qrx, _ = qrcode.symbol_size(1,0)
|
||||
qrcode.save(out, scale=width*2/qrx, kind="PNG", border=0)
|
||||
qrcode.save(out, scale=width*3/qrx, kind="PNG", border=0)
|
||||
qrimg = Image.open(out)
|
||||
img.paste(qrimg, box=(int(width*4),int(width*5.75)))
|
||||
|
||||
img.paste(qrimg, box=(int(width*3.5),int(width*4.5)))
|
||||
img = img.crop((width+int(width / 1.4)-int(width/8),width+int(width / 1.4)-int(width/8),img.size[0] - (width+int(width / 1.4)-int(width/8)), img.size[1] - (width+int(width / 1.4)-int(width/8)) ))
|
||||
img = img.resize((1200, 1200), Image.LANCZOS) # 1200 dpi
|
||||
|
||||
return img
|
||||
|
||||
|
2064
label_template.pdf
Normal file
2064
label_template.pdf
Normal file
File diff suppressed because one or more lines are too long
6
run.py
6
run.py
@ -422,7 +422,7 @@ def setup_server(pool, manager):
|
||||
if sensor_ready is False:
|
||||
fprint("waiting for " + "Sensor Initialization" + " to complete...", sendqueue=to_server_queue)
|
||||
global mbconn
|
||||
mbconn = ModbusClient(host="192.168.1.20", port=502, auto_open=True, auto_close=True)
|
||||
mbconn = ModbusClient(host="192.168.1.20", port=502, auto_open=True, auto_close=False)
|
||||
get_sensors()
|
||||
fprint("Sensors initialized.", sendqueue=to_server_queue)
|
||||
|
||||
@ -461,7 +461,7 @@ def get_sensors():
|
||||
global sensors
|
||||
oldsens = sensors
|
||||
#print("Reading sensors")
|
||||
#mbconn.open()
|
||||
# mbconn.open()
|
||||
"""
|
||||
port 1: 256
|
||||
port 2: 272
|
||||
@ -490,7 +490,7 @@ def get_sensors():
|
||||
return -1
|
||||
sensors = out
|
||||
#fprint("Values: " + str(sensors))
|
||||
#mbconn.close()
|
||||
mbconn.close()
|
||||
for x in range(len(oldsens)):
|
||||
if oldsens[x] == 0 and out[x] == 1:
|
||||
# cable newly detected on tray
|
||||
|
@ -83,7 +83,7 @@ async def send_messages(to_server_queue):
|
||||
await asyncio.sleep(0.001)
|
||||
|
||||
def websocket_server(to_server_queue, from_server_queue):
|
||||
start_server = websockets.serve(lambda ws, path: handler(ws, path, to_server_queue, from_server_queue), "localhost", 9000)
|
||||
start_server = websockets.serve(lambda ws, path: handler(ws, path, to_server_queue, from_server_queue), "0.0.0.0", 9000)
|
||||
|
||||
asyncio.get_event_loop().run_until_complete(start_server)
|
||||
asyncio.get_event_loop().create_task(send_messages(to_server_queue))
|
||||
|
Loading…
x
Reference in New Issue
Block a user