DialogCustomVariables.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 import translate
  5. from module.MyMessageBox import show_dialog
  6. class DialogCustomVariables(Ui_DialogCustomVariables, QDialog):
  7. def __init__(self, parent: str = None) -> None:
  8. self.path_env = parent
  9. super(DialogCustomVariables, self).__init__()
  10. self.setAttribute(Qt.WA_DeleteOnClose)
  11. self.setupUi(self)
  12. self.btn_show_path_photo.clicked.connect(
  13. self._show_path_photo
  14. )
  15. self.btn_show_path_database.clicked.connect(
  16. self._show_path_database
  17. )
  18. self.btn_save.clicked.connect(
  19. self._save
  20. )
  21. def _show_path_photo(self) -> None:
  22. dir = str(QFileDialog.getExistingDirectory(None, translate(
  23. 'Photo directory')))
  24. self.path_photo.setText(dir)
  25. def _show_path_database(self) -> None:
  26. dir = str(QFileDialog.getExistingDirectory(None, translate(
  27. 'Database directory')))
  28. self.path_db.setText(dir)
  29. def _save(self) -> None:
  30. with open(self.path_env, 'w+', encoding="utf-8") as file:
  31. file.write(F"DB_DIR={self.path_db.text()} \n")
  32. file.write(F"PHOTO_DIR={self.path_photo.text()} \n")
  33. show_dialog(QMessageBox.Icon.Information,
  34. translate('Success'),
  35. translate('Save success'))
  36. self.close()