Bladeren bron

Изменяем на две камеры, одна для лица другая для паспорта

Alex Sidorov 1 jaar geleden
bovenliggende
commit
2ad2fba49b
5 gewijzigde bestanden met toevoegingen van 228 en 87 verwijderingen
  1. 7 4
      PropuskWidgets/PCamChecked.py
  2. 12 0
      module/WorkWithDB.py
  3. 59 16
      window/DialogSettingCam.py
  4. 113 49
      window/ui/DialogSettingCam.ui
  5. 37 18
      window/ui_py/ui_DialogSettingCam.py

+ 7 - 4
PropuskWidgets/PCamChecked.py

@@ -34,13 +34,13 @@ class PCamChecked(QWidget):
         self.btn_check = QPushButton(self)
         self.btn_check.setObjectName('btn_check')
         self.btn_check.setText('Проверить')
-        self.btn_check.clicked.connect(self._start_cam)
+        self.btn_check.clicked.connect(self.__start_cam)
         self.hLayout.addWidget(self.btn_check)
 
         self.btn_stop = QPushButton(self)
         self.btn_stop.setObjectName('btn_stop')
         self.btn_stop.setText('Остановить')
-        self.btn_stop.clicked.connect(self._stop_cam)
+        self.btn_stop.clicked.connect(self.__stop_cam)
         self.hLayout.addWidget(self.btn_stop)
 
         self.vLayout.addLayout(self.hLayout)
@@ -53,7 +53,7 @@ class PCamChecked(QWidget):
                 return self.line_cam.text()
             case _: return None
 
-    def _start_cam(self) -> None:
+    def __start_cam(self) -> None:
         
         match self.__mode:
             case 'video':
@@ -70,7 +70,10 @@ class PCamChecked(QWidget):
                     
             case _: return None
 
-    def _stop_cam(self):
+    def __stop_cam(self):
         self.__wwc.stop_cam()
         del self.__wwc
         self.pStackedWidget.to_image()
+        
+    def __del__(self) -> None:
+        self.__stop_cam

+ 12 - 0
module/WorkWithDB.py

@@ -1,6 +1,7 @@
 from sqlalchemy import (MetaData, Table, Column, Integer,
                         DateTime, String, Text, ForeignKey,
                         create_engine, func)
+from sqlalchemy.exc import ProgrammingError
 import os
 from module.MyMessageBox import show_dialog
 from PySide6.QtWidgets import QMessageBox
@@ -24,6 +25,7 @@ else:
     
 cam_setting = Table("сam_setting", meta,
                     Column('id', Integer, primary_key=True),
+                    Column('type', Integer, nullable=False),
                     Column('mode', String, nullable=False),
                     Column("selected_cam", String, nullable=False),
                     Column('created', DateTime, default=func.now()),
@@ -76,3 +78,13 @@ def init_db():
 
 def connect():
     return engine.connect()
+
+
+def check_error_sql(func):
+    def wrapper(*arg, **args):
+        try:
+            return func(arg, args)
+        except ProgrammingError as pe:
+            logger.error(pe)
+            
+    return wrapper

+ 59 - 16
window/DialogSettingCam.py

@@ -1,6 +1,6 @@
 from .ui_py.ui_DialogSettingCam import Ui_DialogSettingCam
 from PySide6.QtWidgets import QDialog
-from PySide6.QtCore import Qt
+from PySide6.QtCore import Qt, Slot
 
 from module.WorkWithDB import *
 from PropuskWidgets.PCamChecked import PCamChecked
@@ -13,45 +13,88 @@ class SettingCam(QDialog, Ui_DialogSettingCam):
         self.setAttribute(Qt.WA_DeleteOnClose)
         self.setupUi(self)
 
+        self.widget = None
+
+        self.__mode = self.mode_list.currentData()
+        self.__load_cams_from_db()
+
         self.save_setting_cam.clicked.connect(self.__save_cams)
-        self.mode_list.currentTextChanged.connect(self.__change_mode)
+        self.mode_list.currentIndexChanged.connect(self.__change_mode)
+        self.tabWidget.currentChanged.connect(self.__change_type)
 
         # self.__recreate_widget()
-        self.__load_cams_from_db()
-        self.__mode = self.mode_list.currentData()
 
+    def __change_type(self) -> None:
+        if self.tabWidget.currentIndex() == 1:
+            self.__mode = 'document'
+
+        self.__load_cams_from_db()
 
     def __change_mode(self) -> None:
         self.__mode = self.mode_list.currentData()
         self.__recreate_widget(self.__mode)
         logger.info(F'Change cams to {self.__mode}')
 
+    @Slot()
     def __recreate_widget(self, select_mode: str = 'video') -> None:
-        if hasattr(self, 'widget'):
-            delattr(self, 'widget')
+        self.__del_widget()
+        if self.tabWidget.currentIndex() == 0:
+            self.__create_widget(
+                mode=select_mode,
+                tab=self.tab,
+                layout=self.verticalLayout)
+        else:
+            self.__create_widget(
+                tab=self.tab_2,
+                layout=self.verticalLayout_3)
 
-        self.widget = PCamChecked(self.groupBox, mode=select_mode)
+    def __create_widget(self, tab, layout, mode: str = 'video') -> None:
+        self.widget = PCamChecked(tab, mode=mode)
         self.widget.setObjectName('widget')
-        self.gridLayout_3.addWidget(self.widget, 1, 0, 1, 1)
+        layout.addWidget(self.widget)
+
+    def __del_widget(self) -> None:
+        if self.widget is not None:
+            self.verticalLayout.removeWidget(self.widget)
+            self.verticalLayout_3.removeWidget(self.widget)
+
+        self.widget = None
 
     def __load_cams_from_db(self):
         with connect() as conn:
-            result = conn.execute(cam_setting.select()).fetchone()
+            result = conn.execute(cam_setting.select().where(
+                cam_setting.c.type == self.tabWidget.currentIndex()
+            )).fetchone()
             if result:
-                self.__recreate_widget(result.mode)
-                match result.mode:
-                    case 'video': self.widget.line_cam.setCurrentText(result.mode)
-                    case 'snapshot': self.widget.line_cam.setText(result.selected_cam)
+                self.__mode = result.mode
+                self.__recreate_widget(self.__mode)
+                match self.__mode:
+                    case 'video':
+                        self.mode_list.setCurrentIndex(0)
+                        self.widget.line_cam.setCurrentText(
+                            result.selected_cam)
+                    case 'snapshot':
+                        self.mode_list.setCurrentIndex(1)
+                        self.widget.line_cam.setText(result.selected_cam)
+                    case 'document':
+                        self.widget.line_cam.setCurrentText(
+                            result.selected_cam)
+                    case _: ...
             else: self.__recreate_widget()
 
     def __save_cams(self) -> None:
         query = None
         with connect() as conn:
-            result = conn.execute(cam_setting.select()).fetchone()
+            result = conn.execute(cam_setting.select().where(
+                cam_setting.c.type == self.tabWidget.currentIndex()
+            )).fetchone()
             if result is None:
                 query = cam_setting.insert().values(
-                    mode=self.__mode, selected_cam=self.widget.get_value())
+                    type=self.tabWidget.currentIndex(),
+                    mode=self.__mode,
+                    selected_cam=self.widget.get_value())
             else:
                 query = cam_setting.update().where(
-                    cam_setting.c.id == 1).values(mode=self.__mode, selected_cam=self.widget.get_value())
+                    cam_setting.c.type == self.tabWidget.currentIndex()
+                ).values(mode=self.__mode, selected_cam=self.widget.get_value())
             result = conn.execute(query)

+ 113 - 49
window/ui/DialogSettingCam.ui

@@ -6,67 +6,131 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>640</width>
-    <height>480</height>
+    <width>794</width>
+    <height>559</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Настройка камеры</string>
   </property>
-  <layout class="QGridLayout" name="gridLayout">
-   <item row="0" column="0">
-    <widget class="QGroupBox" name="groupBox">
-     <property name="title">
-      <string>Фото лица</string>
+  <layout class="QVBoxLayout" name="verticalLayout_2">
+   <item>
+    <widget class="QTabWidget" name="tabWidget">
+     <property name="currentIndex">
+      <number>1</number>
      </property>
-     <layout class="QGridLayout" name="gridLayout_3">
-      <item row="0" column="0">
-       <widget class="QComboBox" name="face_list_cam"/>
-      </item>
-      <item row="2" column="0">
-       <layout class="QHBoxLayout" name="horizontalLayout">
-        <item>
-         <widget class="QPushButton" name="chacked_cam_face">
-          <property name="text">
-           <string>Проверить</string>
-          </property>
+     <property name="tabsClosable">
+      <bool>false</bool>
+     </property>
+     <property name="movable">
+      <bool>false</bool>
+     </property>
+     <property name="tabBarAutoHide">
+      <bool>false</bool>
+     </property>
+     <widget class="QWidget" name="tab">
+      <attribute name="title">
+       <string>Фото лица</string>
+      </attribute>
+      <layout class="QVBoxLayout" name="verticalLayout">
+       <item>
+        <widget class="QComboBox" name="face_list_cam"/>
+       </item>
+       <item>
+        <widget class="QStackedWidget" name="stackedWidget">
+         <widget class="QWidget" name="page_9">
+          <layout class="QGridLayout" name="gridLayout_10">
+           <item row="0" column="0">
+            <widget class="QLabel" name="image_4">
+             <property name="text">
+              <string/>
+             </property>
+            </widget>
+           </item>
+          </layout>
          </widget>
-        </item>
-        <item>
-         <widget class="QPushButton" name="stop_cam_face">
-          <property name="text">
-           <string>Остановить</string>
-          </property>
+         <widget class="QWidget" name="page_10">
+          <layout class="QGridLayout" name="gridLayout_11">
+           <item row="0" column="0">
+            <widget class="QVideoWidget" name="video_4"/>
+           </item>
+          </layout>
          </widget>
-        </item>
-       </layout>
-      </item>
-      <item row="1" column="0">
-       <widget class="QStackedWidget" name="stackedWidget">
-        <widget class="QWidget" name="page_3">
-         <layout class="QGridLayout" name="gridLayout_2">
-          <item row="0" column="0">
-           <widget class="QLabel" name="image">
-            <property name="text">
-             <string/>
-            </property>
-           </widget>
-          </item>
-         </layout>
         </widget>
-        <widget class="QWidget" name="page_4">
-         <layout class="QGridLayout" name="gridLayout_4">
-          <item row="0" column="0">
-           <widget class="QVideoWidget" name="video"/>
-          </item>
-         </layout>
+       </item>
+       <item>
+        <layout class="QHBoxLayout" name="horizontalLayout_4">
+         <item>
+          <widget class="QPushButton" name="chacked_cam_face_3">
+           <property name="text">
+            <string>Проверить</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QPushButton" name="stop_cam_face_3">
+           <property name="text">
+            <string>Остановить</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="tab_2">
+      <attribute name="title">
+       <string>Фото документа</string>
+      </attribute>
+      <layout class="QVBoxLayout" name="verticalLayout_3">
+       <item>
+        <widget class="QComboBox" name="face_list_cam_2"/>
+       </item>
+       <item>
+        <widget class="QStackedWidget" name="stackedWidget_2">
+         <widget class="QWidget" name="page_5">
+          <layout class="QGridLayout" name="gridLayout_7">
+           <item row="0" column="0">
+            <widget class="QLabel" name="image_2">
+             <property name="text">
+              <string/>
+             </property>
+            </widget>
+           </item>
+          </layout>
+         </widget>
+         <widget class="QWidget" name="page_6">
+          <layout class="QGridLayout" name="gridLayout_8">
+           <item row="0" column="0">
+            <widget class="QVideoWidget" name="video_2"/>
+           </item>
+          </layout>
+         </widget>
         </widget>
-       </widget>
-      </item>
-     </layout>
+       </item>
+       <item>
+        <layout class="QHBoxLayout" name="horizontalLayout_2">
+         <item>
+          <widget class="QPushButton" name="chacked_cam_document">
+           <property name="text">
+            <string>Проверить</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QPushButton" name="stop_cam_document">
+           <property name="text">
+            <string>Остановить</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
+      </layout>
+     </widget>
     </widget>
    </item>
-   <item row="1" column="0">
+   <item>
     <widget class="QPushButton" name="save_setting_cam">
      <property name="text">
       <string>Сохранить настройки</string>

+ 37 - 18
window/ui_py/ui_DialogSettingCam.py

@@ -9,48 +9,67 @@
 ################################################################################
 
 from PySide6.QtCore import (QCoreApplication, QMetaObject)
-from PySide6.QtWidgets import (QComboBox, QGridLayout, QGroupBox, QPushButton)
+from PySide6.QtWidgets import (
+    QComboBox, QPushButton, QTabWidget, QVBoxLayout, QWidget)
+from PropuskWidgets.PCamChecked import PCamChecked
 
 
 class Ui_DialogSettingCam(object):
     def setupUi(self, DialogSettingCam):
         if not DialogSettingCam.objectName():
             DialogSettingCam.setObjectName(u"DialogSettingCam")
+        DialogSettingCam.resize(794, 559)
+        self.verticalLayout_2 = QVBoxLayout(DialogSettingCam)
+        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
+        self.tabWidget = QTabWidget(DialogSettingCam)
+        self.tabWidget.setObjectName(u"tabWidget")
+        self.tabWidget.setTabsClosable(False)
+        self.tabWidget.setMovable(False)
+        self.tabWidget.setTabBarAutoHide(False)
+        self.tab = QWidget()
+        self.tab.setObjectName(u"tab")
+        self.verticalLayout = QVBoxLayout(self.tab)
+        self.verticalLayout.setObjectName(u"verticalLayout")
 
-        DialogSettingCam.resize(640, 480)
-        self.gridLayout = QGridLayout(DialogSettingCam)
-        self.gridLayout.setObjectName(u"gridLayout")
-        self.groupBox = QGroupBox(DialogSettingCam)
-        self.groupBox.setObjectName(u"groupBox")
-        self.gridLayout_3 = QGridLayout(self.groupBox)
-        self.gridLayout_3.setObjectName(u"gridLayout_3")
-
-        self.mode_list = QComboBox(self.groupBox)
+        self.mode_list = QComboBox(self.tab)
         self.mode_list.setObjectName(u'mode_list')
-        self.gridLayout_3.addWidget(self.mode_list, 0, 0, 1, 1)
+        self.verticalLayout.addWidget(self.mode_list)
+
+        self.tabWidget.addTab(self.tab, "")
+        self.tab_2 = QWidget()
+        self.tab_2.setObjectName(u"tab_2")
+
+        self.verticalLayout_3 = QVBoxLayout(self.tab_2)
+        self.verticalLayout_3.setObjectName('verticalLayout_3')
+        
+
+        self.tabWidget.addTab(self.tab_2, "")
 
-        self.gridLayout.addWidget(self.groupBox, 0, 0, 1, 1)
+        self.verticalLayout_2.addWidget(self.tabWidget)
 
         self.save_setting_cam = QPushButton(DialogSettingCam)
         self.save_setting_cam.setObjectName(u"save_setting_cam")
 
-        self.gridLayout.addWidget(self.save_setting_cam, 1, 0, 1, 1)
+        self.verticalLayout_2.addWidget(self.save_setting_cam)
 
         self.retranslateUi(DialogSettingCam)
 
+        self.tabWidget.setCurrentIndex(0)
+
         QMetaObject.connectSlotsByName(DialogSettingCam)
     # setupUi
 
     def retranslateUi(self, DialogSettingCam):
-
         DialogSettingCam.setWindowTitle(QCoreApplication.translate(
-            "DialogSettingCam", u"Настройка камеры", None))
+            "DialogSettingCam", u"\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043a\u0430\u043c\u0435\u0440\u044b", None))
 
         self.mode_list.addItem('USB Camera', userData='video')
         self.mode_list.addItem('IP Camera', userData='snapshot')
-
-        self.groupBox.setTitle(QCoreApplication.translate(
-            "DialogSettingCam", u"\u0424\u043e\u0442\u043e \u043b\u0438\u0446\u0430", None))
+        
+        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), QCoreApplication.translate(
+            "DialogSettingCam", u"\u041A\u0430\u043C\u0435\u0440\u0430 \u0434\u043B\u044F \u043B\u0438\u0446\u0430", None))
+        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QCoreApplication.translate(
+            "DialogSettingCam", u"\u041A\u0430\u043C\u0435\u0440\u0430 \u0434\u043B\u044F \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u0430", None))
         self.save_setting_cam.setText(QCoreApplication.translate(
             "DialogSettingCam", u"\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438", None))
     # retranslateUi