DialogCustomVariables.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from .ui_py.ui_DialogCustomVariables import Ui_DialogCustomVariables
  2. from PySide6.QtWidgets import QDialog, QFileDialog, QMessageBox
  3. from PySide6.QtCore import Qt
  4. from module.MyMessageBox import show_dialog
  5. class DialogCustomVariables(Ui_DialogCustomVariables, QDialog):
  6. def __init__(self, parent: str = None) -> None:
  7. self.path_env = parent
  8. super(DialogCustomVariables, self).__init__()
  9. self.setAttribute(Qt.WA_DeleteOnClose)
  10. self.setupUi(self)
  11. self.btn_show_path_photo.clicked.connect(
  12. self._show_path_photo
  13. )
  14. self.btn_show_path_database.clicked.connect(
  15. self._show_path_database
  16. )
  17. self.btn_save.clicked.connect(
  18. self._save
  19. )
  20. def _show_path_photo(self) -> None:
  21. dir = str(QFileDialog.getExistingDirectory(None, "Выбрать директорию где будут храниться фоотографии"))
  22. self.path_photo.setText(dir)
  23. def _show_path_database(self) -> None:
  24. dir = str(QFileDialog.getExistingDirectory(None, "Выбрать директорию где будет храниться база данных"))
  25. self.path_db.setText(dir)
  26. def _save(self) -> None:
  27. with open(self.path_env, 'w+', encoding="utf-8") as file:
  28. file.write(F"DB_DIR={self.path_db.text()} \n")
  29. file.write(F"PHOTO_DIR={self.path_photo.text()} \n")
  30. show_dialog(QMessageBox.Icon.Information,
  31. "Успешно!",
  32. "Сохранения произошло успешно!")
  33. self.close()