diff --git a/GothamCond-Medium.otf b/GothamCond-Medium.otf
new file mode 100644
index 0000000..cfe2b87
Binary files /dev/null and b/GothamCond-Medium.otf differ
diff --git a/belden-logo.svg b/belden-logo.svg
new file mode 100644
index 0000000..0e7e668
--- /dev/null
+++ b/belden-logo.svg
@@ -0,0 +1,41 @@
+
+
+
diff --git a/get_specs.py b/get_specs.py
index 1391de0..e31cb85 100755
--- a/get_specs.py
+++ b/get_specs.py
@@ -281,6 +281,7 @@ def get_multi(partnums, delay=0.25, dir="cables/", cache=True):
return out
def run_search(partnum):
+ partnum = partnum.replace("%20", " ") # undo URL encoding
oldpartnum = partnum
if dstype == "Alphawire":
# For alphawire, sanitize the part number for only the final result check, because their API is very wierd
@@ -407,6 +408,7 @@ if __name__ == "__main__":
# ]
partnums = [
# Actual cables in Jukebox
+
"AW86104CY",
"AW3050",
"AW6714",
@@ -439,7 +441,7 @@ if __name__ == "__main__":
# Some ones I picked, including some invalid ones
"BL10GXS12",
- "BLRST 5L-RKT 5L-949",
+ "BLRST%205L-RKT%205L-949",
"BL10GXS13",
"BL10GXW12",
"BL10GXW13",
@@ -450,12 +452,17 @@ if __name__ == "__main__":
"BLFISD012R9",
"BLFDSD012A9",
"BLFSSL024NG",
- "BLFISX006W0",
- "BLFISX00103",
- "BLC6D1100007"
+ "BLFISX006W0", # datasheet only
+ "BLFISX00103", # invalid
+ "BLC6D1100007" # invalid
]
#print(query_search("TT-SLG-024-HTNN", "Belden"))
+ from label_generator import gen_label
+ gen_label("BLTF-SD9-006-RI5")
+ gen_label("BLRA500P")
+ gen_label("AWFIT-221-1_4")
+ gen_label("BLRST 5L-RKT 5L-949")
get_multi(partnums, 0.25)
#query_search("10GXS13", "Belden")
diff --git a/index.html b/index.html
deleted file mode 100644
index cb0c070..0000000
--- a/index.html
+++ /dev/null
@@ -1 +0,0 @@
-
RGB Controller Configuration RGB Controller Configuration
Set IP address
Needs reboot to apply
Set to 0.0.0.0 for DHCP
Set Hostname
Needs reboot to apply
Max 64 characters
DMX512 Start Universe
Applies immediately
Between (inclusive) 1-65000
\ No newline at end of file
diff --git a/label_generator.py b/label_generator.py
index f0fbaa9..9551999 100755
--- a/label_generator.py
+++ b/label_generator.py
@@ -61,9 +61,15 @@ def input_cable():
imgstr = "BL"
elif output[1] == "Alphawire":
imgstr = "AW"
- img = generate_code(imgstr + output[0])
- os.makedirs("labels", exist_ok=True)
- img.save("labels/" + imgstr + output[0] + ".png")
+ gen_label(imgstr + output[0])
+ #img = generate_code(imgstr + output[0])
+ #os.makedirs("labels", exist_ok=True)
+ #img.save("labels/" + imgstr + output[0] + ".png")
+
+def gen_label(partnum, path="labels"):
+ img = generate_code(partnum)
+ os.makedirs(path, exist_ok=True)
+ img.save(path + "/" + partnum + ".png")
def delete_folder(path):
# Check if the path is a directory
diff --git a/label_image.py b/label_image.py
index 17de9ba..7bc6395 100755
--- a/label_image.py
+++ b/label_image.py
@@ -3,8 +3,13 @@ from util import fprint
from PIL import Image
from PIL import ImageDraw
+from PIL import ImageFont
#import cv2
import numpy as np
+from util import find_data_file
+import segno
+import io
+import cairosvg
#import math
@@ -134,7 +139,8 @@ for charset in (CODE128A, CODE128B):
def generate_code(data, show=False, check=False):
- img = code128_image(data)
+ #img = code128_image(data)
+ img = qr_image(data)
if show:
img.show()
#img.show()
@@ -198,6 +204,7 @@ def code128_format(data):
return codes
def code128_image(data, height=100, thickness=3, quiet_zone=False):
+ partnum = data
if not data[-1] == CODE128B['Stop']:
data = code128_format(data)
@@ -227,12 +234,81 @@ def code128_image(data, height=100, thickness=3, quiet_zone=False):
#draw.arc(((width - width/5, width - width/5), (width*9 + width/5, width*9 + width/5)),0,360,fill='blue', width = int(width/8))
draw.arc(((width+int(width / 1.4), width+int(width / 1.4)), (width*9-int(width / 1.4), width*9-int(width / 1.4))),0,360,fill='blue', width = int(width/8))
+ font_path = find_data_file("OCRAEXT.TTF")
+ font_size = width/2
+ font = ImageFont.truetype(font_path, font_size)
+ text_width = font.getlength(partnum)
+ while text_width > width*4:
+ font_size -= 1
+ font = ImageFont.truetype(font_path, font_size)
+ text_width = font.getlength(partnum)
+
+ txtx = (int(width * 10) - text_width) / 2
+ txty = (int(width * 10)) / 2 + width / 2
+
+ draw.text((txtx,txty),partnum, "black", font)
+ return img
+
+def qr_image(data, width=600):
+ partnum = data
+
+
+
+ # Monochrome Image
+ img = Image.new('RGB', (int(width * 10), int(width * 10)), 'white')
+ draw = ImageDraw.Draw(img)
+
+
+
+ svg_path = find_data_file("belden-logo.svg")
+ with open(svg_path, 'rb') as svg_file:
+ png_image = cairosvg.svg2png(file_obj=svg_file,dpi=width*8, scale=7, background_color="white")
+ png_image_io = io.BytesIO(png_image)
+ png_image_pillow = Image.open(png_image_io)
+ 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)))
+
+ # 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))
+ draw.arc(((width+int(width / 1.4), width+int(width / 1.4)), (width*9-int(width / 1.4), width*9-int(width / 1.4))),0,360,fill=(0, 73,144), width = int(width/8))
+
+ font_path = find_data_file("GothamCond-Medium.otf")
+ font_size = width/2
+ font = ImageFont.truetype(font_path, font_size)
+ text_width = font.getlength(partnum[2:])
+ # shrink font dynamically if it's too long of a name
+ while text_width > width*4:
+ font_size -= 1
+ font = ImageFont.truetype(font_path, font_size)
+ text_width = font.getlength(partnum[2:])
+
+ txtx = (int(width * 10) - text_width) / 2
+ txty = (int(width * 10)) / 2
+ # draw part number text
+ draw.text((txtx,txty),partnum[2:], "black", font)
+
+ # Draw QR code
+ partnum = partnum.replace(" ", "%20")
+ qrcode = segno.make('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)
+ qrimg = Image.open(out)
+ img.paste(qrimg, box=(int(width*4),int(width*5.75)))
+
+
return img
if __name__ == "__main__":
#print(generate_code("BL10GXS13"))
#print(generate_code("BL10GXgd35j35S13"))
#print(generate_code("BL10GX54hS13"))
- print(generate_code("BL10Gj34qXS13", False, False))
+ #print(generate_code("BL10Gj34qXS13", False, False))
#print(generate_code("BL104w5545dp7bfwp43643534/4563G-XS13"))
- #adjust_image(cv2.imread('test_skew.jpg'))
\ No newline at end of file
+ #adjust_image(cv2.imread('test_skew.jpg'))
+ path = "labels"
+ img = generate_code("BL10GXS13")
+ import os
+ os.makedirs(path, exist_ok=True)
+ img.save(path + "/" + "BL10GXS13" + ".png")
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 55c1942..70ee707 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -19,7 +19,7 @@ pandas
pyarrow
ghostscript
pyzbar
-
+cairosvg
# Development
matplotlib
diff --git a/setup-label-generator.py b/setup-label-generator.py
index 0376975..bfc7f35 100644
--- a/setup-label-generator.py
+++ b/setup-label-generator.py
@@ -10,7 +10,7 @@ import opcode
import os
import distutils
#distutils_path = os.path.join(os.path.dirname(opcode.__file__), 'distutils')
-build_exe_options = {"include_msvcr": True, "packages": ["camelot", "setuptools"], "optimize": 0, "silent": True, "include_files": ["gs10030w64.exe"], "excludes": ["scipy", "torch"]}
+build_exe_options = {"include_msvcr": True, "packages": ["camelot", "setuptools"], "optimize": 0, "silent": True, "include_files": ["gs10030w64.exe", "GothamCond-Medium.otf", "belden-logo.svg"], "excludes": ["scipy", "torch"]}
# base="Win32GUI" should be used only for Windows GUI app
base = "console"
diff --git a/test.pdf b/test.pdf
deleted file mode 100644
index 033532c..0000000
Binary files a/test.pdf and /dev/null differ
diff --git a/test2.pdf b/test2.pdf
deleted file mode 100644
index 489e0e9..0000000
Binary files a/test2.pdf and /dev/null differ