PCamChecked.py 2.7 KB

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