PCamChecked.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from PySide6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLineEdit, QComboBox, QPushButton, QMessageBox
  2. from widgets.PStackedWidget import PStackedWidget
  3. from module.cam import IPCam, USBCam, get_list_name_cam
  4. class PCamChecked(QWidget):
  5. def __init__(self, parent=None, mode: str = 'video') -> None:
  6. super().__init__(parent)
  7. self.__mode = mode
  8. self.vLayout = QVBoxLayout(self)
  9. self.vLayout.setObjectName(u'vLayout')
  10. if self.__mode in 'snapshot':
  11. self.line_cam = QLineEdit(self)
  12. else:
  13. self.line_cam = QComboBox(self)
  14. # load list cam
  15. [self.line_cam.addItem(x) for x in get_list_name_cam()]
  16. self.line_cam.setObjectName(u"line_cam")
  17. self.vLayout.addWidget(self.line_cam)
  18. self.pStackedWidget = PStackedWidget(self, mode=mode)
  19. self.pStackedWidget.setObjectName(u'pStackedWidget')
  20. self.vLayout.addWidget(self.pStackedWidget)
  21. self.hLayout = QHBoxLayout()
  22. self.hLayout.setObjectName(u'hLayout')
  23. self.btn_check = QPushButton(self)
  24. self.btn_check.setObjectName('btn_check')
  25. self.btn_check.setText('Проверить')
  26. self.btn_check.clicked.connect(self.__start_cam)
  27. self.hLayout.addWidget(self.btn_check)
  28. self.btn_stop = QPushButton(self)
  29. self.btn_stop.setObjectName('btn_stop')
  30. self.btn_stop.setText('Остановить')
  31. self.btn_stop.clicked.connect(self.__stop_cam)
  32. self.hLayout.addWidget(self.btn_stop)
  33. self.vLayout.addLayout(self.hLayout)
  34. def get_value(self) -> str:
  35. match self.__mode:
  36. case 'video':
  37. return self.line_cam.currentText()
  38. case 'snapshot':
  39. return self.line_cam.text()
  40. case _: return None
  41. def __start_cam(self) -> None:
  42. match self.__mode:
  43. case 'video':
  44. self.pStackedWidget.to_video()
  45. self.__wwc = USBCam(self.pStackedWidget.video,
  46. self.line_cam.currentText())
  47. self.__wwc.start_cam()
  48. case 'snapshot':
  49. self.pStackedWidget.to_video()
  50. self.__wwc = IPCam()
  51. self.__wwc.qLabel = self.pStackedWidget.video
  52. self.__wwc.lnk_connect = self.line_cam.text()
  53. self.__wwc.start()
  54. case _: return None
  55. def __stop_cam(self):
  56. self.__wwc.stop_cam()
  57. del self.__wwc
  58. self.pStackedWidget.to_image()
  59. def __del__(self) -> None:
  60. self.__stop_cam