PCamChecked.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. from logger import logger
  5. class PCamChecked(QWidget):
  6. def __init__(self, parent=None, mode: str = 'video') -> None:
  7. super().__init__(parent)
  8. self.__mode = mode
  9. self.__wwc = None
  10. self.vLayout = QVBoxLayout(self)
  11. self.vLayout.setObjectName(u'vLayout')
  12. if self.__mode in 'snapshot':
  13. self.line_cam = QLineEdit(self)
  14. else:
  15. self.line_cam = QComboBox(self)
  16. # load list cam
  17. [self.line_cam.addItem(x) for x in get_list_name_cam()]
  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. logger.info("Start USB cam")
  51. case 'snapshot':
  52. self.pStackedWidget.to_video()
  53. self.__wwc = IPCam()
  54. self.__wwc.qLabel = self.pStackedWidget.video
  55. self.__wwc.lnk_connect = self.line_cam.text()
  56. self.__wwc.start()
  57. logger.info("Start IP cam")
  58. case _: return None
  59. def stop_cam(self):
  60. logger.info("Stop cam")
  61. self.__wwc.stop_cam()
  62. self.__wwc = None
  63. self.pStackedWidget.to_image()