PCamChecked.py 2.6 KB

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