DialogSettingCam.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from .ui_py.ui_DialogSettingCam import Ui_DialogSettingCam
  2. from PySide6.QtWidgets import QDialog
  3. from PySide6.QtCore import Qt, Slot
  4. from PySide6.QtMultimedia import QMediaDevices
  5. from module.WorkWithCam import WorkWithCam, get_list_name_cam, load_image
  6. from module.WorkWithDB import *
  7. class SettingCam(QDialog, Ui_DialogSettingCam):
  8. def __init__(self, parent=None) -> None:
  9. super(SettingCam, self).__init__(parent)
  10. self.setAttribute(Qt.WA_DeleteOnClose)
  11. self.setupUi(self)
  12. self.load_cams()
  13. load_image(self.image, os.environ.get("NO_MEDIA_IMAGE"))
  14. self.chacked_cam_face.clicked.connect(self._open_cam_face)
  15. self.stop_cam_face.clicked.connect(self._close_cam_face)
  16. self.save_setting_cam.clicked.connect(self._save_setting_cam)
  17. def load_cams(self) -> None:
  18. for name in get_list_name_cam():
  19. self.face_list_cam.addItem(name)
  20. self.load_cams_from_db()
  21. def _save_setting_cam(self) -> None:
  22. self.save_cams(self.face_list_cam.currentText())
  23. def _open_cam_face(self) -> None:
  24. self.stackedWidget.setCurrentIndex(int(os.environ.get('INDEX_CAMERA')))
  25. self._cam_face = WorkWithCam(
  26. self.video, self.face_list_cam.currentText())
  27. self._cam_face.start_cam()
  28. def _close_cam_face(self) -> None:
  29. if self._cam_face:
  30. self.stackedWidget.setCurrentIndex(int(os.environ.get('INDEX_PHOTO')))
  31. del self._cam_face
  32. def load_cams_from_db(self):
  33. with connect() as conn:
  34. result = conn.execute(cam_setting.select()).fetchone()
  35. if result:
  36. self.face_list_cam.setCurrentText(result.selected_cam)
  37. def save_cams(self, description_cam: str) -> None:
  38. query = None
  39. with connect() as conn:
  40. result = conn.execute(cam_setting.select()).fetchone()
  41. if result is None:
  42. query = cam_setting.insert().values(selected_cam=description_cam)
  43. else:
  44. query = cam_setting.update().where(
  45. cam_setting.c.id == 1).values(selected_cam=description_cam)
  46. result = conn.execute(query)