diff --git a/ui/dialogs/tafaseer_Dialog.py b/ui/dialogs/tafaseer_Dialog.py index 77742c0..b5c5b5c 100644 --- a/ui/dialogs/tafaseer_Dialog.py +++ b/ui/dialogs/tafaseer_Dialog.py @@ -1,3 +1,4 @@ +import os from PyQt6.QtWidgets import ( QWidget, QHBoxLayout, @@ -14,8 +15,7 @@ from ui.widgets.qText_edit import ReadOnlyTextEdit from core_functions.tafaseer import TafaseerManager, Category from utils.universal_speech import UniversalSpeech -import os - +from utils.const import albayan_documents_dir class TafaseerDialog(QDialog): @@ -97,19 +97,14 @@ def copy_content(self): clipboard.setText(copied_content) UniversalSpeech.say("تم نسخ التفسير.") - def save_content(self): - # Get the path to the Documents directory - documents_dir = os.path.join(os.path.expanduser("~"), "Documents") - albayan_dir = os.path.join(documents_dir, "Albayan") - - # Create the Albayan directory if it does not exist - if not os.path.exists(albayan_dir): - os.makedirs(albayan_dir) + def save_content(self): + file_name = os.path.join(albayan_documents_dir, self.windowTitle()) # Open the file dialog in the Albayan directory file_path, _ = QFileDialog.getSaveFileName( - self, "Save File", albayan_dir, "Text files (*.txt)" + self, "Save File", file_name, "Text files (*.txt)", ) + if file_path: with open(file_path, "w") as file: file.write(self.text_edit.toPlainText()) diff --git a/utils/const.py b/utils/const.py index 9d178aa..27d8ef3 100644 --- a/utils/const.py +++ b/utils/const.py @@ -8,6 +8,10 @@ temp_folder = os.path.join(os.getenv("TEMP"), "albayan") os.makedirs(temp_folder, exist_ok=True) +# Get the path to the Documents directory +albayan_documents_dir = os.path.join(os.path.expanduser("~"), "Documents", "Albayan") +os.makedirs(albayan_documents_dir, exist_ok=True) + # program information program_name = "البيان" program_version = "1.0.0"