component_label.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. qrcode_size = 7.2
  58. def put_content(self, qr_data, component_name='', manufacturer='', package=''):
  59. 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)
  60. 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)
  61. 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)
  62. qr = qrcode.QRCode(
  63. version=1,
  64. error_correction=qrcode.constants.ERROR_CORRECT_L,
  65. box_size=self.qrcode_size,
  66. border=0,
  67. )
  68. qr.add_data(qr_data)
  69. qr.make(fit=True)
  70. qr_image = qr.make_image(fill_color="black", back_color="white")
  71. qr_y_size = qr_image.size[1]
  72. self.img.paste(qr_image, box=(0, int(self.pixels_y/2 - qr_y_size/2)))
  73. class StorageComponentLabelSmdBook(ComponentLabelSmall):
  74. pixels_x = 826
  75. pixels_y = 191
  76. ql_format = '38'
  77. ql_rotation = 0
  78. dpi_600 = True
  79. red_label = False
  80. text_pos_x = 235
  81. qrcode_size = 6
  82. def put_content(self, storage_qr_data, stock_qr_data, component_name='', manufacturer='', package=''):
  83. super().put_content(stock_qr_data, component_name, manufacturer, package)
  84. qr = qrcode.QRCode(
  85. version=1,
  86. error_correction=qrcode.constants.ERROR_CORRECT_L,
  87. box_size=self.qrcode_size,
  88. border=0,
  89. )
  90. qr.add_data(storage_qr_data)
  91. qr.make(fit=True)
  92. qr_image = qr.make_image(fill_color="black", back_color="white")
  93. qr_y_size = qr_image.size[1]
  94. self.img.paste(qr_image, box=(550, int(self.pixels_y/2 - qr_y_size/2)))
  95. class ComponentLabelSmdMiceToiletPocket(Label):
  96. pixels_x = 307
  97. pixels_y = 212
  98. ql_format = '12'
  99. ql_rotation = 270
  100. dpi_600 = True
  101. red_label = False
  102. def __init__(self):
  103. super().__init__()
  104. def put_content(self, heading, line1=None, line2=None):
  105. self.draw_text(heading, self.pixels_x/2, 10, size=50, font_file='bold', centered_x=True, centered_y=True, scale_to_fit=True)
  106. if line1:
  107. self.draw_text(line1, self.pixels_x/2, 80, size=40, centered_x=True, centered_y=True, scale_to_fit=True)
  108. if line2:
  109. self.draw_text(line2, self.pixels_x/2, 165, size=40, centered_x=True, centered_y=True, scale_to_fit=True)