PStackedWidget.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from PySide6.QtWidgets import QStackedWidget, QWidget, QLabel, QGridLayout
  2. from PySide6.QtMultimediaWidgets import QVideoWidget
  3. from module.cam.USBCam import load_image
  4. import os
  5. class PStackedWidget(QStackedWidget):
  6. def __init__(self, parent=None, mode='video'):
  7. super(PStackedWidget, self).__init__(parent)
  8. self.__mode = mode
  9. self.__setup_image_stacked()
  10. self.__setup_video_stacked()
  11. self.set_default_image()
  12. def __setup_image_stacked(self) -> None:
  13. self.page_image = QWidget()
  14. self.page_image.setObjectName("page_image")
  15. self.layout_image = QGridLayout(self.page_image)
  16. self.layout_image.setObjectName("layout_image")
  17. self.image = QLabel(self.page_image)
  18. self.image.setObjectName("image")
  19. self.layout_image.addWidget(self.image, 0, 0, 0, 0)
  20. self.addWidget(self.page_image)
  21. def __setup_video_stacked(self) -> None:
  22. self.page_video = QWidget()
  23. self.page_video.setObjectName("page_video")
  24. self.layout_video = QGridLayout(self.page_video)
  25. self.layout_video.setObjectName("layout_video")
  26. if self.__mode == 'video':
  27. self.video = QVideoWidget(self.page_video)
  28. else:
  29. self.video = QLabel(self.page_video)
  30. self.video.setObjectName("video")
  31. self.layout_video.addWidget(self.video, 0, 0, 0, 0)
  32. self.addWidget(self.page_video)
  33. def set_default_image(self) -> None:
  34. load_image(self.image, os.environ.get("NO_MEDIA_IMAGE"))
  35. def to_image(self) -> None:
  36. self.setCurrentIndex(0)
  37. def to_video(self) -> None:
  38. self.setCurrentIndex(1)
  39. # def cupture_image(self) -> None:
  40. # if self.__mode == 'video':
  41. # self.video = self.video.cupture_image(self.image)
  42. # else:
  43. # self.video = self.video.cupture_image(self.image)