123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- from .label_image import Label
- import qrcode
- class ComponentLabel(Label):
- pixels_x = 991
- pixels_y = 306
- text_pos_x = 320
- ql_format = '62'
- ql_rotation = 90
- dpi_600 = True
- red_label = False
- def __init__(self):
- super().__init__()
- def put_content(self, qr_data, component_name, manufacturer, package):
- self.draw_text(component_name, self.text_pos_x, self.pixels_y/2-45, size=38, font_file='bold', scale_to_fit=True, centered_x=False, centered_y=True)
- self.draw_text(manufacturer, self.text_pos_x, self.pixels_y/2, size=32, font_file='bold', scale_to_fit=True, centered_x=False, centered_y=True)
- self.draw_text(package, self.text_pos_x, self.pixels_y/2+40, size=32, font_file='bold', scale_to_fit=True, centered_x=False, centered_y=True)
- qr = qrcode.QRCode(
- version=1,
- error_correction=qrcode.constants.ERROR_CORRECT_L,
- box_size=8,
- border=0,
- )
- qr.add_data(qr_data)
- qr.make(fit=True)
- qr_image = qr.make_image(fill_color="black", back_color="white")
- qr_y_size = qr_image.size[1]
- self.img.paste(qr_image, box=(0, int(self.pixels_y/2 - qr_y_size/2)))
- class ComponentLabelSmallest(ComponentLabel):
- pixels_x = 212
- pixels_y = 212
- ql_format = '12'
- ql_rotation = 90
- dpi_600 = True
- red_label = False
- def __init__(self):
- super().__init__()
- def put_content(self, qr_data, component_name=None, manufacturer=None, package=None):
- qr = qrcode.QRCode(
- version=1,
- error_correction=qrcode.constants.ERROR_CORRECT_L,
- box_size=7.2,
- border=0,
- )
- qr.add_data(qr_data)
- qr.make(fit=True)
- qr_image = qr.make_image(fill_color="black", back_color="white")
- qr_y_size = qr_image.size[1]
- self.img.paste(qr_image, box=(0, int(self.pixels_y/2 - qr_y_size/2)))
- class ComponentLabelSmall(ComponentLabel):
- pixels_x = 600
- pixels_y = 212
- ql_format = '12'
- ql_rotation = 90
- dpi_600 = True
- red_label = False
- text_pos_x = 235
- def __init__(self):
- super().__init__()
- def put_content(self, qr_data, component_name='', manufacturer='', package=''):
- self.draw_text(component_name, self.text_pos_x, self.pixels_y/2-65, size=42, font_file='bold', scale_to_fit=True, centered_x=False, centered_y=True)
- self.draw_text(manufacturer, self.text_pos_x, self.pixels_y/2, size=36, font_file='bold', scale_to_fit=True, centered_x=False, centered_y=True)
- self.draw_text(package, self.text_pos_x, self.pixels_y/2+55, size=36, font_file='bold', scale_to_fit=True, centered_x=False, centered_y=True)
- qr = qrcode.QRCode(
- version=1,
- error_correction=qrcode.constants.ERROR_CORRECT_L,
- box_size=7.2,
- border=0,
- )
- qr.add_data(qr_data)
- qr.make(fit=True)
- qr_image = qr.make_image(fill_color="black", back_color="white")
- qr_y_size = qr_image.size[1]
- self.img.paste(qr_image, box=(0, int(self.pixels_y/2 - qr_y_size/2)))
- class ComponentLabelSmdMiceToiletPocket(Label):
- pixels_x = 307
- pixels_y = 212
- ql_format = '12'
- ql_rotation = 270
- dpi_600 = True
- red_label = False
- def __init__(self):
- super().__init__()
- def put_content(self, heading, line1=None, line2=None):
- self.draw_text(heading, self.pixels_x/2, 10, size=50, font_file='bold', centered_x=True, centered_y=True, scale_to_fit=True)
- if line1:
- self.draw_text(line1, self.pixels_x/2, 80, size=40, centered_x=True, centered_y=True, scale_to_fit=True)
- if line2:
- self.draw_text(line2, self.pixels_x/2, 165, size=40, centered_x=True, centered_y=True, scale_to_fit=True)
|