component_label.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. from .label_image import Label
  2. import qrcode
  3. class ComponentLabel(Label):
  4. pixels_x = 991
  5. pixels_y = 306
  6. text_pos_x = 320
  7. ql_format = '62'
  8. ql_rotation = 90
  9. dpi_600 = True
  10. red_label = False
  11. def __init__(self):
  12. super().__init__()
  13. def put_content(self, qr_data, component_name, manufacturer, package):
  14. 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)
  15. 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)
  16. 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)
  17. qr = qrcode.QRCode(
  18. version=1,
  19. error_correction=qrcode.constants.ERROR_CORRECT_L,
  20. box_size=8,
  21. border=0,
  22. )
  23. qr.add_data(qr_data)
  24. qr.make(fit=True)
  25. qr_image = qr.make_image(fill_color="black", back_color="white")
  26. qr_y_size = qr_image.size[1]
  27. self.img.paste(qr_image, box=(0, int(self.pixels_y/2 - qr_y_size/2)))
  28. class ComponentLabelSmallest(ComponentLabel):
  29. pixels_x = 212
  30. pixels_y = 212
  31. ql_format = '12'
  32. ql_rotation = 90
  33. dpi_600 = True
  34. red_label = False
  35. def __init__(self):
  36. super().__init__()
  37. def put_content(self, qr_data, component_name=None, manufacturer=None, package=None):
  38. qr = qrcode.QRCode(
  39. version=1,
  40. error_correction=qrcode.constants.ERROR_CORRECT_L,
  41. box_size=7.2,
  42. border=0,
  43. )
  44. qr.add_data(qr_data)
  45. qr.make(fit=True)
  46. qr_image = qr.make_image(fill_color="black", back_color="white")
  47. qr_y_size = qr_image.size[1]
  48. self.img.paste(qr_image, box=(0, int(self.pixels_y/2 - qr_y_size/2)))
  49. class ComponentLabelSmall(ComponentLabel):
  50. pixels_x = 600
  51. pixels_y = 212
  52. ql_format = '12'
  53. ql_rotation = 90
  54. dpi_600 = True
  55. red_label = False
  56. text_pos_x = 235
  57. def __init__(self):
  58. super().__init__()
  59. def put_content(self, qr_data, component_name='', manufacturer='', package=''):
  60. 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)
  61. 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)
  62. 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)
  63. qr = qrcode.QRCode(
  64. version=1,
  65. error_correction=qrcode.constants.ERROR_CORRECT_L,
  66. box_size=7.2,
  67. border=0,
  68. )
  69. qr.add_data(qr_data)
  70. qr.make(fit=True)
  71. qr_image = qr.make_image(fill_color="black", back_color="white")
  72. qr_y_size = qr_image.size[1]
  73. self.img.paste(qr_image, box=(0, int(self.pixels_y/2 - qr_y_size/2)))
  74. class ComponentLabelSmdMiceToiletPocket(Label):
  75. pixels_x = 307
  76. pixels_y = 212
  77. ql_format = '12'
  78. ql_rotation = 270
  79. dpi_600 = True
  80. red_label = False
  81. def __init__(self):
  82. super().__init__()
  83. def put_content(self, heading, line1=None, line2=None):
  84. self.draw_text(heading, self.pixels_x/2, 10, size=50, font_file='bold', centered_x=True, centered_y=True, scale_to_fit=True)
  85. if line1:
  86. self.draw_text(line1, self.pixels_x/2, 80, size=40, centered_x=True, centered_y=True, scale_to_fit=True)
  87. if line2:
  88. self.draw_text(line2, self.pixels_x/2, 165, size=40, centered_x=True, centered_y=True, scale_to_fit=True)