PCamChecked.py 2.5 KB

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