storage_label.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 StorageLabelSmdMiceToilet(StorageLabel):
  50. pixels_x = 1108
  51. pixels_y = 200
  52. qr_size = 7
  53. text_size_verbose_name = 64
  54. text_size_name = 48
  55. text_pos_x = 320
  56. ql_format = '50'
  57. ql_rotation = 0
  58. dpi_600 = True
  59. red_label = False
  60. class StorageLabelSmdMiceToiletBottomQR(StorageLabel):
  61. pixels_x = 307
  62. pixels_y = 212
  63. ql_format = '12'
  64. ql_rotation = 270
  65. dpi_600 = True
  66. red_label = False
  67. def put_content(self, qr_data, storage_name=None, verbose_name=None):
  68. qr = qrcode.QRCode(
  69. version=1,
  70. error_correction=qrcode.constants.ERROR_CORRECT_L,
  71. box_size=7,
  72. border=0,
  73. )
  74. qr.add_data(qr_data)
  75. qr.make(fit=True)
  76. qr_image = qr.make_image(fill_color="black", back_color="white")
  77. qr_x_size = qr_image.size[0]
  78. qr_y_size = qr_image.size[1]
  79. self.img.paste(qr_image, box=(int(self.pixels_x/2 - qr_x_size/2), int(self.pixels_y/2 - qr_y_size/2)))
  80. class StorageLabelSmdMiceToiletTop(StorageLabel):
  81. pixels_x = 307
  82. pixels_y = 212
  83. ql_format = '12'
  84. ql_rotation = 270
  85. dpi_600 = True
  86. red_label = False
  87. def put_content(self, heading, line_1=None, line_2=None):
  88. self.draw_text(heading, self.pixels_x/2, 40, size=50, font_file='bold', centered_x=True, centered_y=True, scale_to_fit=True)
  89. if line_1:
  90. self.draw_text(line_1, self.pixels_x/2, 110, size=40, centered_x=True, centered_y=True, scale_to_fit=True)
  91. if line_2:
  92. self.draw_text(line_2, self.pixels_x/2, 170, size=40, centered_x=True, centered_y=True, scale_to_fit=True)