storage_label.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. from .label_image import Label
  2. import qrcode
  3. class StorageLabel(Label):
  4. pixels_x = 696
  5. pixels_y = 250
  6. text_pos_x = 225
  7. qr_size = 9
  8. text_size_verbose_name = 48
  9. text_size_name = 32
  10. ql_format = '62'
  11. ql_rotation = 0
  12. dpi_600 = False
  13. red_label = True
  14. def __init__(self):
  15. super().__init__()
  16. def put_content(self, qr_data, storage_name, verbose_name=None):
  17. name_pos = self.pixels_y/2
  18. name_font_file = 'bold'
  19. if verbose_name:
  20. self.draw_text(verbose_name,
  21. self.text_pos_x,
  22. self.pixels_y/4,
  23. size=self.text_size_verbose_name,
  24. font_file='bold',
  25. scale_to_fit=True,
  26. centered_x=False,
  27. centered_y=True)
  28. name_pos = self.pixels_y/4 * 3
  29. name_font_file = None
  30. self.draw_text(storage_name,
  31. self.text_pos_x,
  32. name_pos,
  33. size=self.text_size_name,
  34. font_file=name_font_file,
  35. scale_to_fit=True,
  36. centered_x=False,
  37. centered_y=True)
  38. qr = qrcode.QRCode(
  39. version=1,
  40. error_correction=qrcode.constants.ERROR_CORRECT_L,
  41. box_size=7,
  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 StorageLabelSmdStrap(StorageLabel):
  50. pixels_x = 700
  51. pixels_y = 212
  52. qr_size = 7
  53. text_size_verbose_name = 64
  54. text_size_name = 64
  55. text_pos_x = 250
  56. ql_format = '12'
  57. ql_rotation = 270
  58. dpi_600 = True
  59. red_label = False
  60. class StorageLabelSmdMiceToilet(StorageLabel):
  61. pixels_x = 1108
  62. pixels_y = 200
  63. qr_size = 7
  64. text_size_verbose_name = 64
  65. text_size_name = 48
  66. text_pos_x = 320
  67. ql_format = '50'
  68. ql_rotation = 0
  69. dpi_600 = True
  70. red_label = False
  71. class StorageLabelSmdMiceToiletBottomQR(StorageLabel):
  72. pixels_x = 307
  73. pixels_y = 212
  74. ql_format = '12'
  75. ql_rotation = 270
  76. dpi_600 = True
  77. red_label = False
  78. def put_content(self, qr_data, storage_name=None, verbose_name=None):
  79. qr = qrcode.QRCode(
  80. version=1,
  81. error_correction=qrcode.constants.ERROR_CORRECT_L,
  82. box_size=7,
  83. border=0,
  84. )
  85. qr.add_data(qr_data)
  86. qr.make(fit=True)
  87. qr_image = qr.make_image(fill_color="black", back_color="white")
  88. qr_x_size = qr_image.size[0]
  89. qr_y_size = qr_image.size[1]
  90. self.img.paste(qr_image, box=(int(self.pixels_x/2 - qr_x_size/2), int(self.pixels_y/2 - qr_y_size/2)))
  91. class StorageLabelSmdMiceToiletTop(StorageLabel):
  92. pixels_x = 307
  93. pixels_y = 212
  94. ql_format = '12'
  95. ql_rotation = 270
  96. dpi_600 = True
  97. red_label = False
  98. def put_content(self, heading, line_1=None, line_2=None):
  99. self.draw_text(heading, self.pixels_x/2, 40, size=50, font_file='bold', centered_x=True, centered_y=True, scale_to_fit=True)
  100. if line_1:
  101. self.draw_text(line_1, self.pixels_x/2, 110, size=40, centered_x=True, centered_y=True, scale_to_fit=True)
  102. if line_2:
  103. self.draw_text(line_2, self.pixels_x/2, 170, size=40, centered_x=True, centered_y=True, scale_to_fit=True)