detail_temp.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # from import_qt_mode import *
  2. # from UI.auto_deal_pics_ui.temp_item import Ui_Form as UI_temp_item
  3. import os
  4. from PIL import Image
  5. import threading
  6. from io import BytesIO
  7. # 详情itme模板组件
  8. class TempItem():
  9. # select_sign = Signal(str)
  10. def __init__(self, parent, _id, image_path):
  11. super().__init__(parent)
  12. # self.ui = UI_temp_item()
  13. # self.ui.setupUi(self)
  14. self.temp_name = _id
  15. self.image_path = image_path
  16. self.id = _id
  17. self.is_select = False
  18. self.init()
  19. # self.show()
  20. def init(self):
  21. # self.ui.label.mousePressEvent = self.pic_show
  22. # self.ui.radioButton.clicked.connect(self.select)
  23. self.set_label_image()
  24. # self.label_temp_name = QLabel(self)
  25. # self.label_temp_name.setText(str(self.temp_name))
  26. # self.label_temp_name.move(5, self.height() - self.label_temp_name.height())
  27. def cancel_select(self, *args):
  28. self.is_select = False
  29. # self.ui.radioButton.setChecked(False)
  30. def select(self, *args):
  31. self.is_select = True
  32. # self.ui.radioButton.setChecked(True)
  33. # self.select_sign.emit(self.id)
  34. def pic_show(self, *args, **kwargs):
  35. if os.path.exists(self.image_path):
  36. im = Image.open(self.image_path)
  37. threading.Thread(target=im.show, args=()).start()
  38. def set_label_image(self):
  39. if not os.path.exists(self.image_path):
  40. return
  41. # try:
  42. # bytes_io = BytesIO()
  43. # w, h = self.ui.image_show.width(), self.ui.image_show.height()
  44. # _img_raw = Image.open(self.image_path)
  45. # _img_raw = self.to_resize(_img_raw, width=w * 2)
  46. # _img_raw = _img_raw.crop(box=(0, 0, w * 2, h * 2))
  47. # # _img_raw.thumbnail((w * 2, int(_img_raw.height * w * 2 / _img_raw.width)))
  48. # # img_raw = _img_raw.resize(size=(w, h))
  49. # _img_raw.save(bytes_io, "JPEG")
  50. # icon = QPixmap()
  51. # # icon.loadFromData(img)
  52. # icon.loadFromData(bytes_io.getvalue())
  53. # icon = icon.scaled(
  54. # self.ui.image_show.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation
  55. # )
  56. # self.ui.image_show.setPixmap(icon)
  57. # # self.mousePressEvent = lambda x: self.show_one_data(row)
  58. # except:
  59. pass
  60. def to_resize(self, _im, width=None, high=None):
  61. _im_x, _im_y = _im.size
  62. if width and high:
  63. if _im_x >= _im_y:
  64. high = None
  65. else:
  66. width = None
  67. if width:
  68. re_x = int(width)
  69. re_y = int(_im_y * re_x / _im_x)
  70. else:
  71. re_y = int(high)
  72. re_x = int(_im_x * re_y / _im_y)
  73. _im = _im.resize((re_x, re_y))
  74. return _im