Explorar el Código

Будет показывать ошибки если произошли пользователю

Alex Sidorov hace 1 año
padre
commit
4d064c3913
Se han modificado 5 ficheros con 56 adiciones y 38 borrados
  1. 1 1
      module/MyMessageBox.pyi
  2. 8 7
      widgets/PCamChecked.py
  3. 1 1
      widgets/__init__.py
  4. 22 12
      window/DialogSettingCam.py
  5. 24 17
      window/MainWindow.py

+ 1 - 1
module/MyMessageBox.pyi

@@ -1,3 +1,3 @@
 from PySide6.QtWidgets import QMessageBox
     
-def show_dialog(state: QMessageBox.Icon, title: str, massage: str): ...
+def show_dialog(state: QMessageBox.Icon, title: str, massage: str) -> bool: ...

+ 8 - 7
widgets/PCamChecked.py

@@ -9,16 +9,17 @@ class PCamChecked(QWidget):
         super().__init__(parent)
 
         self.__mode = mode
+        
         self.vLayout = QVBoxLayout(self)
         self.vLayout.setObjectName(u'vLayout')
 
-        match self.__mode:
-            case 'video':
-                self.line_cam = QComboBox(self)
-                # load list cam
-                [self.line_cam.addItem(x) for x in get_list_name_cam()]
-            case 'snapshot': self.line_cam = QLineEdit(self)
-
+        if self.__mode in 'snapshot':
+            self.line_cam = QLineEdit(self)
+        else:
+            self.line_cam = QComboBox(self)
+            # load list cam
+            [self.line_cam.addItem(x) for x in get_list_name_cam()]
+        
         self.line_cam.setObjectName(u"line_cam")
         self.vLayout.addWidget(self.line_cam)
 

+ 1 - 1
widgets/__init__.py

@@ -4,7 +4,7 @@ from .PCamChecked import *
 
 
 
-def create_widget_cam_shecked(obj, layout, name_object: str, mode: str = 'video', ) -> PCamChecked:
+def create_widget_cam_shecked(obj, layout, name_object: str, mode: str = 'video') -> PCamChecked:
     widget = PCamChecked(obj, mode=mode)
     widget.setObjectName(name_object)
     layout.addWidget(widget)

+ 22 - 12
window/DialogSettingCam.py

@@ -1,6 +1,7 @@
 from .ui_py.ui_DialogSettingCam import Ui_DialogSettingCam
 from PySide6.QtWidgets import QDialog
 from PySide6.QtCore import Qt, Slot
+from sqlalchemy.exc import OperationalError
 
 from module.WorkWithDB import *
 from widgets import create_widget_cam_shecked
@@ -27,6 +28,8 @@ class SettingCam(QDialog, Ui_DialogSettingCam):
     def __change_type(self) -> None:
         if self.tabWidget.currentIndex() == 1:
             self.__mode = 'document'
+        # else:
+        #     self.__mode = 'video'     
 
         self.__load_cams_from_db()
 
@@ -63,6 +66,7 @@ class SettingCam(QDialog, Ui_DialogSettingCam):
                 cam_setting.c.type == self.tabWidget.currentIndex()
             )).fetchone()
             if result:
+                print(result)
                 self.__mode = result.mode
                 self.__recreate_widget(self.__mode)
                 match self.__mode:
@@ -82,16 +86,22 @@ class SettingCam(QDialog, Ui_DialogSettingCam):
     def __save_cams(self) -> None:
         query = None
         with connect() as conn:
-            result = conn.execute(cam_setting.select().where(
-                cam_setting.c.type == self.tabWidget.currentIndex()
-            )).fetchone()
-            if result is None:
-                query = cam_setting.insert().values(
-                    type=self.tabWidget.currentIndex(),
-                    mode=self.__mode,
-                    selected_cam=self.widget.get_value())
-            else:
-                query = cam_setting.update().where(
+            try:
+                result = conn.execute(cam_setting.select().where(
                     cam_setting.c.type == self.tabWidget.currentIndex()
-                ).values(mode=self.__mode, selected_cam=self.widget.get_value())
-            result = conn.execute(query)
+                )).fetchone()
+                if result is None:
+                    query = cam_setting.insert().values(
+                        type=self.tabWidget.currentIndex(),
+                        mode=self.__mode,
+                        selected_cam=self.widget.get_value())
+                else:
+                    query = cam_setting.update().where(
+                        cam_setting.c.type == self.tabWidget.currentIndex()
+                    ).values(mode=self.__mode, selected_cam=self.widget.get_value())
+                result = conn.execute(query)
+                show_dialog(QMessageBox.Icon.Information, '', 'Сохранено')
+                logger.info('Камера сохранена')
+            except OperationalError as er:
+                logger.error(er)
+                show_dialog(QMessageBox.Icon.Critical, 'Ошибка', 'Произошла ошибка! \nОбратитеcь к администратору')

+ 24 - 17
window/MainWindow.py

@@ -1,5 +1,6 @@
 from PySide6.QtWidgets import QMainWindow, QMessageBox, QApplication
 from PySide6.QtCore import QDate, QDateTime
+from sqlalchemy.exc import OperationalError
 
 from module.WorkWithDB import *
 from module.MyMessageBox import show_dialog
@@ -8,7 +9,6 @@ from module.Printer import Printer
 from module.lang.ru import *
 from module.cam import IPCam, USBCam, load_image
 
-
 from widgets import PStackedWidget, create_widget_stacked
 
 from .ui_py.ui_MainWindow import Ui_MainWindow
@@ -30,12 +30,12 @@ vecrot_cam_from_db = [str, str, str]
 
 class MainWindow(QMainWindow, Ui_MainWindow):
     def __init__(self, parent=None) -> None:
-        
+
         super(MainWindow, self).__init__(parent)
         self.setupUi(self)
         self.__wwc = None
         self.data_propusk = None
-        self._parent=parent
+
         self.date_from.setDateTime(QDateTime().currentDateTime())
         self.date_to.setDateTime(QDateTime().currentDateTime())
 
@@ -131,8 +131,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
         except TypeError:
             logger.warning(warring_cams.get("title"))
 
-        
-
     def __update_list_combobox(self) -> None:
         self.__load_personal()
         self.__load_place()
@@ -213,14 +211,16 @@ class MainWindow(QMainWindow, Ui_MainWindow):
 
     def __take_image_face(self) -> None:
         if self.tabWidget.currentIndex() == 1:
-            self.__file_name_document = self.__wwc.cupture_image(self.stacked_document.image)
+            self.__file_name_document = self.__wwc.cupture_image(
+                self.stacked_document.image)
             sleep(1)
             load_image(self.stacked_document.image, self.__file_name_document)
         else:
-            self.__file_name_face = self.__wwc.cupture_image(self.stacked_face.image)
+            self.__file_name_face = self.__wwc.cupture_image(
+                self.stacked_face.image)
             sleep(1)
             load_image(self.stacked_face.image, self.__file_name_face)
-            
+
         self.__stop_cam()
 
     def __print(self) -> None:
@@ -228,14 +228,14 @@ class MainWindow(QMainWindow, Ui_MainWindow):
             self.__save()
 
         propusk_data = self.data_propusk.copy()
-        
+
         propusk_data.update({
             "personal": self.personal_combobox.currentText(),
             "place": self.place_combobox.currentText(),
             "date_from": self.date_from.dateTime().toString('dd.MM.yyyy hh:mm'),
             "date_to": self.date_to.dateTime().toString('dd.MM.yyyy hh:mm'),
             "face": self.__file_name_face,
-            "document": self.__file_name_face        
+            "document": self.__file_name_face
         })
 
         render_text = TemplatePropusk(
@@ -268,9 +268,16 @@ class MainWindow(QMainWindow, Ui_MainWindow):
         }
 
         with connect() as conn:
-            conn.execute(
-                list_propusk.insert().values(**self.data_propusk)
-            )
+            try:
+                conn.execute(
+                    list_propusk.insert().values(**self.data_propusk)
+                )
+
+                show_dialog(QMessageBox.Icon.Information, '', 'Сохранено')
+            except OperationalError as er:
+                logger.error(er)
+                show_dialog(QMessageBox.Icon.Critical, 'Ошибка',
+                            'Произошла ошибка при сохранении! \n Обратитесь к администратору')
 
     def __set_default_data(self) -> None:
         self.number_propusk.clear()
@@ -279,7 +286,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
 
         if self.__wwc is not None:
             self.__stop_cam()
-            
+
         self.receiving_man.clear()
         self.purpose_visite.clear()
 
@@ -290,7 +297,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
 
         if self.tabWidget.currentIndex() == 1:
             self.stacked_document.to_image()
-        else: self.stacked_face.to_image()
+        else:
+            self.stacked_face.to_image()
 
     def __create_widget_face_cam(self) -> None:
         if hasattr(self, 'stacked_face'):
@@ -300,8 +308,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
             obj=self.tab,
             layout=self.gridLayout,
             mode=self.__mode)
-        
+
         self.stacked_face.currentChanged.connect(
             self.__change_text_in_btn_start_cam
         )
-