PCamChecked.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. match self.__mode:
  11. case 'video':
  12. self.line_cam = QComboBox(self)
  13. # load list cam
  14. [self.line_cam.addItem(x) for x in get_list_name_cam()]
  15. case 'snapshot': self.line_cam = QLineEdit(self)
  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